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 (!da.isComplex()) {
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 (!da.isComplex()) {
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                                        }
1545                                        t /= d1;
1546                                        r.setAbs(k, t * d.getDouble(isReversed ? s : 0));
1547                                } else if (i == -s - 2) {
1548                                        if (right != null) {
1549                                                r.setAbs(k, right.doubleValue());
1550                                                continue;
1551                                        }
1552                                        final double d1 = xa[s] - xa[s - 1];
1553                                        double t = d1 - v + xa[s];
1554                                        if (t <= 0) {
1555                                                continue; // sets to zero
1556                                        }
1557                                        t /= d1;
1558                                        r.setAbs(k, t * d.getDouble(isReversed ? 0 : s));
1559                                } else {
1560                                        i = -i - 1;
1561                                        double t = (xa[i] - v) / (xa[i] - xa[i - 1]);
1562                                        if (isReversed) {
1563                                                i = s - i;
1564                                                r.setAbs(k, t * d.getDouble(i + 1) + (1 - t) * d.getDouble(i));
1565                                        } else {
1566                                                r.setAbs(k, (1 - t) * d.getDouble(i) + t * d.getDouble(i - 1));
1567                                        }
1568                                }
1569                        } else {
1570                                r.setAbs(k, d.getDouble(isReversed ? s - i : i));
1571                        }
1572                }
1573                return r;
1574        }
1575
1576        /**
1577         * Linearly interpolate a value at a point in a 1D dataset. The dataset is
1578         * considered to have zero support outside its bounds. Thus points just
1579         * outside are interpolated from the boundary value to zero.
1580         * 
1581         * @param d
1582         *            input dataset
1583         * @param x0
1584         *            coordinate
1585         * @return interpolated value
1586         */
1587        public static double interpolate(final Dataset d, final double x0) {
1588                assert d.getRank() == 1;
1589
1590                final int i0 = (int) Math.floor(x0);
1591                final int e0 = d.getSize() - 1;
1592                if (i0 < -1 || i0 > e0) {
1593                        return 0;
1594                }
1595
1596                final double u0 = x0 - i0;
1597
1598                double r = 0;
1599                final double f1 = i0 < 0 ? 0 : d.getDouble(i0);
1600                if (u0 > 0) {
1601                        r = (1 - u0) * f1 + (i0 == e0 ? 0 : u0 * d.getDouble(i0 + 1));
1602                } else {
1603                        r = f1;
1604                }
1605                return r;
1606        }
1607
1608        /**
1609         * Linearly interpolate a value at a point in a 1D dataset with a mask. The
1610         * dataset is considered to have zero support outside its bounds. Thus
1611         * points just outside are interpolated from the boundary value to zero.
1612         * 
1613         * @param d
1614         *            input dataset
1615         * @param m
1616         *            mask dataset
1617         * @param x0
1618         *            coordinate
1619         * @return interpolated value
1620         */
1621        public static double interpolate(final Dataset d, final Dataset m, final double x0) {
1622                assert d.getRank() == 1;
1623                assert m.getRank() == 1;
1624
1625                final int i0 = (int) Math.floor(x0);
1626                final int e0 = d.getSize() - 1;
1627                if (i0 < -1 || i0 > e0) {
1628                        return 0;
1629                }
1630
1631                final double u0 = x0 - i0;
1632
1633                double r = 0;
1634                final double f1 = i0 < 0 ? 0 : d.getDouble(i0) * m.getDouble(i0);
1635                if (u0 > 0) {
1636                        r = (1 - u0) * f1 + (i0 == e0 ? 0 : u0 * d.getDouble(i0 + 1) * m.getDouble(i0 + 1));
1637                } else {
1638                        r = f1;
1639                }
1640                return r;
1641        }
1642
1643        /**
1644         * Linearly interpolate an array of values at a point in a compound 1D
1645         * dataset. The dataset is considered to have zero support outside its
1646         * bounds. Thus points just outside are interpolated from the boundary value
1647         * to zero.
1648         * 
1649         * @param values
1650         *            interpolated array
1651         * @param d
1652         *            input dataset
1653         * @param x0
1654         *            coordinate
1655         */
1656        public static void interpolate(final double[] values, final CompoundDataset d, final double x0) {
1657                assert d.getRank() == 1;
1658
1659                final int is = d.getElementsPerItem();
1660                if (is != values.length) {
1661                        throw new IllegalArgumentException("Output array length must match elements in item");
1662                }
1663                final double[] f1, f2;
1664
1665                final int i0 = (int) Math.floor(x0);
1666                final int e0 = d.getSize() - 1;
1667                if (i0 < -1 || i0 > e0) {
1668                        Arrays.fill(values, 0);
1669                        return;
1670                }
1671                final double u0 = x0 - i0;
1672
1673                if (u0 > 0) {
1674                        f1 = new double[is];
1675                        if (i0 >= 0) {
1676                                d.getDoubleArray(f1, i0);
1677                        }
1678                        double t = 1 - u0;
1679                        if (i0 == e0) {
1680                                for (int j = 0; j < is; j++) {
1681                                        values[j] = t * f1[j];
1682                                }
1683                        } else {
1684                                f2 = new double[is];
1685                                d.getDoubleArray(f2, i0 + 1);
1686                                for (int j = 0; j < is; j++) {
1687                                        values[j] = t * f1[j] + u0 * f2[j];
1688                                }
1689                        }
1690                } else {
1691                        if (i0 >= 0) {
1692                                d.getDoubleArray(values, i0);
1693                        } else {
1694                                Arrays.fill(values, 0);
1695                        }
1696                }
1697        }
1698
1699        /**
1700         * Linearly interpolate a value at a point in a 2D dataset. The dataset is
1701         * considered to have zero support outside its bounds. Thus points just
1702         * outside are interpolated from the boundary value to zero.
1703         * 
1704         * @param d
1705         *            input dataset
1706         * @param x0
1707         *            coordinate
1708         * @param x1
1709         *            coordinate
1710         * @return bilinear interpolation
1711         */
1712        public static double interpolate(final Dataset d, final double x0, final double x1) {
1713                final int[] s = d.getShape();
1714                assert s.length == 2;
1715
1716                final int e0 = s[0] - 1;
1717                final int e1 = s[1] - 1;
1718                final int i0 = (int) Math.floor(x0);
1719                final int i1 = (int) Math.floor(x1);
1720                final double u0 = x0 - i0;
1721                final double u1 = x1 - i1;
1722                if (i0 < -1 || i0 > e0 || i1 < -1 || i1 > e1) {
1723                        return 0;
1724                }
1725
1726                // use bilinear interpolation
1727                double r = 0;
1728                final double f1, f2, f3, f4;
1729                f1 = i0 < 0 || i1 < 0 ? 0 : d.getDouble(i0, i1);
1730                if (u1 > 0) {
1731                        if (u0 > 0) {
1732                                if (i0 == e0) {
1733                                        f2 = 0;
1734                                        f4 = 0;
1735                                        f3 = i1 == e1 ? 0 : d.getDouble(i0, i1 + 1);
1736                                } else {
1737                                        f2 = i1 < 0 ? 0 : d.getDouble(i0 + 1, i1);
1738                                        if (i1 == e1) {
1739                                                f4 = 0;
1740                                                f3 = 0;
1741                                        } else {
1742                                                f4 = d.getDouble(i0 + 1, i1 + 1);
1743                                                f3 = i0 < 0 ? 0 : d.getDouble(i0, i1 + 1);
1744                                        }
1745                                }
1746                                r = (1 - u0) * (1 - u1) * f1 + u0 * (1 - u1) * f2 + (1 - u0) * u1 * f3 + u0 * u1 * f4;
1747                        } else {
1748                                f3 = i0 < 0 || i1 == e1 ? 0 : d.getDouble(i0, i1 + 1);
1749                                r = (1 - u1) * f1 + u1 * f3;
1750                        }
1751                } else { // exactly on axis 1
1752                        if (u0 > 0) {
1753                                f2 = i0 == e0 || i1 < 0 ? 0 : d.getDouble(i0 + 1, i1);
1754                                r = (1 - u0) * f1 + u0 * f2;
1755                        } else { // exactly on axis 0
1756                                r = f1;
1757                        }
1758                }
1759                return r;
1760        }
1761
1762        /**
1763         * Linearly interpolate a value at a point in a 2D dataset with a mask. The
1764         * dataset is considered to have zero support outside its bounds. Thus
1765         * points just outside are interpolated from the boundary value to zero.
1766         * 
1767         * @param d
1768         *            input dataset
1769         * @param m
1770         *            mask dataset
1771         * @param x0
1772         *            coordinate
1773         * @param x1
1774         *            coordinate
1775         * @return bilinear interpolation
1776         */
1777        public static double interpolate(final Dataset d, final Dataset m, final double x0, final double x1) {
1778                if (m == null) {
1779                        return interpolate(d, x0, x1);
1780                }
1781
1782                final int[] s = d.getShapeRef();
1783                assert s.length == 2;
1784                assert m.getRank() == 2;
1785
1786                final int e0 = s[0] - 1;
1787                final int e1 = s[1] - 1;
1788                final int i0 = (int) Math.floor(x0);
1789                final int i1 = (int) Math.floor(x1);
1790                final double u0 = x0 - i0;
1791                final double u1 = x1 - i1;
1792                if (i0 < -1 || i0 > e0 || i1 < -1 || i1 > e1) {
1793                        return 0;
1794                }
1795
1796                // use bilinear interpolation
1797                double r = 0;
1798                final double f1, f2, f3, f4;
1799                f1 = i0 < 0 || i1 < 0 ? 0 : d.getDouble(i0, i1) * m.getDouble(i0, i1);
1800                if (u1 > 0) {
1801                        if (i0 == e0) {
1802                                f2 = 0;
1803                                f4 = 0;
1804                                f3 = i1 == e1 ? 0 : d.getDouble(i0, i1 + 1) * m.getDouble(i0, i1 + 1);
1805                        } else {
1806                                f2 = i1 < 0 ? 0 : d.getDouble(i0 + 1, i1) * m.getDouble(i0 + 1, i1);
1807                                if (i1 == e1) {
1808                                        f4 = 0;
1809                                        f3 = 0;
1810                                } else {
1811                                        f4 = d.getDouble(i0 + 1, i1 + 1) * m.getDouble(i0 + 1, i1 + 1);
1812                                        f3 = i0 < 0 ? 0 : d.getDouble(i0, i1 + 1) * m.getDouble(i0, i1 + 1);
1813                                }
1814                        }
1815                        r = (1 - u0) * (1 - u1) * f1 + u0 * (1 - u1) * f2 + (1 - u0) * u1 * f3 + u0 * u1 * f4;
1816                } else { // exactly on axis 1
1817                        if (u0 > 0) {
1818                                f2 = i0 == e0 || i1 < 0 ? 0 : d.getDouble(i0 + 1, i1) * m.getDouble(i0 + 1, i1);
1819                                r = (1 - u0) * f1 + u0 * f2;
1820                        } else { // exactly on axis 0
1821                                r = f1;
1822                        }
1823                }
1824                return r;
1825        }
1826
1827        /**
1828         * Linearly interpolate an array of values at a point in a compound 2D
1829         * dataset. The dataset is considered to have zero support outside its
1830         * bounds. Thus points just outside are interpolated from the boundary value
1831         * to zero.
1832         * 
1833         * @param values
1834         *            bilinear interpolated array
1835         * @param d
1836         * @param x0
1837         * @param x1
1838         */
1839        public static void interpolate(final double[] values, final CompoundDataset d, final double x0, final double x1) {
1840                final int[] s = d.getShapeRef();
1841                assert s.length == 2;
1842
1843                final int is = d.getElementsPerItem();
1844                if (is != values.length) {
1845                        throw new IllegalArgumentException("Output array length must match elements in item");
1846                }
1847
1848                final int e0 = s[0] - 1;
1849                final int e1 = s[1] - 1;
1850                final int i0 = (int) Math.floor(x0);
1851                final int i1 = (int) Math.floor(x1);
1852                final double u0 = x0 - i0;
1853                final double u1 = x1 - i1;
1854                if (i0 < -1 || i0 > e0 || i1 < -1 || i1 > e1) {
1855                        Arrays.fill(values, 0);
1856                        return;
1857                }
1858                // use bilinear interpolation
1859                double[] f1 = new double[is];
1860                if (i0 >= 0 && i1 >= 0) {
1861                        d.getDoubleArray(f1, i0, i1);
1862                }
1863
1864                if (u1 > 0) {
1865                        if (u0 > 0) {
1866                                double[] f2 = new double[is];
1867                                double[] f3 = new double[is];
1868                                double[] f4 = new double[is];
1869                                if (i0 != e0) {
1870                                        if (i1 != e1) {
1871                                                d.getDoubleArray(f3, i0 + 1, i1 + 1);
1872                                        }
1873                                        if (i1 >= 0) {
1874                                                d.getDoubleArray(f4, i0 + 1, i1);
1875                                        }
1876                                }
1877                                if (i0 >= 0 && i1 != e1) {
1878                                        d.getDoubleArray(f2, i0, i1 + 1);
1879                                }
1880                                final double t0 = 1 - u0;
1881                                final double t1 = 1 - u1;
1882                                final double w1 = t0 * t1;
1883                                final double w2 = t0 * u1;
1884                                final double w3 = u0 * u1;
1885                                final double w4 = u0 * t1;
1886                                for (int j = 0; j < is; j++) {
1887                                        values[j] = w1 * f1[j] + w2 * f2[j] + w3 * f3[j] + w4 * f4[j];
1888                                }
1889                        } else {
1890                                double[] f2 = new double[is];
1891                                if (i0 >= 0 && i1 != e1) {
1892                                        d.getDoubleArray(f2, i0, i1 + 1);
1893                                }
1894                                final double t1 = 1 - u1;
1895                                for (int j = 0; j < is; j++) {
1896                                        values[j] = t1 * f1[j] + u1 * f2[j];
1897                                }
1898                        }
1899                } else { // exactly on axis 1
1900                        if (u0 > 0) {
1901                                double[] f4 = new double[is];
1902                                if (i0 != e0 && i1 >= 0) {
1903                                        d.getDoubleArray(f4, i0 + 1, i1);
1904                                }
1905                                final double t0 = 1 - u0;
1906                                for (int j = 0; j < is; j++) {
1907                                        values[j] = t0 * f1[j] + u0 * f4[j];
1908                                }
1909                        } else { // exactly on axis 0
1910                                if (i0 >= 0 && i1 >= 0) {
1911                                        d.getDoubleArray(values, i0, i1);
1912                                } else {
1913                                        Arrays.fill(values, 0);
1914                                }
1915                        }
1916                }
1917        }
1918
1919        /**
1920         * Linearly interpolate a value at a point in a n-D dataset. The dataset is
1921         * considered to have zero support outside its bounds. Thus points just
1922         * outside are interpolated from the boundary value to zero. The number of
1923         * coordinates must match the rank of the dataset.
1924         * 
1925         * @param d
1926         *            input dataset
1927         * @param x
1928         *            coordinates
1929         * @return interpolated value
1930         */
1931        public static double interpolate(final Dataset d, final double... x) {
1932                return interpolate(d, null, x);
1933        }
1934
1935        /**
1936         * Linearly interpolate a value at a point in a n-D dataset with a mask. The
1937         * dataset is considered to have zero support outside its bounds. Thus
1938         * points just outside are interpolated from the boundary value to zero. The
1939         * number of coordinates must match the rank of the dataset.
1940         * 
1941         * @param d
1942         *            input dataset
1943         * @param m
1944         *            mask dataset (can be null)
1945         * @param x
1946         *            coordinates
1947         * @return interpolated value
1948         */
1949        public static double interpolate(final Dataset d, final Dataset m, final double... x) {
1950                int r = d.getRank();
1951                if (r != x.length) {
1952                        throw new IllegalArgumentException("Number of coordinates must be equal to rank of dataset");
1953                }
1954
1955                switch (r) {
1956                case 1:
1957                        return m == null ? interpolate(d, x[0]) : interpolate(d, m, x[0]);
1958                case 2:
1959                        return m == null ? interpolate(d, x[0], x[1]) : interpolate(d, m, x[0], x[1]);
1960                }
1961
1962                if (m != null && r != m.getRank()) {
1963                        throw new IllegalArgumentException("Rank of mask dataset must be equal to rank of dataset");
1964                }
1965
1966                // now do it iteratively
1967                int[] l = new int[r]; // lower indexes
1968                double[] f = new double[r]; // fractions
1969                for (int i = 0; i < r; i++) {
1970                        double xi = x[i];
1971                        l[i] = (int) Math.floor(xi);
1972                        f[i] = xi - l[i];
1973                }
1974
1975                int[] s = d.getShape();
1976
1977                int n = 1 << r;
1978                double[] results = new double[n];
1979
1980                // iterate over permutations {l} and {l+1}
1981                int[] twos = new int[r];
1982                Arrays.fill(twos, 2);
1983                PositionIterator it = new PositionIterator(twos);
1984                int[] ip = it.getPos();
1985                int j = 0;
1986                if (m == null) {
1987                        while (it.hasNext()) {
1988                                int[] p = l.clone();
1989                                boolean omit = false;
1990                                for (int i = 0; i < r; i++) {
1991                                        int pi = p[i] + ip[i];
1992                                        if (pi < 0 || pi >= s[i]) {
1993                                                omit = true;
1994                                                break;
1995                                        }
1996                                        p[i] = pi;
1997                                }
1998                                results[j++] = omit ? 0 : d.getDouble(p);
1999                        }
2000                } else {
2001                        while (it.hasNext()) {
2002                                int[] p = l.clone();
2003                                boolean omit = false;
2004                                for (int i = 0; i < r; i++) {
2005                                        int pi = p[i] + ip[i];
2006                                        if (pi < 0 || pi >= s[i]) {
2007                                                omit = true;
2008                                                break;
2009                                        }
2010                                        p[i] = pi;
2011                                }
2012                                results[j++] = omit ? 0 : d.getDouble(p) * m.getDouble(p);
2013                        }
2014                }
2015
2016                // reduce recursively
2017                for (int i = r - 1; i >= 0; i--) {
2018                        results = combine(results, f[i], 1 << i);
2019                }
2020                return results[0];
2021        }
2022
2023        private static double[] combine(double[] values, double f, int n) {
2024                double g = 1 - f;
2025                double[] results = new double[n];
2026                for (int j = 0; j < n; j++) {
2027                        int tj = 2 * j;
2028                        results[j] = g * values[tj] + f * values[tj + 1];
2029                }
2030
2031                return results;
2032        }
2033
2034        /**
2035         * Linearly interpolate an array of values at a point in a compound n-D
2036         * dataset. The dataset is considered to have zero support outside its
2037         * bounds. Thus points just outside are interpolated from the boundary value
2038         * to zero.
2039         * 
2040         * @param values
2041         *            linearly interpolated array
2042         * @param d
2043         * @param x
2044         */
2045        public static void interpolate(final double[] values, final CompoundDataset d, final double... x) {
2046                int r = d.getRank();
2047                if (r != x.length) {
2048                        throw new IllegalArgumentException("Number of coordinates must be equal to rank of dataset");
2049                }
2050
2051                switch (r) {
2052                case 1:
2053                        interpolate(values, d, x[0]);
2054                        return;
2055                case 2:
2056                        interpolate(values, d, x[0], x[1]);
2057                        return;
2058                }
2059
2060                final int is = d.getElementsPerItem();
2061                if (is != values.length) {
2062                        throw new IllegalArgumentException("Output array length must match elements in item");
2063                }
2064
2065                // now do it iteratively
2066                int[] l = new int[r]; // lower indexes
2067                double[] f = new double[r]; // fractions
2068                for (int i = 0; i < r; i++) {
2069                        double xi = x[i];
2070                        l[i] = (int) Math.floor(xi);
2071                        f[i] = xi - l[i];
2072                }
2073
2074                int[] s = d.getShape();
2075
2076                int n = 1 << r;
2077                double[][] results = new double[n][is];
2078
2079                // iterate over permutations {l} and {l+1}
2080                int[] twos = new int[r];
2081                Arrays.fill(twos, 2);
2082                PositionIterator it = new PositionIterator(twos);
2083                int[] ip = it.getPos();
2084                int j = 0;
2085                while (it.hasNext()) {
2086                        int[] p = l.clone();
2087                        boolean omit = false;
2088                        for (int i = 0; i < r; i++) {
2089                                int pi = p[i] + ip[i];
2090                                if (pi < 0 || pi >= s[i]) {
2091                                        omit = true;
2092                                        break;
2093                                }
2094                                p[i] = pi;
2095                        }
2096                        if (!omit) {
2097                                d.getDoubleArray(results[j++], p);
2098                        }
2099                }
2100
2101                // reduce recursively
2102                for (int i = r - 1; i >= 0; i--) {
2103                        results = combineArray(is, results, f[i], 1 << i);
2104                }
2105                for (int k = 0; k < is; k++) {
2106                        values[k] = results[0][k];
2107                }
2108        }
2109
2110        private static double[][] combineArray(int is, double[][] values, double f, int n) {
2111                double g = 1 - f;
2112                double[][] results = new double[n][is];
2113                for (int j = 0; j < n; j++) {
2114                        int tj = 2 * j;
2115                        for (int k = 0; k < is; k++) {
2116                                results[j][k] = g * values[tj][k] + f * values[tj + 1][k];
2117                        }
2118                }
2119
2120                return results;
2121        }
2122
2123        /**
2124         * Linearly interpolate a value at a point in a 1D dataset. The dataset is
2125         * considered to have zero support outside its bounds. Thus points just
2126         * outside are interpolated from the boundary value to zero.
2127         * 
2128         * @param d
2129         *            input dataset
2130         * @param x0
2131         *            coordinate
2132         * @return interpolated value
2133         * @deprecated Use {@link #interpolate(Dataset, double)}
2134         */
2135        @Deprecated
2136        public static double getLinear(final IDataset d, final double x0) {
2137                return interpolate(DatasetUtils.convertToDataset(d), x0);
2138        }
2139
2140        /**
2141         * Linearly interpolate a value at a point in a compound 1D dataset. The
2142         * dataset is considered to have zero support outside its bounds. Thus
2143         * points just outside are interpolated from the boundary value to zero.
2144         * 
2145         * @param values
2146         *            interpolated array
2147         * @param d
2148         *            input dataset
2149         * @param x0
2150         *            coordinate
2151         * @deprecated Use {@link #interpolate(double[], CompoundDataset, double)}
2152         */
2153        @Deprecated
2154        public static void getLinear(final double[] values, final CompoundDataset d, final double x0) {
2155                interpolate(values, d, x0);
2156        }
2157
2158        /**
2159         * Interpolated a value from 2D dataset
2160         * 
2161         * @param d
2162         *            input dataset
2163         * @param x0
2164         *            coordinate
2165         * @param x1
2166         *            coordinate
2167         * @return bilinear interpolation
2168         * @deprecated Use {@link #interpolate(Dataset, double, double)}
2169         */
2170        @Deprecated
2171        public static double getBilinear(final IDataset d, final double x0, final double x1) {
2172                return interpolate(DatasetUtils.convertToDataset(d), x0, x1);
2173        }
2174
2175        /**
2176         * Interpolated a value from 2D dataset with mask
2177         * 
2178         * @param d
2179         *            input dataset
2180         * @param m
2181         *            mask dataset
2182         * @param x0
2183         *            coordinate
2184         * @param x1
2185         *            coordinate
2186         * @return bilinear interpolation
2187         * @deprecated Use {@link #interpolate(Dataset, Dataset, double, double)}
2188         */
2189        @Deprecated
2190        public static double getBilinear(final IDataset d, final IDataset m, final double x0, final double x1) {
2191                return interpolate(DatasetUtils.convertToDataset(d), DatasetUtils.convertToDataset(m), x0, x1);
2192        }
2193
2194        /**
2195         * Interpolated a value from 2D compound dataset
2196         * 
2197         * @param values
2198         *            bilinear interpolated array
2199         * @param d
2200         * @param x0
2201         * @param x1
2202         * @deprecated Use
2203         *             {@link #interpolate(double[], CompoundDataset, double, double)}
2204         */
2205        @Deprecated
2206        public static void getBilinear(final double[] values, final CompoundDataset d, final double x0, final double x1) {
2207                interpolate(values, d, x0, x1);
2208        }
2209
2210        /**
2211         * generate binomial coefficients with negative sign:
2212         * <p>
2213         * 
2214         * <pre>
2215         *  (-1)^i n! / ( i! (n-i)! )
2216         * </pre>
2217         * 
2218         * @param n
2219         * @return array of coefficients
2220         */
2221        private static int[] bincoeff(final int n) {
2222                final int[] b = new int[n + 1];
2223                final int hn = n / 2;
2224
2225                int bc = 1;
2226                b[0] = bc;
2227                for (int i = 1; i <= hn; i++) {
2228                        bc = -(bc * (n - i + 1)) / i;
2229                        b[i] = bc;
2230                }
2231                if (n % 2 != 0) {
2232                        for (int i = hn + 1; i <= n; i++) {
2233                                b[i] = -b[n - i];
2234                        }
2235                } else {
2236                        for (int i = hn + 1; i <= n; i++) {
2237                                b[i] = b[n - i];
2238                        }
2239                }
2240                return b;
2241        }
2242
2243        /**
2244         * 1st order discrete difference of dataset along flattened dataset using
2245         * finite difference
2246         * 
2247         * @param a
2248         *            is 1d dataset
2249         * @param out
2250         *            is 1d dataset
2251         */
2252        private static void difference(final Dataset a, final Dataset out) {
2253                final int isize = a.getElementsPerItem();
2254
2255                final IndexIterator it = a.getIterator();
2256                if (!it.hasNext())
2257                        return;
2258                int oi = it.index;
2259
2260                switch (a.getDType()) {
2261                case Dataset.INT8:
2262                        final byte[] i8data = ((ByteDataset) a).getData();
2263                        final byte[] oi8data = ((ByteDataset) out).getData();
2264                        for (int i = 0; it.hasNext();) {
2265                                oi8data[i++] = (byte) (i8data[it.index] - i8data[oi]);
2266                                oi = it.index;
2267                        }
2268                        break;
2269                case Dataset.INT16:
2270                        final short[] i16data = ((ShortDataset) a).getData();
2271                        final short[] oi16data = ((ShortDataset) out).getData();
2272                        for (int i = 0; it.hasNext();) {
2273                                oi16data[i++] = (short) (i16data[it.index] - i16data[oi]);
2274                                oi = it.index;
2275                        }
2276                        break;
2277                case Dataset.INT32:
2278                        final int[] i32data = ((IntegerDataset) a).getData();
2279                        final int[] oi32data = ((IntegerDataset) out).getData();
2280                        for (int i = 0; it.hasNext();) {
2281                                oi32data[i++] = i32data[it.index] - i32data[oi];
2282                                oi = it.index;
2283                        }
2284                        break;
2285                case Dataset.INT64:
2286                        final long[] i64data = ((LongDataset) a).getData();
2287                        final long[] oi64data = ((LongDataset) out).getData();
2288                        for (int i = 0; it.hasNext();) {
2289                                oi64data[i++] = i64data[it.index] - i64data[oi];
2290                                oi = it.index;
2291                        }
2292                        break;
2293                case Dataset.ARRAYINT8:
2294                        final byte[] ai8data = ((CompoundByteDataset) a).getData();
2295                        final byte[] oai8data = ((CompoundByteDataset) out).getData();
2296                        for (int i = 0; it.hasNext();) {
2297                                for (int k = 0; k < isize; k++) {
2298                                        oai8data[i++] = (byte) (ai8data[it.index + k] - ai8data[oi++]);
2299                                }
2300                                oi = it.index;
2301                        }
2302                        break;
2303                case Dataset.ARRAYINT16:
2304                        final short[] ai16data = ((CompoundShortDataset) a).getData();
2305                        final short[] oai16data = ((CompoundShortDataset) out).getData();
2306                        for (int i = 0; it.hasNext();) {
2307                                for (int k = 0; k < isize; k++) {
2308                                        oai16data[i++] = (short) (ai16data[it.index + k] - ai16data[oi++]);
2309                                }
2310                                oi = it.index;
2311                        }
2312                        break;
2313                case Dataset.ARRAYINT32:
2314                        final int[] ai32data = ((CompoundIntegerDataset) a).getData();
2315                        final int[] oai32data = ((CompoundIntegerDataset) out).getData();
2316                        for (int i = 0; it.hasNext();) {
2317                                for (int k = 0; k < isize; k++) {
2318                                        oai32data[i++] = ai32data[it.index + k] - ai32data[oi++];
2319                                }
2320                                oi = it.index;
2321                        }
2322                        break;
2323                case Dataset.ARRAYINT64:
2324                        final long[] ai64data = ((CompoundLongDataset) a).getData();
2325                        final long[] oai64data = ((CompoundLongDataset) out).getData();
2326                        for (int i = 0; it.hasNext();) {
2327                                for (int k = 0; k < isize; k++) {
2328                                        oai64data[i++] = ai64data[it.index + k] - ai64data[oi++];
2329                                }
2330                                oi = it.index;
2331                        }
2332                        break;
2333                case Dataset.FLOAT32:
2334                        final float[] f32data = ((FloatDataset) a).getData();
2335                        final float[] of32data = ((FloatDataset) out).getData();
2336                        for (int i = 0; it.hasNext();) {
2337                                of32data[i++] = f32data[it.index] - f32data[oi];
2338                                oi = it.index;
2339                        }
2340                        break;
2341                case Dataset.FLOAT64:
2342                        final double[] f64data = ((DoubleDataset) a).getData();
2343                        final double[] of64data = ((DoubleDataset) out).getData();
2344                        for (int i = 0; it.hasNext();) {
2345                                of64data[i++] = f64data[it.index] - f64data[oi];
2346                                oi = it.index;
2347                        }
2348                        break;
2349                case Dataset.COMPLEX64:
2350                        final float[] c64data = ((ComplexFloatDataset) a).getData();
2351                        final float[] oc64data = ((ComplexFloatDataset) out).getData();
2352                        for (int i = 0; it.hasNext();) {
2353                                oc64data[i++] = c64data[it.index] - c64data[oi];
2354                                oc64data[i++] = c64data[it.index + 1] - c64data[oi + 1];
2355                                oi = it.index;
2356                        }
2357                        break;
2358                case Dataset.COMPLEX128:
2359                        final double[] c128data = ((ComplexDoubleDataset) a).getData();
2360                        final double[] oc128data = ((ComplexDoubleDataset) out).getData();
2361                        for (int i = 0; it.hasNext();) {
2362                                oc128data[i++] = c128data[it.index] - c128data[oi];
2363                                oc128data[i++] = c128data[it.index + 1] - c128data[oi + 1];
2364                                oi = it.index;
2365                        }
2366                        break;
2367                case Dataset.ARRAYFLOAT32:
2368                        final float[] af32data = ((CompoundFloatDataset) a).getData();
2369                        final float[] oaf32data = ((CompoundFloatDataset) out).getData();
2370                        for (int i = 0; it.hasNext();) {
2371                                for (int k = 0; k < isize; k++) {
2372                                        oaf32data[i++] = af32data[it.index + k] - af32data[oi++];
2373                                }
2374                                oi = it.index;
2375                        }
2376                        break;
2377                case Dataset.ARRAYFLOAT64:
2378                        final double[] af64data = ((CompoundDoubleDataset) a).getData();
2379                        final double[] oaf64data = ((CompoundDoubleDataset) out).getData();
2380                        for (int i = 0; it.hasNext();) {
2381                                for (int k = 0; k < isize; k++) {
2382                                        oaf64data[i++] = af64data[it.index + k] - af64data[oi++];
2383                                }
2384                                oi = it.index;
2385                        }
2386                        break;
2387                default:
2388                        throw new UnsupportedOperationException("difference does not support this dataset type");
2389                }
2390        }
2391
2392        /**
2393         * Get next set of indexes
2394         * 
2395         * @param it
2396         * @param indexes
2397         * @return true if there is more
2398         */
2399        private static boolean nextIndexes(IndexIterator it, int[] indexes) {
2400                if (!it.hasNext())
2401                        return false;
2402                int m = indexes.length;
2403                int i = 0;
2404                for (i = 0; i < m - 1; i++) {
2405                        indexes[i] = indexes[i + 1];
2406                }
2407                indexes[i] = it.index;
2408                return true;
2409        }
2410
2411        /**
2412         * General order discrete difference of dataset along flattened dataset
2413         * using finite difference
2414         * 
2415         * @param a
2416         *            is 1d dataset
2417         * @param out
2418         *            is 1d dataset
2419         * @param n
2420         *            order of difference
2421         */
2422        private static void difference(final Dataset a, final Dataset out, final int n) {
2423                if (n == 1) {
2424                        difference(a, out);
2425                        return;
2426                }
2427
2428                final int isize = a.getElementsPerItem();
2429
2430                final int[] coeff = bincoeff(n);
2431                final int m = n + 1;
2432                final int[] indexes = new int[m]; // store for index values
2433
2434                final IndexIterator it = a.getIterator();
2435                for (int i = 0; i < n; i++) {
2436                        indexes[i] = it.index;
2437                        it.hasNext();
2438                }
2439                indexes[n] = it.index;
2440
2441                switch (a.getDType()) {
2442                case Dataset.INT8:
2443                        final byte[] i8data = ((ByteDataset) a).getData();
2444                        final byte[] oi8data = ((ByteDataset) out).getData();
2445                        for (int i = 0; nextIndexes(it, indexes);) {
2446                                int ox = 0;
2447                                for (int j = 0; j < m; j++) {
2448                                        ox += i8data[indexes[j]] * coeff[j];
2449                                }
2450                                oi8data[i++] = (byte) ox;
2451                        }
2452                        break;
2453                case Dataset.INT16:
2454                        final short[] i16data = ((ShortDataset) a).getData();
2455                        final short[] oi16data = ((ShortDataset) out).getData();
2456                        for (int i = 0; nextIndexes(it, indexes);) {
2457                                int ox = 0;
2458                                for (int j = 0; j < m; j++) {
2459                                        ox += i16data[indexes[j]] * coeff[j];
2460                                }
2461                                oi16data[i++] = (short) ox;
2462                        }
2463                        break;
2464                case Dataset.INT32:
2465                        final int[] i32data = ((IntegerDataset) a).getData();
2466                        final int[] oi32data = ((IntegerDataset) out).getData();
2467                        for (int i = 0; nextIndexes(it, indexes);) {
2468                                int ox = 0;
2469                                for (int j = 0; j < m; j++) {
2470                                        ox += i32data[indexes[j]] * coeff[j];
2471                                }
2472                                oi32data[i++] = ox;
2473                        }
2474                        break;
2475                case Dataset.INT64:
2476                        final long[] i64data = ((LongDataset) a).getData();
2477                        final long[] oi64data = ((LongDataset) out).getData();
2478                        for (int i = 0; nextIndexes(it, indexes);) {
2479                                long ox = 0;
2480                                for (int j = 0; j < m; j++) {
2481                                        ox += i64data[indexes[j]] * coeff[j];
2482                                }
2483                                oi64data[i++] = ox;
2484                        }
2485                        break;
2486                case Dataset.ARRAYINT8:
2487                        final byte[] ai8data = ((CompoundByteDataset) a).getData();
2488                        final byte[] oai8data = ((CompoundByteDataset) out).getData();
2489                        int[] box = new int[isize];
2490                        for (int i = 0; nextIndexes(it, indexes);) {
2491                                Arrays.fill(box, 0);
2492                                for (int j = 0; j < m; j++) {
2493                                        double c = coeff[j];
2494                                        int l = indexes[j];
2495                                        for (int k = 0; k < isize; k++) {
2496                                                box[k] += ai8data[l++] * c;
2497                                        }
2498                                }
2499                                for (int k = 0; k < isize; k++) {
2500                                        oai8data[i++] = (byte) box[k];
2501                                }
2502                        }
2503                        break;
2504                case Dataset.ARRAYINT16:
2505                        final short[] ai16data = ((CompoundShortDataset) a).getData();
2506                        final short[] oai16data = ((CompoundShortDataset) out).getData();
2507                        int[] sox = new int[isize];
2508                        for (int i = 0; nextIndexes(it, indexes);) {
2509                                Arrays.fill(sox, 0);
2510                                for (int j = 0; j < m; j++) {
2511                                        double c = coeff[j];
2512                                        int l = indexes[j];
2513                                        for (int k = 0; k < isize; k++) {
2514                                                sox[k] += ai16data[l++] * c;
2515                                        }
2516                                }
2517                                for (int k = 0; k < isize; k++) {
2518                                        oai16data[i++] = (short) sox[k];
2519                                }
2520                        }
2521                        break;
2522                case Dataset.ARRAYINT32:
2523                        final int[] ai32data = ((CompoundIntegerDataset) a).getData();
2524                        final int[] oai32data = ((CompoundIntegerDataset) out).getData();
2525                        int[] iox = new int[isize];
2526                        for (int i = 0; nextIndexes(it, indexes);) {
2527                                Arrays.fill(iox, 0);
2528                                for (int j = 0; j < m; j++) {
2529                                        double c = coeff[j];
2530                                        int l = indexes[j];
2531                                        for (int k = 0; k < isize; k++) {
2532                                                iox[k] += ai32data[l++] * c;
2533                                        }
2534                                }
2535                                for (int k = 0; k < isize; k++) {
2536                                        oai32data[i++] = iox[k];
2537                                }
2538                        }
2539                        break;
2540                case Dataset.ARRAYINT64:
2541                        final long[] ai64data = ((CompoundLongDataset) a).getData();
2542                        final long[] oai64data = ((CompoundLongDataset) out).getData();
2543                        long[] lox = new long[isize];
2544                        for (int i = 0; nextIndexes(it, indexes);) {
2545                                Arrays.fill(lox, 0);
2546                                for (int j = 0; j < m; j++) {
2547                                        double c = coeff[j];
2548                                        int l = indexes[j];
2549                                        for (int k = 0; k < isize; k++) {
2550                                                lox[k] += ai64data[l++] * c;
2551                                        }
2552                                }
2553                                for (int k = 0; k < isize; k++) {
2554                                        oai64data[i++] = lox[k];
2555                                }
2556                        }
2557                        break;
2558                case Dataset.FLOAT32:
2559                        final float[] f32data = ((FloatDataset) a).getData();
2560                        final float[] of32data = ((FloatDataset) out).getData();
2561                        for (int i = 0; nextIndexes(it, indexes);) {
2562                                float ox = 0;
2563                                for (int j = 0; j < m; j++) {
2564                                        ox += f32data[indexes[j]] * coeff[j];
2565                                }
2566                                of32data[i++] = ox;
2567                        }
2568                        break;
2569                case Dataset.FLOAT64:
2570                        final double[] f64data = ((DoubleDataset) a).getData();
2571                        final double[] of64data = ((DoubleDataset) out).getData();
2572                        for (int i = 0; nextIndexes(it, indexes);) {
2573                                double ox = 0;
2574                                for (int j = 0; j < m; j++) {
2575                                        ox += f64data[indexes[j]] * coeff[j];
2576                                }
2577                                of64data[i++] = ox;
2578                        }
2579                        break;
2580                case Dataset.COMPLEX64:
2581                        final float[] c64data = ((ComplexFloatDataset) a).getData();
2582                        final float[] oc64data = ((ComplexFloatDataset) out).getData();
2583                        for (int i = 0; nextIndexes(it, indexes);) {
2584                                float ox = 0;
2585                                float oy = 0;
2586                                for (int j = 0; j < m; j++) {
2587                                        int l = indexes[j];
2588                                        ox += c64data[l++] * coeff[j];
2589                                        oy += c64data[l] * coeff[j];
2590                                }
2591                                oc64data[i++] = ox;
2592                                oc64data[i++] = oy;
2593                        }
2594                        break;
2595                case Dataset.COMPLEX128:
2596                        final double[] c128data = ((ComplexDoubleDataset) a).getData();
2597                        final double[] oc128data = ((ComplexDoubleDataset) out).getData();
2598                        for (int i = 0; nextIndexes(it, indexes);) {
2599                                double ox = 0;
2600                                double oy = 0;
2601                                for (int j = 0; j < m; j++) {
2602                                        int l = indexes[j];
2603                                        ox += c128data[l++] * coeff[j];
2604                                        oy += c128data[l] * coeff[j];
2605                                }
2606                                oc128data[i++] = ox;
2607                                oc128data[i++] = oy;
2608                        }
2609                        break;
2610                case Dataset.ARRAYFLOAT32:
2611                        final float[] af32data = ((CompoundFloatDataset) a).getData();
2612                        final float[] oaf32data = ((CompoundFloatDataset) out).getData();
2613                        float[] fox = new float[isize];
2614                        for (int i = 0; nextIndexes(it, indexes);) {
2615                                Arrays.fill(fox, 0);
2616                                for (int j = 0; j < m; j++) {
2617                                        double c = coeff[j];
2618                                        int l = indexes[j];
2619                                        for (int k = 0; k < isize; k++) {
2620                                                fox[k] += af32data[l++] * c;
2621                                        }
2622                                }
2623                                for (int k = 0; k < isize; k++) {
2624                                        oaf32data[i++] = fox[k];
2625                                }
2626                        }
2627                        break;
2628                case Dataset.ARRAYFLOAT64:
2629                        final double[] af64data = ((CompoundDoubleDataset) a).getData();
2630                        final double[] oaf64data = ((CompoundDoubleDataset) out).getData();
2631                        double[] dox = new double[isize];
2632                        for (int i = 0; nextIndexes(it, indexes);) {
2633                                Arrays.fill(dox, 0);
2634                                for (int j = 0; j < m; j++) {
2635                                        double c = coeff[j];
2636                                        int l = indexes[j];
2637                                        for (int k = 0; k < isize; k++) {
2638                                                dox[k] += af64data[l++] * c;
2639                                        }
2640                                }
2641                                for (int k = 0; k < isize; k++) {
2642                                        oaf64data[i++] = dox[k];
2643                                }
2644                        }
2645                        break;
2646                default:
2647                        throw new UnsupportedOperationException("difference does not support multiple-element dataset");
2648                }
2649        }
2650
2651        /**
2652         * Discrete difference of dataset along axis using finite difference
2653         * 
2654         * @param a
2655         * @param n
2656         *            order of difference
2657         * @param axis
2658         * @return difference
2659         */
2660        public static Dataset difference(Dataset a, final int n, int axis) {
2661                Dataset ds;
2662                final Class<? extends Dataset> clazz = a.getClass();
2663                final int rank = a.getRank();
2664                final int is = a.getElementsPerItem();
2665
2666                if (axis < 0) {
2667                        axis += rank;
2668                }
2669                if (axis < 0 || axis >= rank) {
2670                        throw new IllegalArgumentException("Axis is out of range");
2671                }
2672
2673                int[] nshape = a.getShape();
2674                if (nshape[axis] <= n) {
2675                        nshape[axis] = 0;
2676                        return DatasetFactory.zeros(is, clazz, nshape);
2677                }
2678
2679                nshape[axis] -= n;
2680                ds = DatasetFactory.zeros(is, clazz, nshape);
2681                if (rank == 1) {
2682                        difference(a, ds, n);
2683                } else {
2684                        final Dataset src = DatasetFactory.zeros(is, clazz, a.getShapeRef()[axis]);
2685                        final Dataset dest = DatasetFactory.zeros(is, clazz, nshape[axis]);
2686                        final PositionIterator pi = a.getPositionIterator(axis);
2687                        final int[] pos = pi.getPos();
2688                        final boolean[] hit = pi.getOmit();
2689                        while (pi.hasNext()) {
2690                                a.copyItemsFromAxes(pos, hit, src);
2691                                difference(src, dest, n);
2692                                ds.setItemsOnAxes(pos, hit, dest.getBuffer());
2693                        }
2694                }
2695
2696                return ds;
2697        }
2698
2699        private static double SelectedMean(Dataset data, int Min, int Max) {
2700
2701                double result = 0.0;
2702                for (int i = Min, imax = data.getSize(); i <= Max; i++) {
2703                        // clip i appropriately, imagine that effectively the two ends
2704                        // continue
2705                        // straight out.
2706                        int pos = i;
2707                        if (pos < 0) {
2708                                pos = 0;
2709                        } else if (pos >= imax) {
2710                                pos = imax - 1;
2711                        }
2712                        result += data.getElementDoubleAbs(pos);
2713                }
2714
2715                // now the sum is complete, average the values.
2716                result /= (Max - Min) + 1;
2717                return result;
2718        }
2719
2720        private static void SelectedMeanArray(double[] out, Dataset data, int Min, int Max) {
2721                final int isize = out.length;
2722                for (int j = 0; j < isize; j++)
2723                        out[j] = 0.;
2724
2725                for (int i = Min, imax = data.getSize(); i <= Max; i++) {
2726                        // clip i appropriately, imagine that effectively the two ends
2727                        // continue
2728                        // straight out.
2729                        int pos = i * isize;
2730                        if (pos < 0) {
2731                                pos = 0;
2732                        } else if (pos >= imax) {
2733                                pos = imax - isize;
2734                        }
2735                        for (int j = 0; j < isize; j++)
2736                                out[j] += data.getElementDoubleAbs(pos + j);
2737                }
2738
2739                // now the sum is complete, average the values.
2740                double norm = 1. / (Max - Min + 1.);
2741                for (int j = 0; j < isize; j++)
2742                        out[j] *= norm;
2743
2744        }
2745
2746        /**
2747         * Calculates the derivative of a line described by two datasets (x,y) given
2748         * a spread of n either side of the point
2749         * 
2750         * @param x
2751         *            The x values of the function to take the derivative of.
2752         * @param y
2753         *            The y values of the function to take the derivative of.
2754         * @param n
2755         *            The spread the derivative is calculated from, i.e. the
2756         *            smoothing, the higher the value, the more smoothing occurs.
2757         * @return A dataset which contains all the derivative point for point.
2758         */
2759        public static Dataset derivative(Dataset x, Dataset y, int n) {
2760                if (x.getRank() != 1 || y.getRank() != 1) {
2761                        throw new IllegalArgumentException("Only one dimensional dataset supported");
2762                }
2763                if (y.getSize() > x.getSize()) {
2764                        throw new IllegalArgumentException("Length of x dataset should be greater than or equal to y's");
2765                }
2766                int dtype = y.getDType();
2767                Dataset result;
2768                switch (dtype) {
2769                case Dataset.BOOL:
2770                case Dataset.INT8:
2771                case Dataset.INT16:
2772                case Dataset.ARRAYINT8:
2773                case Dataset.ARRAYINT16:
2774                        result = DatasetFactory.zeros(y, FloatDataset.class);
2775                        break;
2776                case Dataset.INT32:
2777                case Dataset.INT64:
2778                case Dataset.ARRAYINT32:
2779                case Dataset.ARRAYINT64:
2780                        result = DatasetFactory.zeros(y, DoubleDataset.class);
2781                        break;
2782                case Dataset.FLOAT32:
2783                case Dataset.FLOAT64:
2784                case Dataset.COMPLEX64:
2785                case Dataset.COMPLEX128:
2786                case Dataset.ARRAYFLOAT32:
2787                case Dataset.ARRAYFLOAT64:
2788                        result = DatasetFactory.zeros(y);
2789                        break;
2790                default:
2791                        throw new UnsupportedOperationException("derivative does not support multiple-element dataset");
2792                }
2793
2794                final int isize = y.getElementsPerItem();
2795                if (isize == 1) {
2796                        for (int i = 0, imax = x.getSize(); i < imax; i++) {
2797                                double LeftValue = SelectedMean(y, i - n, i - 1);
2798                                double RightValue = SelectedMean(y, i + 1, i + n);
2799                                double LeftPosition = SelectedMean(x, i - n, i - 1);
2800                                double RightPosition = SelectedMean(x, i + 1, i + n);
2801
2802                                // now the values and positions are calculated, the derivative
2803                                // can be
2804                                // calculated.
2805                                result.set(((RightValue - LeftValue) / (RightPosition - LeftPosition)), i);
2806                        }
2807                } else {
2808                        double[] leftValues = new double[isize];
2809                        double[] rightValues = new double[isize];
2810                        for (int i = 0, imax = x.getSize(); i < imax; i++) {
2811                                SelectedMeanArray(leftValues, y, i - n, i - 1);
2812                                SelectedMeanArray(rightValues, y, i + 1, i + n);
2813                                double delta = SelectedMean(x, i - n, i - 1);
2814                                delta = 1. / (SelectedMean(x, i + 1, i + n) - delta);
2815                                for (int j = 0; j < isize; j++) {
2816                                        rightValues[j] -= leftValues[j];
2817                                        rightValues[j] *= delta;
2818                                }
2819                                result.set(rightValues, i);
2820                        }
2821                }
2822
2823                // set the name based on the changes made
2824                result.setName(y.getName() + "'");
2825
2826                return result;
2827        }
2828
2829        /**
2830         * Discrete difference of dataset along axis using finite central difference
2831         * 
2832         * @param a
2833         * @param axis
2834         * @return difference
2835         */
2836        public static Dataset centralDifference(Dataset a, int axis) {
2837                Dataset ds;
2838                final Class<? extends Dataset> clazz = a.getClass();
2839                final int rank = a.getRank();
2840                final int is = a.getElementsPerItem();
2841
2842                if (axis < 0) {
2843                        axis += rank;
2844                }
2845                if (axis < 0 || axis >= rank) {
2846                        throw new IllegalArgumentException("Axis is out of range");
2847                }
2848
2849                final int len = a.getShapeRef()[axis];
2850                if (len < 2) {
2851                        throw new IllegalArgumentException("Dataset should have a size > 1 along given axis");
2852                }
2853                ds = DatasetFactory.zeros(is, clazz, a.getShapeRef());
2854                if (rank == 1) {
2855                        centralDifference(a, ds);
2856                } else {
2857                        final Dataset src = DatasetFactory.zeros(is, clazz, len);
2858                        final Dataset dest = DatasetFactory.zeros(is, clazz, len);
2859                        final PositionIterator pi = a.getPositionIterator(axis);
2860                        final int[] pos = pi.getPos();
2861                        final boolean[] hit = pi.getOmit();
2862                        while (pi.hasNext()) {
2863                                a.copyItemsFromAxes(pos, hit, src);
2864                                centralDifference(src, dest);
2865                                ds.setItemsOnAxes(pos, hit, dest.getBuffer());
2866                        }
2867                }
2868
2869                return ds;
2870        }
2871
2872        /**
2873         * 1st order discrete difference of dataset along flattened dataset using
2874         * central difference
2875         * 
2876         * @param a
2877         *            is 1d dataset
2878         * @param out
2879         *            is 1d dataset
2880         */
2881        private static void centralDifference(final Dataset a, final Dataset out) {
2882                final int isize = a.getElementsPerItem();
2883                final int dt = a.getDType();
2884
2885                final int nlen = (out.getShapeRef()[0] - 1) * isize;
2886                if (nlen < 1) {
2887                        throw new IllegalArgumentException("Dataset should have a size > 1 along given axis");
2888                }
2889                final IndexIterator it = a.getIterator();
2890                if (!it.hasNext())
2891                        return;
2892                int oi = it.index;
2893                if (!it.hasNext())
2894                        return;
2895                int pi = it.index;
2896
2897                switch (dt) {
2898                case Dataset.INT8:
2899                        final byte[] i8data = ((ByteDataset) a).getData();
2900                        final byte[] oi8data = ((ByteDataset) out).getData();
2901                        oi8data[0] = (byte) (i8data[pi] - i8data[oi]);
2902                        for (int i = 1; it.hasNext(); i++) {
2903                                oi8data[i] = (byte) ((i8data[it.index] - i8data[oi]) / 2);
2904                                oi = pi;
2905                                pi = it.index;
2906                        }
2907                        oi8data[nlen] = (byte) (i8data[pi] - i8data[oi]);
2908                        break;
2909                case Dataset.INT16:
2910                        final short[] i16data = ((ShortDataset) a).getData();
2911                        final short[] oi16data = ((ShortDataset) out).getData();
2912                        oi16data[0] = (short) (i16data[pi] - i16data[oi]);
2913                        for (int i = 1; it.hasNext(); i++) {
2914                                oi16data[i] = (short) ((i16data[it.index] - i16data[oi]) / 2);
2915                                oi = pi;
2916                                pi = it.index;
2917                        }
2918                        oi16data[nlen] = (short) (i16data[pi] - i16data[oi]);
2919                        break;
2920                case Dataset.INT32:
2921                        final int[] i32data = ((IntegerDataset) a).getData();
2922                        final int[] oi32data = ((IntegerDataset) out).getData();
2923                        oi32data[0] = i32data[pi] - i32data[oi];
2924                        for (int i = 1; it.hasNext(); i++) {
2925                                oi32data[i] = (i32data[it.index] - i32data[oi]) / 2;
2926                                oi = pi;
2927                                pi = it.index;
2928                        }
2929                        oi32data[nlen] = i32data[pi] - i32data[oi];
2930                        break;
2931                case Dataset.INT64:
2932                        final long[] i64data = ((LongDataset) a).getData();
2933                        final long[] oi64data = ((LongDataset) out).getData();
2934                        oi64data[0] = i64data[pi] - i64data[oi];
2935                        for (int i = 1; it.hasNext(); i++) {
2936                                oi64data[i] = (i64data[it.index] - i64data[oi]) / 2;
2937                                oi = pi;
2938                                pi = it.index;
2939                        }
2940                        oi64data[nlen] = i64data[pi] - i64data[oi];
2941                        break;
2942                case Dataset.ARRAYINT8:
2943                        final byte[] ai8data = ((CompoundByteDataset) a).getData();
2944                        final byte[] oai8data = ((CompoundByteDataset) out).getData();
2945                        for (int k = 0; k < isize; k++) {
2946                                oai8data[k] = (byte) (ai8data[pi + k] - ai8data[oi + k]);
2947                        }
2948                        for (int i = isize; it.hasNext();) {
2949                                int l = it.index;
2950                                for (int k = 0; k < isize; k++) {
2951                                        oai8data[i++] = (byte) ((ai8data[l++] - ai8data[oi++]) / 2);
2952                                }
2953                                oi = pi;
2954                                pi = it.index;
2955                        }
2956                        for (int k = 0; k < isize; k++) {
2957                                oai8data[nlen + k] = (byte) (ai8data[pi + k] - ai8data[oi + k]);
2958                        }
2959                        break;
2960                case Dataset.ARRAYINT16:
2961                        final short[] ai16data = ((CompoundShortDataset) a).getData();
2962                        final short[] oai16data = ((CompoundShortDataset) out).getData();
2963                        for (int k = 0; k < isize; k++) {
2964                                oai16data[k] = (short) (ai16data[pi + k] - ai16data[oi + k]);
2965                        }
2966                        for (int i = isize; it.hasNext();) {
2967                                int l = it.index;
2968                                for (int k = 0; k < isize; k++) {
2969                                        oai16data[i++] = (short) ((ai16data[l++] - ai16data[oi++]) / 2);
2970                                }
2971                                oi = pi;
2972                                pi = it.index;
2973                        }
2974                        for (int k = 0; k < isize; k++) {
2975                                oai16data[nlen + k] = (short) (ai16data[pi + k] - ai16data[oi + k]);
2976                        }
2977                        break;
2978                case Dataset.ARRAYINT32:
2979                        final int[] ai32data = ((CompoundIntegerDataset) a).getData();
2980                        final int[] oai32data = ((CompoundIntegerDataset) out).getData();
2981                        for (int k = 0; k < isize; k++) {
2982                                oai32data[k] = ai32data[pi + k] - ai32data[oi + k];
2983                        }
2984                        for (int i = isize; it.hasNext();) {
2985                                int l = it.index;
2986                                for (int k = 0; k < isize; k++) {
2987                                        oai32data[i++] = (ai32data[l++] - ai32data[oi++]) / 2;
2988                                }
2989                                oi = pi;
2990                                pi = it.index;
2991                        }
2992                        for (int k = 0; k < isize; k++) {
2993                                oai32data[nlen + k] = ai32data[pi + k] - ai32data[oi + k];
2994                        }
2995                        break;
2996                case Dataset.ARRAYINT64:
2997                        final long[] ai64data = ((CompoundLongDataset) a).getData();
2998                        final long[] oai64data = ((CompoundLongDataset) out).getData();
2999                        for (int k = 0; k < isize; k++) {
3000                                oai64data[k] = ai64data[pi + k] - ai64data[oi + k];
3001                        }
3002                        for (int i = isize; it.hasNext();) {
3003                                int l = it.index;
3004                                for (int k = 0; k < isize; k++) {
3005                                        oai64data[i++] = (ai64data[l++] - ai64data[oi++]) / 2;
3006                                }
3007                                oi = pi;
3008                                pi = it.index;
3009                        }
3010                        for (int k = 0; k < isize; k++) {
3011                                oai64data[nlen + k] = ai64data[pi + k] - ai64data[oi + k];
3012                        }
3013                        break;
3014                case Dataset.FLOAT32:
3015                        final float[] f32data = ((FloatDataset) a).getData();
3016                        final float[] of32data = ((FloatDataset) out).getData();
3017                        of32data[0] = f32data[pi] - f32data[oi];
3018                        for (int i = 1; it.hasNext(); i++) {
3019                                of32data[i] = (f32data[it.index] - f32data[oi]) * 0.5f;
3020                                oi = pi;
3021                                pi = it.index;
3022                        }
3023                        of32data[nlen] = f32data[pi] - f32data[oi];
3024                        break;
3025                case Dataset.FLOAT64:
3026                        final double[] f64data = ((DoubleDataset) a).getData();
3027                        final double[] of64data = ((DoubleDataset) out).getData();
3028                        of64data[0] = f64data[pi] - f64data[oi];
3029                        for (int i = 1; it.hasNext(); i++) {
3030                                of64data[i] = (f64data[it.index] - f64data[oi]) * 0.5f;
3031                                oi = pi;
3032                                pi = it.index;
3033                        }
3034                        of64data[nlen] = f64data[pi] - f64data[oi];
3035                        break;
3036                case Dataset.COMPLEX64:
3037                        final float[] c64data = ((ComplexFloatDataset) a).getData();
3038                        final float[] oc64data = ((ComplexFloatDataset) out).getData();
3039                        oc64data[0] = c64data[pi] - c64data[oi];
3040                        oc64data[1] = c64data[pi + 1] - c64data[oi + 1];
3041                        for (int i = 2; it.hasNext();) {
3042                                oc64data[i++] = (c64data[it.index] - c64data[oi++]) * 0.5f;
3043                                oc64data[i++] = (c64data[it.index + 1] - c64data[oi]) * 0.5f;
3044                                oi = pi;
3045                                pi = it.index;
3046                        }
3047                        oc64data[nlen] = c64data[pi] - c64data[oi];
3048                        oc64data[nlen + 1] = c64data[pi + 1] - c64data[oi + 1];
3049                        break;
3050                case Dataset.COMPLEX128:
3051                        final double[] c128data = ((ComplexDoubleDataset) a).getData();
3052                        final double[] oc128data = ((ComplexDoubleDataset) out).getData();
3053                        oc128data[0] = c128data[pi] - c128data[oi];
3054                        oc128data[1] = c128data[pi + 1] - c128data[oi + 1];
3055                        for (int i = 2; it.hasNext();) {
3056                                oc128data[i++] = (c128data[it.index] - c128data[oi++]) * 0.5f;
3057                                oc128data[i++] = (c128data[it.index + 1] - c128data[oi]) * 0.5f;
3058                                oi = pi;
3059                                pi = it.index;
3060                        }
3061                        oc128data[nlen] = c128data[pi] - c128data[oi];
3062                        oc128data[nlen + 1] = c128data[pi + 1] - c128data[oi + 1];
3063                        break;
3064                case Dataset.ARRAYFLOAT32:
3065                        final float[] af32data = ((CompoundFloatDataset) a).getData();
3066                        final float[] oaf32data = ((CompoundFloatDataset) out).getData();
3067                        for (int k = 0; k < isize; k++) {
3068                                oaf32data[k] = af32data[pi + k] - af32data[oi + k];
3069                        }
3070                        for (int i = isize; it.hasNext();) {
3071                                int l = it.index;
3072                                for (int k = 0; k < isize; k++) {
3073                                        oaf32data[i++] = (af32data[l++] - af32data[oi++]) * 0.5f;
3074                                }
3075                                oi = pi;
3076                                pi = it.index;
3077                        }
3078                        for (int k = 0; k < isize; k++) {
3079                                oaf32data[nlen + k] = af32data[pi + k] - af32data[oi + k];
3080                        }
3081                        break;
3082                case Dataset.ARRAYFLOAT64:
3083                        final double[] af64data = ((CompoundDoubleDataset) a).getData();
3084                        final double[] oaf64data = ((CompoundDoubleDataset) out).getData();
3085                        for (int k = 0; k < isize; k++) {
3086                                oaf64data[k] = af64data[pi + k] - af64data[oi + k];
3087                        }
3088                        for (int i = isize; it.hasNext();) {
3089                                int l = it.index;
3090                                for (int k = 0; k < isize; k++) {
3091                                        oaf64data[i++] = (af64data[l++] - af64data[oi++]) * 0.5;
3092                                }
3093                                oi = pi;
3094                                pi = it.index;
3095                        }
3096                        for (int k = 0; k < isize; k++) {
3097                                oaf64data[nlen + k] = af64data[pi + k] - af64data[oi + k];
3098                        }
3099                        break;
3100                default:
3101                        throw new UnsupportedOperationException("difference does not support this dataset type");
3102                }
3103        }
3104
3105        /**
3106         * Calculate gradient (or partial derivatives) by central difference
3107         * 
3108         * @param y
3109         * @param x
3110         *            one or more datasets for dependent variables
3111         * @return a list of datasets (one for each dimension in y)
3112         */
3113        public static List<Dataset> gradient(Dataset y, Dataset... x) {
3114                final int rank = y.getRank();
3115
3116                if (x.length > 0) {
3117                        if (x.length != rank) {
3118                                throw new IllegalArgumentException(
3119                                                "Number of dependent datasets must be equal to rank of first argument");
3120                        }
3121                        for (int a = 0; a < rank; a++) {
3122                                int rx = x[a].getRank();
3123                                if (rx != rank && rx != 1) {
3124                                        throw new IllegalArgumentException(
3125                                                        "Dependent datasets must be 1-D or match rank of first argument");
3126                                }
3127                                if (rx == 1) {
3128                                        if (y.getShapeRef()[a] != x[a].getShapeRef()[0]) {
3129                                                throw new IllegalArgumentException("Length of dependent dataset must match axis length");
3130                                        }
3131                                } else {
3132                                        y.checkCompatibility(x[a]);
3133                                }
3134                        }
3135                }
3136
3137                List<Dataset> grad = new ArrayList<Dataset>(rank);
3138
3139                for (int a = 0; a < rank; a++) {
3140                        Dataset g = centralDifference(y, a);
3141                        grad.add(g);
3142                }
3143
3144                if (x.length > 0) {
3145                        for (int a = 0; a < rank; a++) {
3146                                Dataset g = grad.get(a);
3147                                Dataset dx = x[a];
3148                                int r = dx.getRank();
3149                                if (r == rank) {
3150                                        g.idivide(centralDifference(dx, a));
3151                                } else {
3152                                        final int is = dx.getElementsPerItem();
3153                                        final Dataset bdx = DatasetFactory.zeros(is, dx.getClass(), y.getShapeRef());
3154                                        final PositionIterator pi = y.getPositionIterator(a);
3155                                        final int[] pos = pi.getPos();
3156                                        final boolean[] hit = pi.getOmit();
3157                                        dx = centralDifference(dx, 0);
3158
3159                                        while (pi.hasNext()) {
3160                                                bdx.setItemsOnAxes(pos, hit, dx.getBuffer());
3161                                        }
3162                                        g.idivide(bdx);
3163                                }
3164                        }
3165                }
3166                return grad;
3167        }
3168
3169        protected static void addFunctionName(final Dataset a, final Dataset b, final Dataset dataset, final String fname) {
3170                dataset.setName(Operations.createFunctionName(fname, a.getName(), b.getName()));
3171        }
3172
3173        protected static void addFunctionName(final Dataset dataset, final String fname) {
3174                dataset.setName(Operations.createFunctionName(fname, dataset.getName()));
3175        }
3176
3177        protected static void addBinaryOperatorName(final Dataset a, final Dataset b, final Dataset dataset, final String oname) {
3178                dataset.setName(Operations.createBinaryOperationName(oname, a.getName(), b.getName()));
3179        }
3180
3181        protected static final long toLong(double d) {
3182                if (Double.isInfinite(d) || Double.isNaN(d))
3183                        return 0l;
3184                return (long) d;
3185        }
3186
3187// Start of generated code
3188        /**
3189         * add operator
3190         * @param a
3191         * @param b
3192         * @return {@code a + b}, addition of a and b
3193         */
3194        public static Dataset add(final Object a, final Object b) {
3195                return add(a, b, null);
3196        }
3197
3198        /**
3199         * add operator
3200         * @param a
3201         * @param b
3202         * @param o output can be null - in which case, a new dataset is created
3203         * @return {@code a + b}, addition of a and b
3204         */
3205        public static Dataset add(final Object a, final Object b, final Dataset o) {
3206                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
3207                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
3208                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
3209                final Dataset result = it.getOutput();
3210                if (!result.isComplex()) {
3211                        boolean change = false;
3212                        if (da.isComplex()) {
3213                                da = da.getRealView();
3214                                change = true;
3215                        }
3216                        if (db.isComplex()) {
3217                                db = db.getRealView();
3218                                change = true;
3219                        }
3220                        if (change) {
3221                                it = BroadcastIterator.createIterator(da, db, result, true);
3222                        }
3223                }
3224                final int is = result.getElementsPerItem();
3225                final int as = da.getElementsPerItem();
3226                final int bs = db.getElementsPerItem();
3227                final int dt = result.getDType();
3228
3229                switch(dt) {
3230                case Dataset.INT8:
3231                        final byte[] oi8data = ((ByteDataset) result).getData();
3232                        if (it.isOutputDouble()) {
3233                                while (it.hasNext()) {
3234                                        final double iax = it.aDouble;
3235                                        final double ibx = it.bDouble;
3236                                        byte ox;
3237                                        ox = (byte) toLong(iax + ibx);
3238                                        oi8data[it.oIndex] = ox;
3239                                }
3240                        } else {
3241                                while (it.hasNext()) {
3242                                        final long iax = it.aLong;
3243                                        final long ibx = it.bLong;
3244                                        byte ox;
3245                                        ox = (byte) (iax + ibx);
3246                                        oi8data[it.oIndex] = ox;
3247                                }
3248                        }
3249                        break;
3250                case Dataset.INT16:
3251                        final short[] oi16data = ((ShortDataset) result).getData();
3252                        if (it.isOutputDouble()) {
3253                                while (it.hasNext()) {
3254                                        final double iax = it.aDouble;
3255                                        final double ibx = it.bDouble;
3256                                        short ox;
3257                                        ox = (short) toLong(iax + ibx);
3258                                        oi16data[it.oIndex] = ox;
3259                                }
3260                        } else {
3261                                while (it.hasNext()) {
3262                                        final long iax = it.aLong;
3263                                        final long ibx = it.bLong;
3264                                        short ox;
3265                                        ox = (short) (iax + ibx);
3266                                        oi16data[it.oIndex] = ox;
3267                                }
3268                        }
3269                        break;
3270                case Dataset.INT64:
3271                        final long[] oi64data = ((LongDataset) result).getData();
3272                        if (it.isOutputDouble()) {
3273                                while (it.hasNext()) {
3274                                        final double iax = it.aDouble;
3275                                        final double ibx = it.bDouble;
3276                                        long ox;
3277                                        ox = toLong(iax + ibx);
3278                                        oi64data[it.oIndex] = ox;
3279                                }
3280                        } else {
3281                                while (it.hasNext()) {
3282                                        final long iax = it.aLong;
3283                                        final long ibx = it.bLong;
3284                                        long ox;
3285                                        ox = (iax + ibx);
3286                                        oi64data[it.oIndex] = ox;
3287                                }
3288                        }
3289                        break;
3290                case Dataset.INT32:
3291                        final int[] oi32data = ((IntegerDataset) result).getData();
3292                        if (it.isOutputDouble()) {
3293                                while (it.hasNext()) {
3294                                        final double iax = it.aDouble;
3295                                        final double ibx = it.bDouble;
3296                                        int ox;
3297                                        ox = (int) toLong(iax + ibx);
3298                                        oi32data[it.oIndex] = ox;
3299                                }
3300                        } else {
3301                                while (it.hasNext()) {
3302                                        final long iax = it.aLong;
3303                                        final long ibx = it.bLong;
3304                                        int ox;
3305                                        ox = (int) (iax + ibx);
3306                                        oi32data[it.oIndex] = ox;
3307                                }
3308                        }
3309                        break;
3310                case Dataset.ARRAYINT8:
3311                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
3312                        if (is == 1) {
3313                                if (it.isOutputDouble()) {
3314                                        while (it.hasNext()) {
3315                                                final double iax = it.aDouble;
3316                                                final double ibx = it.bDouble;
3317                                                byte ox;
3318                                                ox = (byte) toLong(iax + ibx);
3319                                                oai8data[it.oIndex] = ox;
3320                                        }
3321                                } else {
3322                                        while (it.hasNext()) {
3323                                                final long iax = it.aLong;
3324                                                final long ibx = it.bLong;
3325                                                byte ox;
3326                                                ox = (byte) (iax + ibx);
3327                                                oai8data[it.oIndex] = ox;
3328                                        }
3329                                }
3330                        } else if (as < bs) {
3331                                if (it.isOutputDouble()) {
3332                                        while (it.hasNext()) {
3333                                                final double iax = it.aDouble;
3334                                                double ibx = it.bDouble;
3335                                                byte ox;
3336                                                ox = (byte) toLong(iax + ibx);
3337                                                oai8data[it.oIndex] = ox;
3338                                                for (int j = 1; j < is; j++) {
3339                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3340                                                        ox = (byte) toLong(iax + ibx);
3341                                                        oai8data[it.oIndex + j] = ox;
3342                                                }
3343                                        }
3344                                } else {
3345                                        while (it.hasNext()) {
3346                                                final long iax = it.aLong;
3347                                                long ibx = it.bLong;
3348                                                byte ox;
3349                                                ox = (byte) (iax + ibx);
3350                                                oai8data[it.oIndex] = ox;
3351                                                for (int j = 1; j < is; j++) {
3352                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3353                                                        ox = (byte) (iax + ibx);
3354                                                        oai8data[it.oIndex + j] = ox;
3355                                                }
3356                                        }
3357                                }
3358                        } else if (as > bs) {
3359                                if (it.isOutputDouble()) {
3360                                        while (it.hasNext()) {
3361                                                double iax = it.aDouble;
3362                                                final double ibx = it.bDouble;
3363                                                byte ox;
3364                                                ox = (byte) toLong(iax + ibx);
3365                                                oai8data[it.oIndex] = ox;
3366                                                for (int j = 1; j < is; j++) {
3367                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3368                                                        ox = (byte) toLong(iax + ibx);
3369                                                        oai8data[it.oIndex + j] = ox;
3370                                                }
3371                                        }
3372                                } else {
3373                                        while (it.hasNext()) {
3374                                                long iax = it.aLong;
3375                                                final long ibx = it.bLong;
3376                                                byte ox;
3377                                                ox = (byte) (iax + ibx);
3378                                                oai8data[it.oIndex] = ox;
3379                                                for (int j = 1; j < is; j++) {
3380                                                        iax = da.getElementLongAbs(it.aIndex + j);
3381                                                        ox = (byte) (iax + ibx);
3382                                                        oai8data[it.oIndex + j] = ox;
3383                                                }
3384                                        }
3385                                }
3386                        } else if (as == 1) {
3387                                if (it.isOutputDouble()) {
3388                                        while (it.hasNext()) {
3389                                                final double iax = it.aDouble;
3390                                                final double ibx = it.bDouble;
3391                                                byte ox;
3392                                                ox = (byte) toLong(iax + ibx);
3393                                                for (int j = 0; j < is; j++) {
3394                                                        oai8data[it.oIndex + j] = ox;
3395                                                }
3396                                        }
3397                                } else {
3398                                        while (it.hasNext()) {
3399                                                final long iax = it.aLong;
3400                                                final long ibx = it.bLong;
3401                                                byte ox;
3402                                                ox = (byte) (iax + ibx);
3403                                                for (int j = 0; j < is; j++) {
3404                                                        oai8data[it.oIndex + j] = ox;
3405                                                }
3406                                        }
3407                                }
3408                        } else {
3409                                if (it.isOutputDouble()) {
3410                                        while (it.hasNext()) {
3411                                                double iax = it.aDouble;
3412                                                double ibx = it.bDouble;
3413                                                byte ox;
3414                                                ox = (byte) toLong(iax + ibx);
3415                                                oai8data[it.oIndex] = ox;
3416                                                for (int j = 1; j < is; j++) {
3417                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3418                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3419                                                        ox = (byte) toLong(iax + ibx);
3420                                                        oai8data[it.oIndex + j] = ox;
3421                                                }
3422                                        }
3423                                } else {
3424                                        while (it.hasNext()) {
3425                                                long iax = it.aLong;
3426                                                long ibx = it.bLong;
3427                                                byte ox;
3428                                                ox = (byte) (iax + ibx);
3429                                                oai8data[it.oIndex] = ox;
3430                                                for (int j = 1; j < is; j++) {
3431                                                        iax = da.getElementLongAbs(it.aIndex + j);
3432                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3433                                                        ox = (byte) (iax + ibx);
3434                                                        oai8data[it.oIndex + j] = ox;
3435                                                }
3436                                        }
3437                                }
3438                        }
3439                        break;
3440                case Dataset.ARRAYINT16:
3441                        final short[] oai16data = ((CompoundShortDataset) result).getData();
3442                        if (is == 1) {
3443                                if (it.isOutputDouble()) {
3444                                        while (it.hasNext()) {
3445                                                final double iax = it.aDouble;
3446                                                final double ibx = it.bDouble;
3447                                                short ox;
3448                                                ox = (short) toLong(iax + ibx);
3449                                                oai16data[it.oIndex] = ox;
3450                                        }
3451                                } else {
3452                                        while (it.hasNext()) {
3453                                                final long iax = it.aLong;
3454                                                final long ibx = it.bLong;
3455                                                short ox;
3456                                                ox = (short) (iax + ibx);
3457                                                oai16data[it.oIndex] = ox;
3458                                        }
3459                                }
3460                        } else if (as < bs) {
3461                                if (it.isOutputDouble()) {
3462                                        while (it.hasNext()) {
3463                                                final double iax = it.aDouble;
3464                                                double ibx = it.bDouble;
3465                                                short ox;
3466                                                ox = (short) toLong(iax + ibx);
3467                                                oai16data[it.oIndex] = ox;
3468                                                for (int j = 1; j < is; j++) {
3469                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3470                                                        ox = (short) toLong(iax + ibx);
3471                                                        oai16data[it.oIndex + j] = ox;
3472                                                }
3473                                        }
3474                                } else {
3475                                        while (it.hasNext()) {
3476                                                final long iax = it.aLong;
3477                                                long ibx = it.bLong;
3478                                                short ox;
3479                                                ox = (short) (iax + ibx);
3480                                                oai16data[it.oIndex] = ox;
3481                                                for (int j = 1; j < is; j++) {
3482                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3483                                                        ox = (short) (iax + ibx);
3484                                                        oai16data[it.oIndex + j] = ox;
3485                                                }
3486                                        }
3487                                }
3488                        } else if (as > bs) {
3489                                if (it.isOutputDouble()) {
3490                                        while (it.hasNext()) {
3491                                                double iax = it.aDouble;
3492                                                final double ibx = it.bDouble;
3493                                                short ox;
3494                                                ox = (short) toLong(iax + ibx);
3495                                                oai16data[it.oIndex] = ox;
3496                                                for (int j = 1; j < is; j++) {
3497                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3498                                                        ox = (short) toLong(iax + ibx);
3499                                                        oai16data[it.oIndex + j] = ox;
3500                                                }
3501                                        }
3502                                } else {
3503                                        while (it.hasNext()) {
3504                                                long iax = it.aLong;
3505                                                final long ibx = it.bLong;
3506                                                short ox;
3507                                                ox = (short) (iax + ibx);
3508                                                oai16data[it.oIndex] = ox;
3509                                                for (int j = 1; j < is; j++) {
3510                                                        iax = da.getElementLongAbs(it.aIndex + j);
3511                                                        ox = (short) (iax + ibx);
3512                                                        oai16data[it.oIndex + j] = ox;
3513                                                }
3514                                        }
3515                                }
3516                        } else if (as == 1) {
3517                                if (it.isOutputDouble()) {
3518                                        while (it.hasNext()) {
3519                                                final double iax = it.aDouble;
3520                                                final double ibx = it.bDouble;
3521                                                short ox;
3522                                                ox = (short) toLong(iax + ibx);
3523                                                for (int j = 0; j < is; j++) {
3524                                                        oai16data[it.oIndex + j] = ox;
3525                                                }
3526                                        }
3527                                } else {
3528                                        while (it.hasNext()) {
3529                                                final long iax = it.aLong;
3530                                                final long ibx = it.bLong;
3531                                                short ox;
3532                                                ox = (short) (iax + ibx);
3533                                                for (int j = 0; j < is; j++) {
3534                                                        oai16data[it.oIndex + j] = ox;
3535                                                }
3536                                        }
3537                                }
3538                        } else {
3539                                if (it.isOutputDouble()) {
3540                                        while (it.hasNext()) {
3541                                                double iax = it.aDouble;
3542                                                double ibx = it.bDouble;
3543                                                short ox;
3544                                                ox = (short) toLong(iax + ibx);
3545                                                oai16data[it.oIndex] = ox;
3546                                                for (int j = 1; j < is; j++) {
3547                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3548                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3549                                                        ox = (short) toLong(iax + ibx);
3550                                                        oai16data[it.oIndex + j] = ox;
3551                                                }
3552                                        }
3553                                } else {
3554                                        while (it.hasNext()) {
3555                                                long iax = it.aLong;
3556                                                long ibx = it.bLong;
3557                                                short ox;
3558                                                ox = (short) (iax + ibx);
3559                                                oai16data[it.oIndex] = ox;
3560                                                for (int j = 1; j < is; j++) {
3561                                                        iax = da.getElementLongAbs(it.aIndex + j);
3562                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3563                                                        ox = (short) (iax + ibx);
3564                                                        oai16data[it.oIndex + j] = ox;
3565                                                }
3566                                        }
3567                                }
3568                        }
3569                        break;
3570                case Dataset.ARRAYINT64:
3571                        final long[] oai64data = ((CompoundLongDataset) result).getData();
3572                        if (is == 1) {
3573                                if (it.isOutputDouble()) {
3574                                        while (it.hasNext()) {
3575                                                final double iax = it.aDouble;
3576                                                final double ibx = it.bDouble;
3577                                                long ox;
3578                                                ox = toLong(iax + ibx);
3579                                                oai64data[it.oIndex] = ox;
3580                                        }
3581                                } else {
3582                                        while (it.hasNext()) {
3583                                                final long iax = it.aLong;
3584                                                final long ibx = it.bLong;
3585                                                long ox;
3586                                                ox = (iax + ibx);
3587                                                oai64data[it.oIndex] = ox;
3588                                        }
3589                                }
3590                        } else if (as < bs) {
3591                                if (it.isOutputDouble()) {
3592                                        while (it.hasNext()) {
3593                                                final double iax = it.aDouble;
3594                                                double ibx = it.bDouble;
3595                                                long ox;
3596                                                ox = toLong(iax + ibx);
3597                                                oai64data[it.oIndex] = ox;
3598                                                for (int j = 1; j < is; j++) {
3599                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3600                                                        ox = toLong(iax + ibx);
3601                                                        oai64data[it.oIndex + j] = ox;
3602                                                }
3603                                        }
3604                                } else {
3605                                        while (it.hasNext()) {
3606                                                final long iax = it.aLong;
3607                                                long ibx = it.bLong;
3608                                                long ox;
3609                                                ox = (iax + ibx);
3610                                                oai64data[it.oIndex] = ox;
3611                                                for (int j = 1; j < is; j++) {
3612                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3613                                                        ox = (iax + ibx);
3614                                                        oai64data[it.oIndex + j] = ox;
3615                                                }
3616                                        }
3617                                }
3618                        } else if (as > bs) {
3619                                if (it.isOutputDouble()) {
3620                                        while (it.hasNext()) {
3621                                                double iax = it.aDouble;
3622                                                final double ibx = it.bDouble;
3623                                                long ox;
3624                                                ox = toLong(iax + ibx);
3625                                                oai64data[it.oIndex] = ox;
3626                                                for (int j = 1; j < is; j++) {
3627                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3628                                                        ox = toLong(iax + ibx);
3629                                                        oai64data[it.oIndex + j] = ox;
3630                                                }
3631                                        }
3632                                } else {
3633                                        while (it.hasNext()) {
3634                                                long iax = it.aLong;
3635                                                final long ibx = it.bLong;
3636                                                long ox;
3637                                                ox = (iax + ibx);
3638                                                oai64data[it.oIndex] = ox;
3639                                                for (int j = 1; j < is; j++) {
3640                                                        iax = da.getElementLongAbs(it.aIndex + j);
3641                                                        ox = (iax + ibx);
3642                                                        oai64data[it.oIndex + j] = ox;
3643                                                }
3644                                        }
3645                                }
3646                        } else if (as == 1) {
3647                                if (it.isOutputDouble()) {
3648                                        while (it.hasNext()) {
3649                                                final double iax = it.aDouble;
3650                                                final double ibx = it.bDouble;
3651                                                long ox;
3652                                                ox = toLong(iax + ibx);
3653                                                for (int j = 0; j < is; j++) {
3654                                                        oai64data[it.oIndex + j] = ox;
3655                                                }
3656                                        }
3657                                } else {
3658                                        while (it.hasNext()) {
3659                                                final long iax = it.aLong;
3660                                                final long ibx = it.bLong;
3661                                                long ox;
3662                                                ox = (iax + ibx);
3663                                                for (int j = 0; j < is; j++) {
3664                                                        oai64data[it.oIndex + j] = ox;
3665                                                }
3666                                        }
3667                                }
3668                        } else {
3669                                if (it.isOutputDouble()) {
3670                                        while (it.hasNext()) {
3671                                                double iax = it.aDouble;
3672                                                double ibx = it.bDouble;
3673                                                long ox;
3674                                                ox = toLong(iax + ibx);
3675                                                oai64data[it.oIndex] = ox;
3676                                                for (int j = 1; j < is; j++) {
3677                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3678                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3679                                                        ox = toLong(iax + ibx);
3680                                                        oai64data[it.oIndex + j] = ox;
3681                                                }
3682                                        }
3683                                } else {
3684                                        while (it.hasNext()) {
3685                                                long iax = it.aLong;
3686                                                long ibx = it.bLong;
3687                                                long ox;
3688                                                ox = (iax + ibx);
3689                                                oai64data[it.oIndex] = ox;
3690                                                for (int j = 1; j < is; j++) {
3691                                                        iax = da.getElementLongAbs(it.aIndex + j);
3692                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3693                                                        ox = (iax + ibx);
3694                                                        oai64data[it.oIndex + j] = ox;
3695                                                }
3696                                        }
3697                                }
3698                        }
3699                        break;
3700                case Dataset.ARRAYINT32:
3701                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
3702                        if (is == 1) {
3703                                if (it.isOutputDouble()) {
3704                                        while (it.hasNext()) {
3705                                                final double iax = it.aDouble;
3706                                                final double ibx = it.bDouble;
3707                                                int ox;
3708                                                ox = (int) toLong(iax + ibx);
3709                                                oai32data[it.oIndex] = ox;
3710                                        }
3711                                } else {
3712                                        while (it.hasNext()) {
3713                                                final long iax = it.aLong;
3714                                                final long ibx = it.bLong;
3715                                                int ox;
3716                                                ox = (int) (iax + ibx);
3717                                                oai32data[it.oIndex] = ox;
3718                                        }
3719                                }
3720                        } else if (as < bs) {
3721                                if (it.isOutputDouble()) {
3722                                        while (it.hasNext()) {
3723                                                final double iax = it.aDouble;
3724                                                double ibx = it.bDouble;
3725                                                int ox;
3726                                                ox = (int) toLong(iax + ibx);
3727                                                oai32data[it.oIndex] = ox;
3728                                                for (int j = 1; j < is; j++) {
3729                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3730                                                        ox = (int) toLong(iax + ibx);
3731                                                        oai32data[it.oIndex + j] = ox;
3732                                                }
3733                                        }
3734                                } else {
3735                                        while (it.hasNext()) {
3736                                                final long iax = it.aLong;
3737                                                long ibx = it.bLong;
3738                                                int ox;
3739                                                ox = (int) (iax + ibx);
3740                                                oai32data[it.oIndex] = ox;
3741                                                for (int j = 1; j < is; j++) {
3742                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3743                                                        ox = (int) (iax + ibx);
3744                                                        oai32data[it.oIndex + j] = ox;
3745                                                }
3746                                        }
3747                                }
3748                        } else if (as > bs) {
3749                                if (it.isOutputDouble()) {
3750                                        while (it.hasNext()) {
3751                                                double iax = it.aDouble;
3752                                                final double ibx = it.bDouble;
3753                                                int ox;
3754                                                ox = (int) toLong(iax + ibx);
3755                                                oai32data[it.oIndex] = ox;
3756                                                for (int j = 1; j < is; j++) {
3757                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3758                                                        ox = (int) toLong(iax + ibx);
3759                                                        oai32data[it.oIndex + j] = ox;
3760                                                }
3761                                        }
3762                                } else {
3763                                        while (it.hasNext()) {
3764                                                long iax = it.aLong;
3765                                                final long ibx = it.bLong;
3766                                                int ox;
3767                                                ox = (int) (iax + ibx);
3768                                                oai32data[it.oIndex] = ox;
3769                                                for (int j = 1; j < is; j++) {
3770                                                        iax = da.getElementLongAbs(it.aIndex + j);
3771                                                        ox = (int) (iax + ibx);
3772                                                        oai32data[it.oIndex + j] = ox;
3773                                                }
3774                                        }
3775                                }
3776                        } else if (as == 1) {
3777                                if (it.isOutputDouble()) {
3778                                        while (it.hasNext()) {
3779                                                final double iax = it.aDouble;
3780                                                final double ibx = it.bDouble;
3781                                                int ox;
3782                                                ox = (int) toLong(iax + ibx);
3783                                                for (int j = 0; j < is; j++) {
3784                                                        oai32data[it.oIndex + j] = ox;
3785                                                }
3786                                        }
3787                                } else {
3788                                        while (it.hasNext()) {
3789                                                final long iax = it.aLong;
3790                                                final long ibx = it.bLong;
3791                                                int ox;
3792                                                ox = (int) (iax + ibx);
3793                                                for (int j = 0; j < is; j++) {
3794                                                        oai32data[it.oIndex + j] = ox;
3795                                                }
3796                                        }
3797                                }
3798                        } else {
3799                                if (it.isOutputDouble()) {
3800                                        while (it.hasNext()) {
3801                                                double iax = it.aDouble;
3802                                                double ibx = it.bDouble;
3803                                                int ox;
3804                                                ox = (int) toLong(iax + ibx);
3805                                                oai32data[it.oIndex] = ox;
3806                                                for (int j = 1; j < is; j++) {
3807                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3808                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3809                                                        ox = (int) toLong(iax + ibx);
3810                                                        oai32data[it.oIndex + j] = ox;
3811                                                }
3812                                        }
3813                                } else {
3814                                        while (it.hasNext()) {
3815                                                long iax = it.aLong;
3816                                                long ibx = it.bLong;
3817                                                int ox;
3818                                                ox = (int) (iax + ibx);
3819                                                oai32data[it.oIndex] = ox;
3820                                                for (int j = 1; j < is; j++) {
3821                                                        iax = da.getElementLongAbs(it.aIndex + j);
3822                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3823                                                        ox = (int) (iax + ibx);
3824                                                        oai32data[it.oIndex + j] = ox;
3825                                                }
3826                                        }
3827                                }
3828                        }
3829                        break;
3830                case Dataset.FLOAT32:
3831                        final float[] of32data = ((FloatDataset) result).getData();
3832                        if (it.isOutputDouble()) {
3833                                while (it.hasNext()) {
3834                                        final double iax = it.aDouble;
3835                                        final double ibx = it.bDouble;
3836                                        float ox;
3837                                        ox = (float) (iax + ibx);
3838                                        of32data[it.oIndex] = ox;
3839                                }
3840                        } else {
3841                                while (it.hasNext()) {
3842                                        final long iax = it.aLong;
3843                                        final long ibx = it.bLong;
3844                                        float ox;
3845                                        ox = (iax + ibx);
3846                                        of32data[it.oIndex] = ox;
3847                                }
3848                        }
3849                        break;
3850                case Dataset.FLOAT64:
3851                        final double[] of64data = ((DoubleDataset) result).getData();
3852                        if (it.isOutputDouble()) {
3853                                while (it.hasNext()) {
3854                                        final double iax = it.aDouble;
3855                                        final double ibx = it.bDouble;
3856                                        double ox;
3857                                        ox = (iax + ibx);
3858                                        of64data[it.oIndex] = ox;
3859                                }
3860                        } else {
3861                                while (it.hasNext()) {
3862                                        final long iax = it.aLong;
3863                                        final long ibx = it.bLong;
3864                                        double ox;
3865                                        ox = (iax + ibx);
3866                                        of64data[it.oIndex] = ox;
3867                                }
3868                        }
3869                        break;
3870                case Dataset.ARRAYFLOAT32:
3871                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
3872                        if (is == 1) {
3873                                if (it.isOutputDouble()) {
3874                                        while (it.hasNext()) {
3875                                                final double iax = it.aDouble;
3876                                                final double ibx = it.bDouble;
3877                                                float ox;
3878                                                ox = (float) (iax + ibx);
3879                                                oaf32data[it.oIndex] = ox;
3880                                        }
3881                                } else {
3882                                        while (it.hasNext()) {
3883                                                final long iax = it.aLong;
3884                                                final long ibx = it.bLong;
3885                                                float ox;
3886                                                ox = (iax + ibx);
3887                                                oaf32data[it.oIndex] = ox;
3888                                        }
3889                                }
3890                        } else if (as < bs) {
3891                                if (it.isOutputDouble()) {
3892                                        while (it.hasNext()) {
3893                                                final double iax = it.aDouble;
3894                                                double ibx = it.bDouble;
3895                                                float ox;
3896                                                ox = (float) (iax + ibx);
3897                                                oaf32data[it.oIndex] = ox;
3898                                                for (int j = 1; j < is; j++) {
3899                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3900                                                        ox = (float) (iax + ibx);
3901                                                        oaf32data[it.oIndex + j] = ox;
3902                                                }
3903                                        }
3904                                } else {
3905                                        while (it.hasNext()) {
3906                                                final long iax = it.aLong;
3907                                                long ibx = it.bLong;
3908                                                float ox;
3909                                                ox = (iax + ibx);
3910                                                oaf32data[it.oIndex] = ox;
3911                                                for (int j = 1; j < is; j++) {
3912                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3913                                                        ox = (iax + ibx);
3914                                                        oaf32data[it.oIndex + j] = ox;
3915                                                }
3916                                        }
3917                                }
3918                        } else if (as > bs) {
3919                                if (it.isOutputDouble()) {
3920                                        while (it.hasNext()) {
3921                                                double iax = it.aDouble;
3922                                                final double ibx = it.bDouble;
3923                                                float ox;
3924                                                ox = (float) (iax + ibx);
3925                                                oaf32data[it.oIndex] = ox;
3926                                                for (int j = 1; j < is; j++) {
3927                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3928                                                        ox = (float) (iax + ibx);
3929                                                        oaf32data[it.oIndex + j] = ox;
3930                                                }
3931                                        }
3932                                } else {
3933                                        while (it.hasNext()) {
3934                                                long iax = it.aLong;
3935                                                final long ibx = it.bLong;
3936                                                float ox;
3937                                                ox = (iax + ibx);
3938                                                oaf32data[it.oIndex] = ox;
3939                                                for (int j = 1; j < is; j++) {
3940                                                        iax = da.getElementLongAbs(it.aIndex + j);
3941                                                        ox = (iax + ibx);
3942                                                        oaf32data[it.oIndex + j] = ox;
3943                                                }
3944                                        }
3945                                }
3946                        } else if (as == 1) {
3947                                if (it.isOutputDouble()) {
3948                                        while (it.hasNext()) {
3949                                                final double iax = it.aDouble;
3950                                                final double ibx = it.bDouble;
3951                                                float ox;
3952                                                ox = (float) (iax + ibx);
3953                                                for (int j = 0; j < is; j++) {
3954                                                        oaf32data[it.oIndex + j] = ox;
3955                                                }
3956                                        }
3957                                } else {
3958                                        while (it.hasNext()) {
3959                                                final long iax = it.aLong;
3960                                                final long ibx = it.bLong;
3961                                                float ox;
3962                                                ox = (iax + ibx);
3963                                                for (int j = 0; j < is; j++) {
3964                                                        oaf32data[it.oIndex + j] = ox;
3965                                                }
3966                                        }
3967                                }
3968                        } else {
3969                                if (it.isOutputDouble()) {
3970                                        while (it.hasNext()) {
3971                                                double iax = it.aDouble;
3972                                                double ibx = it.bDouble;
3973                                                float ox;
3974                                                ox = (float) (iax + ibx);
3975                                                oaf32data[it.oIndex] = ox;
3976                                                for (int j = 1; j < is; j++) {
3977                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3978                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3979                                                        ox = (float) (iax + ibx);
3980                                                        oaf32data[it.oIndex + j] = ox;
3981                                                }
3982                                        }
3983                                } else {
3984                                        while (it.hasNext()) {
3985                                                long iax = it.aLong;
3986                                                long ibx = it.bLong;
3987                                                float ox;
3988                                                ox = (iax + ibx);
3989                                                oaf32data[it.oIndex] = ox;
3990                                                for (int j = 1; j < is; j++) {
3991                                                        iax = da.getElementLongAbs(it.aIndex + j);
3992                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3993                                                        ox = (iax + ibx);
3994                                                        oaf32data[it.oIndex + j] = ox;
3995                                                }
3996                                        }
3997                                }
3998                        }
3999                        break;
4000                case Dataset.ARRAYFLOAT64:
4001                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
4002                        if (is == 1) {
4003                                if (it.isOutputDouble()) {
4004                                        while (it.hasNext()) {
4005                                                final double iax = it.aDouble;
4006                                                final double ibx = it.bDouble;
4007                                                double ox;
4008                                                ox = (iax + ibx);
4009                                                oaf64data[it.oIndex] = ox;
4010                                        }
4011                                } else {
4012                                        while (it.hasNext()) {
4013                                                final long iax = it.aLong;
4014                                                final long ibx = it.bLong;
4015                                                double ox;
4016                                                ox = (iax + ibx);
4017                                                oaf64data[it.oIndex] = ox;
4018                                        }
4019                                }
4020                        } else if (as < bs) {
4021                                if (it.isOutputDouble()) {
4022                                        while (it.hasNext()) {
4023                                                final double iax = it.aDouble;
4024                                                double ibx = it.bDouble;
4025                                                double ox;
4026                                                ox = (iax + ibx);
4027                                                oaf64data[it.oIndex] = ox;
4028                                                for (int j = 1; j < is; j++) {
4029                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4030                                                        ox = (iax + ibx);
4031                                                        oaf64data[it.oIndex + j] = ox;
4032                                                }
4033                                        }
4034                                } else {
4035                                        while (it.hasNext()) {
4036                                                final long iax = it.aLong;
4037                                                long ibx = it.bLong;
4038                                                double ox;
4039                                                ox = (iax + ibx);
4040                                                oaf64data[it.oIndex] = ox;
4041                                                for (int j = 1; j < is; j++) {
4042                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4043                                                        ox = (iax + ibx);
4044                                                        oaf64data[it.oIndex + j] = ox;
4045                                                }
4046                                        }
4047                                }
4048                        } else if (as > bs) {
4049                                if (it.isOutputDouble()) {
4050                                        while (it.hasNext()) {
4051                                                double iax = it.aDouble;
4052                                                final double ibx = it.bDouble;
4053                                                double ox;
4054                                                ox = (iax + ibx);
4055                                                oaf64data[it.oIndex] = ox;
4056                                                for (int j = 1; j < is; j++) {
4057                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4058                                                        ox = (iax + ibx);
4059                                                        oaf64data[it.oIndex + j] = ox;
4060                                                }
4061                                        }
4062                                } else {
4063                                        while (it.hasNext()) {
4064                                                long iax = it.aLong;
4065                                                final long ibx = it.bLong;
4066                                                double ox;
4067                                                ox = (iax + ibx);
4068                                                oaf64data[it.oIndex] = ox;
4069                                                for (int j = 1; j < is; j++) {
4070                                                        iax = da.getElementLongAbs(it.aIndex + j);
4071                                                        ox = (iax + ibx);
4072                                                        oaf64data[it.oIndex + j] = ox;
4073                                                }
4074                                        }
4075                                }
4076                        } else if (as == 1) {
4077                                if (it.isOutputDouble()) {
4078                                        while (it.hasNext()) {
4079                                                final double iax = it.aDouble;
4080                                                final double ibx = it.bDouble;
4081                                                double ox;
4082                                                ox = (iax + ibx);
4083                                                for (int j = 0; j < is; j++) {
4084                                                        oaf64data[it.oIndex + j] = ox;
4085                                                }
4086                                        }
4087                                } else {
4088                                        while (it.hasNext()) {
4089                                                final long iax = it.aLong;
4090                                                final long ibx = it.bLong;
4091                                                double ox;
4092                                                ox = (iax + ibx);
4093                                                for (int j = 0; j < is; j++) {
4094                                                        oaf64data[it.oIndex + j] = ox;
4095                                                }
4096                                        }
4097                                }
4098                        } else {
4099                                if (it.isOutputDouble()) {
4100                                        while (it.hasNext()) {
4101                                                double iax = it.aDouble;
4102                                                double ibx = it.bDouble;
4103                                                double ox;
4104                                                ox = (iax + ibx);
4105                                                oaf64data[it.oIndex] = ox;
4106                                                for (int j = 1; j < is; j++) {
4107                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4108                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4109                                                        ox = (iax + ibx);
4110                                                        oaf64data[it.oIndex + j] = ox;
4111                                                }
4112                                        }
4113                                } else {
4114                                        while (it.hasNext()) {
4115                                                long iax = it.aLong;
4116                                                long ibx = it.bLong;
4117                                                double ox;
4118                                                ox = (iax + ibx);
4119                                                oaf64data[it.oIndex] = ox;
4120                                                for (int j = 1; j < is; j++) {
4121                                                        iax = da.getElementLongAbs(it.aIndex + j);
4122                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4123                                                        ox = (iax + ibx);
4124                                                        oaf64data[it.oIndex + j] = ox;
4125                                                }
4126                                        }
4127                                }
4128                        }
4129                        break;
4130                case Dataset.COMPLEX64:
4131                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
4132                        if (!da.isComplex()) {
4133                                if (it.isOutputDouble()) {
4134                                        final double iay = 0;
4135                                        if (db.isComplex()) {
4136                                                while (it.hasNext()) {
4137                                                        final double iax = it.aDouble;
4138                                                        final double ibx = it.bDouble;
4139                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
4140                                                        float ox;
4141                                                        float oy;
4142                                                        ox = (float) (iax + ibx);
4143                                                        oy = (float) (iay + iby);
4144                                                        oc64data[it.oIndex] = ox;
4145                                                        oc64data[it.oIndex + 1] = oy;
4146                                                }
4147                                        } else {
4148                                                while (it.hasNext()) {
4149                                                        final double iax = it.aDouble;
4150                                                        final double ibx = it.bDouble;
4151                                                        final double iby = 0;
4152                                                        float ox;
4153                                                        float oy;
4154                                                        ox = (float) (iax + ibx);
4155                                                        oy = (float) (iay + iby);
4156                                                        oc64data[it.oIndex] = ox;
4157                                                        oc64data[it.oIndex + 1] = oy;
4158                                                }
4159                                        }
4160                                } else {
4161                                        final long iay = 0;
4162                                        while (it.hasNext()) {
4163                                                final long iax = it.aLong;
4164                                                final long ibx = it.bLong;
4165                                                final long iby = 0;
4166                                                float ox;
4167                                                float oy;
4168                                                ox = (float) (iax + ibx);
4169                                                oy = (float) (iay + iby);
4170                                                oc64data[it.oIndex] = ox;
4171                                                oc64data[it.oIndex + 1] = oy;
4172                                        }
4173                                }
4174                        } else if (!db.isComplex()) {
4175                                final double iby = 0;
4176                                while (it.hasNext()) {
4177                                        final double iax = it.aDouble;
4178                                        final double ibx = it.bDouble;
4179                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
4180                                        float ox;
4181                                        float oy;
4182                                        ox = (float) (iax + ibx);
4183                                        oy = (float) (iay + iby);
4184                                        oc64data[it.oIndex] = ox;
4185                                        oc64data[it.oIndex + 1] = oy;
4186                                }
4187                        } else {
4188                                while (it.hasNext()) {
4189                                        final double iax = it.aDouble;
4190                                        final double ibx = it.bDouble;
4191                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
4192                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
4193                                        float ox;
4194                                        float oy;
4195                                        ox = (float) (iax + ibx);
4196                                        oy = (float) (iay + iby);
4197                                        oc64data[it.oIndex] = ox;
4198                                        oc64data[it.oIndex + 1] = oy;
4199                                }
4200                        }
4201                        break;
4202                case Dataset.COMPLEX128:
4203                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
4204                        if (!da.isComplex()) {
4205                                if (it.isOutputDouble()) {
4206                                        final double iay = 0;
4207                                        if (db.isComplex()) {
4208                                                while (it.hasNext()) {
4209                                                        final double iax = it.aDouble;
4210                                                        final double ibx = it.bDouble;
4211                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
4212                                                        double ox;
4213                                                        double oy;
4214                                                        ox = (iax + ibx);
4215                                                        oy = (iay + iby);
4216                                                        oc128data[it.oIndex] = ox;
4217                                                        oc128data[it.oIndex + 1] = oy;
4218                                                }
4219                                        } else {
4220                                                while (it.hasNext()) {
4221                                                        final double iax = it.aDouble;
4222                                                        final double ibx = it.bDouble;
4223                                                        final double iby = 0;
4224                                                        double ox;
4225                                                        double oy;
4226                                                        ox = (iax + ibx);
4227                                                        oy = (iay + iby);
4228                                                        oc128data[it.oIndex] = ox;
4229                                                        oc128data[it.oIndex + 1] = oy;
4230                                                }
4231                                        }
4232                                } else {
4233                                        final long iay = 0;
4234                                        while (it.hasNext()) {
4235                                                final long iax = it.aLong;
4236                                                final long ibx = it.bLong;
4237                                                final long iby = 0;
4238                                                double ox;
4239                                                double oy;
4240                                                ox = (iax + ibx);
4241                                                oy = (iay + iby);
4242                                                oc128data[it.oIndex] = ox;
4243                                                oc128data[it.oIndex + 1] = oy;
4244                                        }
4245                                }
4246                        } else if (!db.isComplex()) {
4247                                final double iby = 0;
4248                                while (it.hasNext()) {
4249                                        final double iax = it.aDouble;
4250                                        final double ibx = it.bDouble;
4251                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
4252                                        double ox;
4253                                        double oy;
4254                                        ox = (iax + ibx);
4255                                        oy = (iay + iby);
4256                                        oc128data[it.oIndex] = ox;
4257                                        oc128data[it.oIndex + 1] = oy;
4258                                }
4259                        } else {
4260                                while (it.hasNext()) {
4261                                        final double iax = it.aDouble;
4262                                        final double ibx = it.bDouble;
4263                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
4264                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
4265                                        double ox;
4266                                        double oy;
4267                                        ox = (iax + ibx);
4268                                        oy = (iay + iby);
4269                                        oc128data[it.oIndex] = ox;
4270                                        oc128data[it.oIndex + 1] = oy;
4271                                }
4272                        }
4273                        break;
4274                default:
4275                        throw new IllegalArgumentException("add supports integer, compound integer, real, compound real, complex datasets only");
4276                }
4277
4278                addBinaryOperatorName(da, db, result, "+");
4279                return result;
4280        }
4281
4282        /**
4283         * subtract operator
4284         * @param a
4285         * @param b
4286         * @return {@code a - b}, subtraction of a by b
4287         */
4288        public static Dataset subtract(final Object a, final Object b) {
4289                return subtract(a, b, null);
4290        }
4291
4292        /**
4293         * subtract operator
4294         * @param a
4295         * @param b
4296         * @param o output can be null - in which case, a new dataset is created
4297         * @return {@code a - b}, subtraction of a by b
4298         */
4299        public static Dataset subtract(final Object a, final Object b, final Dataset o) {
4300                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
4301                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
4302                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
4303                final Dataset result = it.getOutput();
4304                if (!result.isComplex()) {
4305                        boolean change = false;
4306                        if (da.isComplex()) {
4307                                da = da.getRealView();
4308                                change = true;
4309                        }
4310                        if (db.isComplex()) {
4311                                db = db.getRealView();
4312                                change = true;
4313                        }
4314                        if (change) {
4315                                it = BroadcastIterator.createIterator(da, db, result, true);
4316                        }
4317                }
4318                final int is = result.getElementsPerItem();
4319                final int as = da.getElementsPerItem();
4320                final int bs = db.getElementsPerItem();
4321                final int dt = result.getDType();
4322
4323                switch(dt) {
4324                case Dataset.INT8:
4325                        final byte[] oi8data = ((ByteDataset) result).getData();
4326                        if (it.isOutputDouble()) {
4327                                while (it.hasNext()) {
4328                                        final double iax = it.aDouble;
4329                                        final double ibx = it.bDouble;
4330                                        byte ox;
4331                                        ox = (byte) toLong(iax - ibx);
4332                                        oi8data[it.oIndex] = ox;
4333                                }
4334                        } else {
4335                                while (it.hasNext()) {
4336                                        final long iax = it.aLong;
4337                                        final long ibx = it.bLong;
4338                                        byte ox;
4339                                        ox = (byte) (iax - ibx);
4340                                        oi8data[it.oIndex] = ox;
4341                                }
4342                        }
4343                        break;
4344                case Dataset.INT16:
4345                        final short[] oi16data = ((ShortDataset) result).getData();
4346                        if (it.isOutputDouble()) {
4347                                while (it.hasNext()) {
4348                                        final double iax = it.aDouble;
4349                                        final double ibx = it.bDouble;
4350                                        short ox;
4351                                        ox = (short) toLong(iax - ibx);
4352                                        oi16data[it.oIndex] = ox;
4353                                }
4354                        } else {
4355                                while (it.hasNext()) {
4356                                        final long iax = it.aLong;
4357                                        final long ibx = it.bLong;
4358                                        short ox;
4359                                        ox = (short) (iax - ibx);
4360                                        oi16data[it.oIndex] = ox;
4361                                }
4362                        }
4363                        break;
4364                case Dataset.INT64:
4365                        final long[] oi64data = ((LongDataset) result).getData();
4366                        if (it.isOutputDouble()) {
4367                                while (it.hasNext()) {
4368                                        final double iax = it.aDouble;
4369                                        final double ibx = it.bDouble;
4370                                        long ox;
4371                                        ox = toLong(iax - ibx);
4372                                        oi64data[it.oIndex] = ox;
4373                                }
4374                        } else {
4375                                while (it.hasNext()) {
4376                                        final long iax = it.aLong;
4377                                        final long ibx = it.bLong;
4378                                        long ox;
4379                                        ox = (iax - ibx);
4380                                        oi64data[it.oIndex] = ox;
4381                                }
4382                        }
4383                        break;
4384                case Dataset.INT32:
4385                        final int[] oi32data = ((IntegerDataset) result).getData();
4386                        if (it.isOutputDouble()) {
4387                                while (it.hasNext()) {
4388                                        final double iax = it.aDouble;
4389                                        final double ibx = it.bDouble;
4390                                        int ox;
4391                                        ox = (int) toLong(iax - ibx);
4392                                        oi32data[it.oIndex] = ox;
4393                                }
4394                        } else {
4395                                while (it.hasNext()) {
4396                                        final long iax = it.aLong;
4397                                        final long ibx = it.bLong;
4398                                        int ox;
4399                                        ox = (int) (iax - ibx);
4400                                        oi32data[it.oIndex] = ox;
4401                                }
4402                        }
4403                        break;
4404                case Dataset.ARRAYINT8:
4405                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
4406                        if (is == 1) {
4407                                if (it.isOutputDouble()) {
4408                                        while (it.hasNext()) {
4409                                                final double iax = it.aDouble;
4410                                                final double ibx = it.bDouble;
4411                                                byte ox;
4412                                                ox = (byte) toLong(iax - ibx);
4413                                                oai8data[it.oIndex] = ox;
4414                                        }
4415                                } else {
4416                                        while (it.hasNext()) {
4417                                                final long iax = it.aLong;
4418                                                final long ibx = it.bLong;
4419                                                byte ox;
4420                                                ox = (byte) (iax - ibx);
4421                                                oai8data[it.oIndex] = ox;
4422                                        }
4423                                }
4424                        } else if (as < bs) {
4425                                if (it.isOutputDouble()) {
4426                                        while (it.hasNext()) {
4427                                                final double iax = it.aDouble;
4428                                                double ibx = it.bDouble;
4429                                                byte ox;
4430                                                ox = (byte) toLong(iax - ibx);
4431                                                oai8data[it.oIndex] = ox;
4432                                                for (int j = 1; j < is; j++) {
4433                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4434                                                        ox = (byte) toLong(iax - ibx);
4435                                                        oai8data[it.oIndex + j] = ox;
4436                                                }
4437                                        }
4438                                } else {
4439                                        while (it.hasNext()) {
4440                                                final long iax = it.aLong;
4441                                                long ibx = it.bLong;
4442                                                byte ox;
4443                                                ox = (byte) (iax - ibx);
4444                                                oai8data[it.oIndex] = ox;
4445                                                for (int j = 1; j < is; j++) {
4446                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4447                                                        ox = (byte) (iax - ibx);
4448                                                        oai8data[it.oIndex + j] = ox;
4449                                                }
4450                                        }
4451                                }
4452                        } else if (as > bs) {
4453                                if (it.isOutputDouble()) {
4454                                        while (it.hasNext()) {
4455                                                double iax = it.aDouble;
4456                                                final double ibx = it.bDouble;
4457                                                byte ox;
4458                                                ox = (byte) toLong(iax - ibx);
4459                                                oai8data[it.oIndex] = ox;
4460                                                for (int j = 1; j < is; j++) {
4461                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4462                                                        ox = (byte) toLong(iax - ibx);
4463                                                        oai8data[it.oIndex + j] = ox;
4464                                                }
4465                                        }
4466                                } else {
4467                                        while (it.hasNext()) {
4468                                                long iax = it.aLong;
4469                                                final long ibx = it.bLong;
4470                                                byte ox;
4471                                                ox = (byte) (iax - ibx);
4472                                                oai8data[it.oIndex] = ox;
4473                                                for (int j = 1; j < is; j++) {
4474                                                        iax = da.getElementLongAbs(it.aIndex + j);
4475                                                        ox = (byte) (iax - ibx);
4476                                                        oai8data[it.oIndex + j] = ox;
4477                                                }
4478                                        }
4479                                }
4480                        } else if (as == 1) {
4481                                if (it.isOutputDouble()) {
4482                                        while (it.hasNext()) {
4483                                                final double iax = it.aDouble;
4484                                                final double ibx = it.bDouble;
4485                                                byte ox;
4486                                                ox = (byte) toLong(iax - ibx);
4487                                                for (int j = 0; j < is; j++) {
4488                                                        oai8data[it.oIndex + j] = ox;
4489                                                }
4490                                        }
4491                                } else {
4492                                        while (it.hasNext()) {
4493                                                final long iax = it.aLong;
4494                                                final long ibx = it.bLong;
4495                                                byte ox;
4496                                                ox = (byte) (iax - ibx);
4497                                                for (int j = 0; j < is; j++) {
4498                                                        oai8data[it.oIndex + j] = ox;
4499                                                }
4500                                        }
4501                                }
4502                        } else {
4503                                if (it.isOutputDouble()) {
4504                                        while (it.hasNext()) {
4505                                                double iax = it.aDouble;
4506                                                double ibx = it.bDouble;
4507                                                byte ox;
4508                                                ox = (byte) toLong(iax - ibx);
4509                                                oai8data[it.oIndex] = ox;
4510                                                for (int j = 1; j < is; j++) {
4511                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4512                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4513                                                        ox = (byte) toLong(iax - ibx);
4514                                                        oai8data[it.oIndex + j] = ox;
4515                                                }
4516                                        }
4517                                } else {
4518                                        while (it.hasNext()) {
4519                                                long iax = it.aLong;
4520                                                long ibx = it.bLong;
4521                                                byte ox;
4522                                                ox = (byte) (iax - ibx);
4523                                                oai8data[it.oIndex] = ox;
4524                                                for (int j = 1; j < is; j++) {
4525                                                        iax = da.getElementLongAbs(it.aIndex + j);
4526                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4527                                                        ox = (byte) (iax - ibx);
4528                                                        oai8data[it.oIndex + j] = ox;
4529                                                }
4530                                        }
4531                                }
4532                        }
4533                        break;
4534                case Dataset.ARRAYINT16:
4535                        final short[] oai16data = ((CompoundShortDataset) result).getData();
4536                        if (is == 1) {
4537                                if (it.isOutputDouble()) {
4538                                        while (it.hasNext()) {
4539                                                final double iax = it.aDouble;
4540                                                final double ibx = it.bDouble;
4541                                                short ox;
4542                                                ox = (short) toLong(iax - ibx);
4543                                                oai16data[it.oIndex] = ox;
4544                                        }
4545                                } else {
4546                                        while (it.hasNext()) {
4547                                                final long iax = it.aLong;
4548                                                final long ibx = it.bLong;
4549                                                short ox;
4550                                                ox = (short) (iax - ibx);
4551                                                oai16data[it.oIndex] = ox;
4552                                        }
4553                                }
4554                        } else if (as < bs) {
4555                                if (it.isOutputDouble()) {
4556                                        while (it.hasNext()) {
4557                                                final double iax = it.aDouble;
4558                                                double ibx = it.bDouble;
4559                                                short ox;
4560                                                ox = (short) toLong(iax - ibx);
4561                                                oai16data[it.oIndex] = ox;
4562                                                for (int j = 1; j < is; j++) {
4563                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4564                                                        ox = (short) toLong(iax - ibx);
4565                                                        oai16data[it.oIndex + j] = ox;
4566                                                }
4567                                        }
4568                                } else {
4569                                        while (it.hasNext()) {
4570                                                final long iax = it.aLong;
4571                                                long ibx = it.bLong;
4572                                                short ox;
4573                                                ox = (short) (iax - ibx);
4574                                                oai16data[it.oIndex] = ox;
4575                                                for (int j = 1; j < is; j++) {
4576                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4577                                                        ox = (short) (iax - ibx);
4578                                                        oai16data[it.oIndex + j] = ox;
4579                                                }
4580                                        }
4581                                }
4582                        } else if (as > bs) {
4583                                if (it.isOutputDouble()) {
4584                                        while (it.hasNext()) {
4585                                                double iax = it.aDouble;
4586                                                final double ibx = it.bDouble;
4587                                                short ox;
4588                                                ox = (short) toLong(iax - ibx);
4589                                                oai16data[it.oIndex] = ox;
4590                                                for (int j = 1; j < is; j++) {
4591                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4592                                                        ox = (short) toLong(iax - ibx);
4593                                                        oai16data[it.oIndex + j] = ox;
4594                                                }
4595                                        }
4596                                } else {
4597                                        while (it.hasNext()) {
4598                                                long iax = it.aLong;
4599                                                final long ibx = it.bLong;
4600                                                short ox;
4601                                                ox = (short) (iax - ibx);
4602                                                oai16data[it.oIndex] = ox;
4603                                                for (int j = 1; j < is; j++) {
4604                                                        iax = da.getElementLongAbs(it.aIndex + j);
4605                                                        ox = (short) (iax - ibx);
4606                                                        oai16data[it.oIndex + j] = ox;
4607                                                }
4608                                        }
4609                                }
4610                        } else if (as == 1) {
4611                                if (it.isOutputDouble()) {
4612                                        while (it.hasNext()) {
4613                                                final double iax = it.aDouble;
4614                                                final double ibx = it.bDouble;
4615                                                short ox;
4616                                                ox = (short) toLong(iax - ibx);
4617                                                for (int j = 0; j < is; j++) {
4618                                                        oai16data[it.oIndex + j] = ox;
4619                                                }
4620                                        }
4621                                } else {
4622                                        while (it.hasNext()) {
4623                                                final long iax = it.aLong;
4624                                                final long ibx = it.bLong;
4625                                                short ox;
4626                                                ox = (short) (iax - ibx);
4627                                                for (int j = 0; j < is; j++) {
4628                                                        oai16data[it.oIndex + j] = ox;
4629                                                }
4630                                        }
4631                                }
4632                        } else {
4633                                if (it.isOutputDouble()) {
4634                                        while (it.hasNext()) {
4635                                                double iax = it.aDouble;
4636                                                double ibx = it.bDouble;
4637                                                short ox;
4638                                                ox = (short) toLong(iax - ibx);
4639                                                oai16data[it.oIndex] = ox;
4640                                                for (int j = 1; j < is; j++) {
4641                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4642                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4643                                                        ox = (short) toLong(iax - ibx);
4644                                                        oai16data[it.oIndex + j] = ox;
4645                                                }
4646                                        }
4647                                } else {
4648                                        while (it.hasNext()) {
4649                                                long iax = it.aLong;
4650                                                long ibx = it.bLong;
4651                                                short ox;
4652                                                ox = (short) (iax - ibx);
4653                                                oai16data[it.oIndex] = ox;
4654                                                for (int j = 1; j < is; j++) {
4655                                                        iax = da.getElementLongAbs(it.aIndex + j);
4656                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4657                                                        ox = (short) (iax - ibx);
4658                                                        oai16data[it.oIndex + j] = ox;
4659                                                }
4660                                        }
4661                                }
4662                        }
4663                        break;
4664                case Dataset.ARRAYINT64:
4665                        final long[] oai64data = ((CompoundLongDataset) result).getData();
4666                        if (is == 1) {
4667                                if (it.isOutputDouble()) {
4668                                        while (it.hasNext()) {
4669                                                final double iax = it.aDouble;
4670                                                final double ibx = it.bDouble;
4671                                                long ox;
4672                                                ox = toLong(iax - ibx);
4673                                                oai64data[it.oIndex] = ox;
4674                                        }
4675                                } else {
4676                                        while (it.hasNext()) {
4677                                                final long iax = it.aLong;
4678                                                final long ibx = it.bLong;
4679                                                long ox;
4680                                                ox = (iax - ibx);
4681                                                oai64data[it.oIndex] = ox;
4682                                        }
4683                                }
4684                        } else if (as < bs) {
4685                                if (it.isOutputDouble()) {
4686                                        while (it.hasNext()) {
4687                                                final double iax = it.aDouble;
4688                                                double ibx = it.bDouble;
4689                                                long ox;
4690                                                ox = toLong(iax - ibx);
4691                                                oai64data[it.oIndex] = ox;
4692                                                for (int j = 1; j < is; j++) {
4693                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4694                                                        ox = toLong(iax - ibx);
4695                                                        oai64data[it.oIndex + j] = ox;
4696                                                }
4697                                        }
4698                                } else {
4699                                        while (it.hasNext()) {
4700                                                final long iax = it.aLong;
4701                                                long ibx = it.bLong;
4702                                                long ox;
4703                                                ox = (iax - ibx);
4704                                                oai64data[it.oIndex] = ox;
4705                                                for (int j = 1; j < is; j++) {
4706                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4707                                                        ox = (iax - ibx);
4708                                                        oai64data[it.oIndex + j] = ox;
4709                                                }
4710                                        }
4711                                }
4712                        } else if (as > bs) {
4713                                if (it.isOutputDouble()) {
4714                                        while (it.hasNext()) {
4715                                                double iax = it.aDouble;
4716                                                final double ibx = it.bDouble;
4717                                                long ox;
4718                                                ox = toLong(iax - ibx);
4719                                                oai64data[it.oIndex] = ox;
4720                                                for (int j = 1; j < is; j++) {
4721                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4722                                                        ox = toLong(iax - ibx);
4723                                                        oai64data[it.oIndex + j] = ox;
4724                                                }
4725                                        }
4726                                } else {
4727                                        while (it.hasNext()) {
4728                                                long iax = it.aLong;
4729                                                final long ibx = it.bLong;
4730                                                long ox;
4731                                                ox = (iax - ibx);
4732                                                oai64data[it.oIndex] = ox;
4733                                                for (int j = 1; j < is; j++) {
4734                                                        iax = da.getElementLongAbs(it.aIndex + j);
4735                                                        ox = (iax - ibx);
4736                                                        oai64data[it.oIndex + j] = ox;
4737                                                }
4738                                        }
4739                                }
4740                        } else if (as == 1) {
4741                                if (it.isOutputDouble()) {
4742                                        while (it.hasNext()) {
4743                                                final double iax = it.aDouble;
4744                                                final double ibx = it.bDouble;
4745                                                long ox;
4746                                                ox = toLong(iax - ibx);
4747                                                for (int j = 0; j < is; j++) {
4748                                                        oai64data[it.oIndex + j] = ox;
4749                                                }
4750                                        }
4751                                } else {
4752                                        while (it.hasNext()) {
4753                                                final long iax = it.aLong;
4754                                                final long ibx = it.bLong;
4755                                                long ox;
4756                                                ox = (iax - ibx);
4757                                                for (int j = 0; j < is; j++) {
4758                                                        oai64data[it.oIndex + j] = ox;
4759                                                }
4760                                        }
4761                                }
4762                        } else {
4763                                if (it.isOutputDouble()) {
4764                                        while (it.hasNext()) {
4765                                                double iax = it.aDouble;
4766                                                double ibx = it.bDouble;
4767                                                long ox;
4768                                                ox = toLong(iax - ibx);
4769                                                oai64data[it.oIndex] = ox;
4770                                                for (int j = 1; j < is; j++) {
4771                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4772                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4773                                                        ox = toLong(iax - ibx);
4774                                                        oai64data[it.oIndex + j] = ox;
4775                                                }
4776                                        }
4777                                } else {
4778                                        while (it.hasNext()) {
4779                                                long iax = it.aLong;
4780                                                long ibx = it.bLong;
4781                                                long ox;
4782                                                ox = (iax - ibx);
4783                                                oai64data[it.oIndex] = ox;
4784                                                for (int j = 1; j < is; j++) {
4785                                                        iax = da.getElementLongAbs(it.aIndex + j);
4786                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4787                                                        ox = (iax - ibx);
4788                                                        oai64data[it.oIndex + j] = ox;
4789                                                }
4790                                        }
4791                                }
4792                        }
4793                        break;
4794                case Dataset.ARRAYINT32:
4795                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
4796                        if (is == 1) {
4797                                if (it.isOutputDouble()) {
4798                                        while (it.hasNext()) {
4799                                                final double iax = it.aDouble;
4800                                                final double ibx = it.bDouble;
4801                                                int ox;
4802                                                ox = (int) toLong(iax - ibx);
4803                                                oai32data[it.oIndex] = ox;
4804                                        }
4805                                } else {
4806                                        while (it.hasNext()) {
4807                                                final long iax = it.aLong;
4808                                                final long ibx = it.bLong;
4809                                                int ox;
4810                                                ox = (int) (iax - ibx);
4811                                                oai32data[it.oIndex] = ox;
4812                                        }
4813                                }
4814                        } else if (as < bs) {
4815                                if (it.isOutputDouble()) {
4816                                        while (it.hasNext()) {
4817                                                final double iax = it.aDouble;
4818                                                double ibx = it.bDouble;
4819                                                int ox;
4820                                                ox = (int) toLong(iax - ibx);
4821                                                oai32data[it.oIndex] = ox;
4822                                                for (int j = 1; j < is; j++) {
4823                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4824                                                        ox = (int) toLong(iax - ibx);
4825                                                        oai32data[it.oIndex + j] = ox;
4826                                                }
4827                                        }
4828                                } else {
4829                                        while (it.hasNext()) {
4830                                                final long iax = it.aLong;
4831                                                long ibx = it.bLong;
4832                                                int ox;
4833                                                ox = (int) (iax - ibx);
4834                                                oai32data[it.oIndex] = ox;
4835                                                for (int j = 1; j < is; j++) {
4836                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4837                                                        ox = (int) (iax - ibx);
4838                                                        oai32data[it.oIndex + j] = ox;
4839                                                }
4840                                        }
4841                                }
4842                        } else if (as > bs) {
4843                                if (it.isOutputDouble()) {
4844                                        while (it.hasNext()) {
4845                                                double iax = it.aDouble;
4846                                                final double ibx = it.bDouble;
4847                                                int ox;
4848                                                ox = (int) toLong(iax - ibx);
4849                                                oai32data[it.oIndex] = ox;
4850                                                for (int j = 1; j < is; j++) {
4851                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4852                                                        ox = (int) toLong(iax - ibx);
4853                                                        oai32data[it.oIndex + j] = ox;
4854                                                }
4855                                        }
4856                                } else {
4857                                        while (it.hasNext()) {
4858                                                long iax = it.aLong;
4859                                                final long ibx = it.bLong;
4860                                                int ox;
4861                                                ox = (int) (iax - ibx);
4862                                                oai32data[it.oIndex] = ox;
4863                                                for (int j = 1; j < is; j++) {
4864                                                        iax = da.getElementLongAbs(it.aIndex + j);
4865                                                        ox = (int) (iax - ibx);
4866                                                        oai32data[it.oIndex + j] = ox;
4867                                                }
4868                                        }
4869                                }
4870                        } else if (as == 1) {
4871                                if (it.isOutputDouble()) {
4872                                        while (it.hasNext()) {
4873                                                final double iax = it.aDouble;
4874                                                final double ibx = it.bDouble;
4875                                                int ox;
4876                                                ox = (int) toLong(iax - ibx);
4877                                                for (int j = 0; j < is; j++) {
4878                                                        oai32data[it.oIndex + j] = ox;
4879                                                }
4880                                        }
4881                                } else {
4882                                        while (it.hasNext()) {
4883                                                final long iax = it.aLong;
4884                                                final long ibx = it.bLong;
4885                                                int ox;
4886                                                ox = (int) (iax - ibx);
4887                                                for (int j = 0; j < is; j++) {
4888                                                        oai32data[it.oIndex + j] = ox;
4889                                                }
4890                                        }
4891                                }
4892                        } else {
4893                                if (it.isOutputDouble()) {
4894                                        while (it.hasNext()) {
4895                                                double iax = it.aDouble;
4896                                                double ibx = it.bDouble;
4897                                                int ox;
4898                                                ox = (int) toLong(iax - ibx);
4899                                                oai32data[it.oIndex] = ox;
4900                                                for (int j = 1; j < is; j++) {
4901                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4902                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4903                                                        ox = (int) toLong(iax - ibx);
4904                                                        oai32data[it.oIndex + j] = ox;
4905                                                }
4906                                        }
4907                                } else {
4908                                        while (it.hasNext()) {
4909                                                long iax = it.aLong;
4910                                                long ibx = it.bLong;
4911                                                int ox;
4912                                                ox = (int) (iax - ibx);
4913                                                oai32data[it.oIndex] = ox;
4914                                                for (int j = 1; j < is; j++) {
4915                                                        iax = da.getElementLongAbs(it.aIndex + j);
4916                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4917                                                        ox = (int) (iax - ibx);
4918                                                        oai32data[it.oIndex + j] = ox;
4919                                                }
4920                                        }
4921                                }
4922                        }
4923                        break;
4924                case Dataset.FLOAT32:
4925                        final float[] of32data = ((FloatDataset) result).getData();
4926                        if (it.isOutputDouble()) {
4927                                while (it.hasNext()) {
4928                                        final double iax = it.aDouble;
4929                                        final double ibx = it.bDouble;
4930                                        float ox;
4931                                        ox = (float) (iax - ibx);
4932                                        of32data[it.oIndex] = ox;
4933                                }
4934                        } else {
4935                                while (it.hasNext()) {
4936                                        final long iax = it.aLong;
4937                                        final long ibx = it.bLong;
4938                                        float ox;
4939                                        ox = (iax - ibx);
4940                                        of32data[it.oIndex] = ox;
4941                                }
4942                        }
4943                        break;
4944                case Dataset.FLOAT64:
4945                        final double[] of64data = ((DoubleDataset) result).getData();
4946                        if (it.isOutputDouble()) {
4947                                while (it.hasNext()) {
4948                                        final double iax = it.aDouble;
4949                                        final double ibx = it.bDouble;
4950                                        double ox;
4951                                        ox = (iax - ibx);
4952                                        of64data[it.oIndex] = ox;
4953                                }
4954                        } else {
4955                                while (it.hasNext()) {
4956                                        final long iax = it.aLong;
4957                                        final long ibx = it.bLong;
4958                                        double ox;
4959                                        ox = (iax - ibx);
4960                                        of64data[it.oIndex] = ox;
4961                                }
4962                        }
4963                        break;
4964                case Dataset.ARRAYFLOAT32:
4965                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
4966                        if (is == 1) {
4967                                if (it.isOutputDouble()) {
4968                                        while (it.hasNext()) {
4969                                                final double iax = it.aDouble;
4970                                                final double ibx = it.bDouble;
4971                                                float ox;
4972                                                ox = (float) (iax - ibx);
4973                                                oaf32data[it.oIndex] = ox;
4974                                        }
4975                                } else {
4976                                        while (it.hasNext()) {
4977                                                final long iax = it.aLong;
4978                                                final long ibx = it.bLong;
4979                                                float ox;
4980                                                ox = (iax - ibx);
4981                                                oaf32data[it.oIndex] = ox;
4982                                        }
4983                                }
4984                        } else if (as < bs) {
4985                                if (it.isOutputDouble()) {
4986                                        while (it.hasNext()) {
4987                                                final double iax = it.aDouble;
4988                                                double ibx = it.bDouble;
4989                                                float ox;
4990                                                ox = (float) (iax - ibx);
4991                                                oaf32data[it.oIndex] = ox;
4992                                                for (int j = 1; j < is; j++) {
4993                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4994                                                        ox = (float) (iax - ibx);
4995                                                        oaf32data[it.oIndex + j] = ox;
4996                                                }
4997                                        }
4998                                } else {
4999                                        while (it.hasNext()) {
5000                                                final long iax = it.aLong;
5001                                                long ibx = it.bLong;
5002                                                float ox;
5003                                                ox = (iax - ibx);
5004                                                oaf32data[it.oIndex] = ox;
5005                                                for (int j = 1; j < is; j++) {
5006                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5007                                                        ox = (iax - ibx);
5008                                                        oaf32data[it.oIndex + j] = ox;
5009                                                }
5010                                        }
5011                                }
5012                        } else if (as > bs) {
5013                                if (it.isOutputDouble()) {
5014                                        while (it.hasNext()) {
5015                                                double iax = it.aDouble;
5016                                                final double ibx = it.bDouble;
5017                                                float ox;
5018                                                ox = (float) (iax - ibx);
5019                                                oaf32data[it.oIndex] = ox;
5020                                                for (int j = 1; j < is; j++) {
5021                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5022                                                        ox = (float) (iax - ibx);
5023                                                        oaf32data[it.oIndex + j] = ox;
5024                                                }
5025                                        }
5026                                } else {
5027                                        while (it.hasNext()) {
5028                                                long iax = it.aLong;
5029                                                final long ibx = it.bLong;
5030                                                float ox;
5031                                                ox = (iax - ibx);
5032                                                oaf32data[it.oIndex] = ox;
5033                                                for (int j = 1; j < is; j++) {
5034                                                        iax = da.getElementLongAbs(it.aIndex + j);
5035                                                        ox = (iax - ibx);
5036                                                        oaf32data[it.oIndex + j] = ox;
5037                                                }
5038                                        }
5039                                }
5040                        } else if (as == 1) {
5041                                if (it.isOutputDouble()) {
5042                                        while (it.hasNext()) {
5043                                                final double iax = it.aDouble;
5044                                                final double ibx = it.bDouble;
5045                                                float ox;
5046                                                ox = (float) (iax - ibx);
5047                                                for (int j = 0; j < is; j++) {
5048                                                        oaf32data[it.oIndex + j] = ox;
5049                                                }
5050                                        }
5051                                } else {
5052                                        while (it.hasNext()) {
5053                                                final long iax = it.aLong;
5054                                                final long ibx = it.bLong;
5055                                                float ox;
5056                                                ox = (iax - ibx);
5057                                                for (int j = 0; j < is; j++) {
5058                                                        oaf32data[it.oIndex + j] = ox;
5059                                                }
5060                                        }
5061                                }
5062                        } else {
5063                                if (it.isOutputDouble()) {
5064                                        while (it.hasNext()) {
5065                                                double iax = it.aDouble;
5066                                                double ibx = it.bDouble;
5067                                                float ox;
5068                                                ox = (float) (iax - ibx);
5069                                                oaf32data[it.oIndex] = ox;
5070                                                for (int j = 1; j < is; j++) {
5071                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5072                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5073                                                        ox = (float) (iax - ibx);
5074                                                        oaf32data[it.oIndex + j] = ox;
5075                                                }
5076                                        }
5077                                } else {
5078                                        while (it.hasNext()) {
5079                                                long iax = it.aLong;
5080                                                long ibx = it.bLong;
5081                                                float ox;
5082                                                ox = (iax - ibx);
5083                                                oaf32data[it.oIndex] = ox;
5084                                                for (int j = 1; j < is; j++) {
5085                                                        iax = da.getElementLongAbs(it.aIndex + j);
5086                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5087                                                        ox = (iax - ibx);
5088                                                        oaf32data[it.oIndex + j] = ox;
5089                                                }
5090                                        }
5091                                }
5092                        }
5093                        break;
5094                case Dataset.ARRAYFLOAT64:
5095                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
5096                        if (is == 1) {
5097                                if (it.isOutputDouble()) {
5098                                        while (it.hasNext()) {
5099                                                final double iax = it.aDouble;
5100                                                final double ibx = it.bDouble;
5101                                                double ox;
5102                                                ox = (iax - ibx);
5103                                                oaf64data[it.oIndex] = ox;
5104                                        }
5105                                } else {
5106                                        while (it.hasNext()) {
5107                                                final long iax = it.aLong;
5108                                                final long ibx = it.bLong;
5109                                                double ox;
5110                                                ox = (iax - ibx);
5111                                                oaf64data[it.oIndex] = ox;
5112                                        }
5113                                }
5114                        } else if (as < bs) {
5115                                if (it.isOutputDouble()) {
5116                                        while (it.hasNext()) {
5117                                                final double iax = it.aDouble;
5118                                                double ibx = it.bDouble;
5119                                                double ox;
5120                                                ox = (iax - ibx);
5121                                                oaf64data[it.oIndex] = ox;
5122                                                for (int j = 1; j < is; j++) {
5123                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5124                                                        ox = (iax - ibx);
5125                                                        oaf64data[it.oIndex + j] = ox;
5126                                                }
5127                                        }
5128                                } else {
5129                                        while (it.hasNext()) {
5130                                                final long iax = it.aLong;
5131                                                long ibx = it.bLong;
5132                                                double ox;
5133                                                ox = (iax - ibx);
5134                                                oaf64data[it.oIndex] = ox;
5135                                                for (int j = 1; j < is; j++) {
5136                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5137                                                        ox = (iax - ibx);
5138                                                        oaf64data[it.oIndex + j] = ox;
5139                                                }
5140                                        }
5141                                }
5142                        } else if (as > bs) {
5143                                if (it.isOutputDouble()) {
5144                                        while (it.hasNext()) {
5145                                                double iax = it.aDouble;
5146                                                final double ibx = it.bDouble;
5147                                                double ox;
5148                                                ox = (iax - ibx);
5149                                                oaf64data[it.oIndex] = ox;
5150                                                for (int j = 1; j < is; j++) {
5151                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5152                                                        ox = (iax - ibx);
5153                                                        oaf64data[it.oIndex + j] = ox;
5154                                                }
5155                                        }
5156                                } else {
5157                                        while (it.hasNext()) {
5158                                                long iax = it.aLong;
5159                                                final long ibx = it.bLong;
5160                                                double ox;
5161                                                ox = (iax - ibx);
5162                                                oaf64data[it.oIndex] = ox;
5163                                                for (int j = 1; j < is; j++) {
5164                                                        iax = da.getElementLongAbs(it.aIndex + j);
5165                                                        ox = (iax - ibx);
5166                                                        oaf64data[it.oIndex + j] = ox;
5167                                                }
5168                                        }
5169                                }
5170                        } else if (as == 1) {
5171                                if (it.isOutputDouble()) {
5172                                        while (it.hasNext()) {
5173                                                final double iax = it.aDouble;
5174                                                final double ibx = it.bDouble;
5175                                                double ox;
5176                                                ox = (iax - ibx);
5177                                                for (int j = 0; j < is; j++) {
5178                                                        oaf64data[it.oIndex + j] = ox;
5179                                                }
5180                                        }
5181                                } else {
5182                                        while (it.hasNext()) {
5183                                                final long iax = it.aLong;
5184                                                final long ibx = it.bLong;
5185                                                double ox;
5186                                                ox = (iax - ibx);
5187                                                for (int j = 0; j < is; j++) {
5188                                                        oaf64data[it.oIndex + j] = ox;
5189                                                }
5190                                        }
5191                                }
5192                        } else {
5193                                if (it.isOutputDouble()) {
5194                                        while (it.hasNext()) {
5195                                                double iax = it.aDouble;
5196                                                double ibx = it.bDouble;
5197                                                double ox;
5198                                                ox = (iax - ibx);
5199                                                oaf64data[it.oIndex] = ox;
5200                                                for (int j = 1; j < is; j++) {
5201                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5202                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5203                                                        ox = (iax - ibx);
5204                                                        oaf64data[it.oIndex + j] = ox;
5205                                                }
5206                                        }
5207                                } else {
5208                                        while (it.hasNext()) {
5209                                                long iax = it.aLong;
5210                                                long ibx = it.bLong;
5211                                                double ox;
5212                                                ox = (iax - ibx);
5213                                                oaf64data[it.oIndex] = ox;
5214                                                for (int j = 1; j < is; j++) {
5215                                                        iax = da.getElementLongAbs(it.aIndex + j);
5216                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5217                                                        ox = (iax - ibx);
5218                                                        oaf64data[it.oIndex + j] = ox;
5219                                                }
5220                                        }
5221                                }
5222                        }
5223                        break;
5224                case Dataset.COMPLEX64:
5225                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
5226                        if (!da.isComplex()) {
5227                                if (it.isOutputDouble()) {
5228                                        final double iay = 0;
5229                                        if (db.isComplex()) {
5230                                                while (it.hasNext()) {
5231                                                        final double iax = it.aDouble;
5232                                                        final double ibx = it.bDouble;
5233                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
5234                                                        float ox;
5235                                                        float oy;
5236                                                        ox = (float) (iax - ibx);
5237                                                        oy = (float) (iay - iby);
5238                                                        oc64data[it.oIndex] = ox;
5239                                                        oc64data[it.oIndex + 1] = oy;
5240                                                }
5241                                        } else {
5242                                                while (it.hasNext()) {
5243                                                        final double iax = it.aDouble;
5244                                                        final double ibx = it.bDouble;
5245                                                        final double iby = 0;
5246                                                        float ox;
5247                                                        float oy;
5248                                                        ox = (float) (iax - ibx);
5249                                                        oy = (float) (iay - iby);
5250                                                        oc64data[it.oIndex] = ox;
5251                                                        oc64data[it.oIndex + 1] = oy;
5252                                                }
5253                                        }
5254                                } else {
5255                                        final long iay = 0;
5256                                        while (it.hasNext()) {
5257                                                final long iax = it.aLong;
5258                                                final long ibx = it.bLong;
5259                                                final long iby = 0;
5260                                                float ox;
5261                                                float oy;
5262                                                ox = (float) (iax - ibx);
5263                                                oy = (float) (iay - iby);
5264                                                oc64data[it.oIndex] = ox;
5265                                                oc64data[it.oIndex + 1] = oy;
5266                                        }
5267                                }
5268                        } else if (!db.isComplex()) {
5269                                final double iby = 0;
5270                                while (it.hasNext()) {
5271                                        final double iax = it.aDouble;
5272                                        final double ibx = it.bDouble;
5273                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
5274                                        float ox;
5275                                        float oy;
5276                                        ox = (float) (iax - ibx);
5277                                        oy = (float) (iay - iby);
5278                                        oc64data[it.oIndex] = ox;
5279                                        oc64data[it.oIndex + 1] = oy;
5280                                }
5281                        } else {
5282                                while (it.hasNext()) {
5283                                        final double iax = it.aDouble;
5284                                        final double ibx = it.bDouble;
5285                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
5286                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
5287                                        float ox;
5288                                        float oy;
5289                                        ox = (float) (iax - ibx);
5290                                        oy = (float) (iay - iby);
5291                                        oc64data[it.oIndex] = ox;
5292                                        oc64data[it.oIndex + 1] = oy;
5293                                }
5294                        }
5295                        break;
5296                case Dataset.COMPLEX128:
5297                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
5298                        if (!da.isComplex()) {
5299                                if (it.isOutputDouble()) {
5300                                        final double iay = 0;
5301                                        if (db.isComplex()) {
5302                                                while (it.hasNext()) {
5303                                                        final double iax = it.aDouble;
5304                                                        final double ibx = it.bDouble;
5305                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
5306                                                        double ox;
5307                                                        double oy;
5308                                                        ox = (iax - ibx);
5309                                                        oy = (iay - iby);
5310                                                        oc128data[it.oIndex] = ox;
5311                                                        oc128data[it.oIndex + 1] = oy;
5312                                                }
5313                                        } else {
5314                                                while (it.hasNext()) {
5315                                                        final double iax = it.aDouble;
5316                                                        final double ibx = it.bDouble;
5317                                                        final double iby = 0;
5318                                                        double ox;
5319                                                        double oy;
5320                                                        ox = (iax - ibx);
5321                                                        oy = (iay - iby);
5322                                                        oc128data[it.oIndex] = ox;
5323                                                        oc128data[it.oIndex + 1] = oy;
5324                                                }
5325                                        }
5326                                } else {
5327                                        final long iay = 0;
5328                                        while (it.hasNext()) {
5329                                                final long iax = it.aLong;
5330                                                final long ibx = it.bLong;
5331                                                final long iby = 0;
5332                                                double ox;
5333                                                double oy;
5334                                                ox = (iax - ibx);
5335                                                oy = (iay - iby);
5336                                                oc128data[it.oIndex] = ox;
5337                                                oc128data[it.oIndex + 1] = oy;
5338                                        }
5339                                }
5340                        } else if (!db.isComplex()) {
5341                                final double iby = 0;
5342                                while (it.hasNext()) {
5343                                        final double iax = it.aDouble;
5344                                        final double ibx = it.bDouble;
5345                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
5346                                        double ox;
5347                                        double oy;
5348                                        ox = (iax - ibx);
5349                                        oy = (iay - iby);
5350                                        oc128data[it.oIndex] = ox;
5351                                        oc128data[it.oIndex + 1] = oy;
5352                                }
5353                        } else {
5354                                while (it.hasNext()) {
5355                                        final double iax = it.aDouble;
5356                                        final double ibx = it.bDouble;
5357                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
5358                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
5359                                        double ox;
5360                                        double oy;
5361                                        ox = (iax - ibx);
5362                                        oy = (iay - iby);
5363                                        oc128data[it.oIndex] = ox;
5364                                        oc128data[it.oIndex + 1] = oy;
5365                                }
5366                        }
5367                        break;
5368                default:
5369                        throw new IllegalArgumentException("subtract supports integer, compound integer, real, compound real, complex datasets only");
5370                }
5371
5372                addBinaryOperatorName(da, db, result, "-");
5373                return result;
5374        }
5375
5376        /**
5377         * multiply operator
5378         * @param a
5379         * @param b
5380         * @return {@code a * b}, product of a and b
5381         */
5382        public static Dataset multiply(final Object a, final Object b) {
5383                return multiply(a, b, null);
5384        }
5385
5386        /**
5387         * multiply operator
5388         * @param a
5389         * @param b
5390         * @param o output can be null - in which case, a new dataset is created
5391         * @return {@code a * b}, product of a and b
5392         */
5393        public static Dataset multiply(final Object a, final Object b, final Dataset o) {
5394                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
5395                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
5396                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
5397                final Dataset result = it.getOutput();
5398                if (!result.isComplex()) {
5399                        boolean change = false;
5400                        if (da.isComplex()) {
5401                                da = da.getRealView();
5402                                change = true;
5403                        }
5404                        if (db.isComplex()) {
5405                                db = db.getRealView();
5406                                change = true;
5407                        }
5408                        if (change) {
5409                                it = BroadcastIterator.createIterator(da, db, result, true);
5410                        }
5411                }
5412                final int is = result.getElementsPerItem();
5413                final int as = da.getElementsPerItem();
5414                final int bs = db.getElementsPerItem();
5415                final int dt = result.getDType();
5416
5417                switch(dt) {
5418                case Dataset.INT8:
5419                        final byte[] oi8data = ((ByteDataset) result).getData();
5420                        if (it.isOutputDouble()) {
5421                                while (it.hasNext()) {
5422                                        final double iax = it.aDouble;
5423                                        final double ibx = it.bDouble;
5424                                        byte ox;
5425                                        ox = (byte) toLong(iax * ibx);
5426                                        oi8data[it.oIndex] = ox;
5427                                }
5428                        } else {
5429                                while (it.hasNext()) {
5430                                        final long iax = it.aLong;
5431                                        final long ibx = it.bLong;
5432                                        byte ox;
5433                                        ox = (byte) (iax * ibx);
5434                                        oi8data[it.oIndex] = ox;
5435                                }
5436                        }
5437                        break;
5438                case Dataset.INT16:
5439                        final short[] oi16data = ((ShortDataset) result).getData();
5440                        if (it.isOutputDouble()) {
5441                                while (it.hasNext()) {
5442                                        final double iax = it.aDouble;
5443                                        final double ibx = it.bDouble;
5444                                        short ox;
5445                                        ox = (short) toLong(iax * ibx);
5446                                        oi16data[it.oIndex] = ox;
5447                                }
5448                        } else {
5449                                while (it.hasNext()) {
5450                                        final long iax = it.aLong;
5451                                        final long ibx = it.bLong;
5452                                        short ox;
5453                                        ox = (short) (iax * ibx);
5454                                        oi16data[it.oIndex] = ox;
5455                                }
5456                        }
5457                        break;
5458                case Dataset.INT64:
5459                        final long[] oi64data = ((LongDataset) result).getData();
5460                        if (it.isOutputDouble()) {
5461                                while (it.hasNext()) {
5462                                        final double iax = it.aDouble;
5463                                        final double ibx = it.bDouble;
5464                                        long ox;
5465                                        ox = toLong(iax * ibx);
5466                                        oi64data[it.oIndex] = ox;
5467                                }
5468                        } else {
5469                                while (it.hasNext()) {
5470                                        final long iax = it.aLong;
5471                                        final long ibx = it.bLong;
5472                                        long ox;
5473                                        ox = (iax * ibx);
5474                                        oi64data[it.oIndex] = ox;
5475                                }
5476                        }
5477                        break;
5478                case Dataset.INT32:
5479                        final int[] oi32data = ((IntegerDataset) result).getData();
5480                        if (it.isOutputDouble()) {
5481                                while (it.hasNext()) {
5482                                        final double iax = it.aDouble;
5483                                        final double ibx = it.bDouble;
5484                                        int ox;
5485                                        ox = (int) toLong(iax * ibx);
5486                                        oi32data[it.oIndex] = ox;
5487                                }
5488                        } else {
5489                                while (it.hasNext()) {
5490                                        final long iax = it.aLong;
5491                                        final long ibx = it.bLong;
5492                                        int ox;
5493                                        ox = (int) (iax * ibx);
5494                                        oi32data[it.oIndex] = ox;
5495                                }
5496                        }
5497                        break;
5498                case Dataset.ARRAYINT8:
5499                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
5500                        if (is == 1) {
5501                                if (it.isOutputDouble()) {
5502                                        while (it.hasNext()) {
5503                                                final double iax = it.aDouble;
5504                                                final double ibx = it.bDouble;
5505                                                byte ox;
5506                                                ox = (byte) toLong(iax * ibx);
5507                                                oai8data[it.oIndex] = ox;
5508                                        }
5509                                } else {
5510                                        while (it.hasNext()) {
5511                                                final long iax = it.aLong;
5512                                                final long ibx = it.bLong;
5513                                                byte ox;
5514                                                ox = (byte) (iax * ibx);
5515                                                oai8data[it.oIndex] = ox;
5516                                        }
5517                                }
5518                        } else if (as < bs) {
5519                                if (it.isOutputDouble()) {
5520                                        while (it.hasNext()) {
5521                                                final double iax = it.aDouble;
5522                                                double ibx = it.bDouble;
5523                                                byte ox;
5524                                                ox = (byte) toLong(iax * ibx);
5525                                                oai8data[it.oIndex] = ox;
5526                                                for (int j = 1; j < is; j++) {
5527                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5528                                                        ox = (byte) toLong(iax * ibx);
5529                                                        oai8data[it.oIndex + j] = ox;
5530                                                }
5531                                        }
5532                                } else {
5533                                        while (it.hasNext()) {
5534                                                final long iax = it.aLong;
5535                                                long ibx = it.bLong;
5536                                                byte ox;
5537                                                ox = (byte) (iax * ibx);
5538                                                oai8data[it.oIndex] = ox;
5539                                                for (int j = 1; j < is; j++) {
5540                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5541                                                        ox = (byte) (iax * ibx);
5542                                                        oai8data[it.oIndex + j] = ox;
5543                                                }
5544                                        }
5545                                }
5546                        } else if (as > bs) {
5547                                if (it.isOutputDouble()) {
5548                                        while (it.hasNext()) {
5549                                                double iax = it.aDouble;
5550                                                final double ibx = it.bDouble;
5551                                                byte ox;
5552                                                ox = (byte) toLong(iax * ibx);
5553                                                oai8data[it.oIndex] = ox;
5554                                                for (int j = 1; j < is; j++) {
5555                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5556                                                        ox = (byte) toLong(iax * ibx);
5557                                                        oai8data[it.oIndex + j] = ox;
5558                                                }
5559                                        }
5560                                } else {
5561                                        while (it.hasNext()) {
5562                                                long iax = it.aLong;
5563                                                final long ibx = it.bLong;
5564                                                byte ox;
5565                                                ox = (byte) (iax * ibx);
5566                                                oai8data[it.oIndex] = ox;
5567                                                for (int j = 1; j < is; j++) {
5568                                                        iax = da.getElementLongAbs(it.aIndex + j);
5569                                                        ox = (byte) (iax * ibx);
5570                                                        oai8data[it.oIndex + j] = ox;
5571                                                }
5572                                        }
5573                                }
5574                        } else if (as == 1) {
5575                                if (it.isOutputDouble()) {
5576                                        while (it.hasNext()) {
5577                                                final double iax = it.aDouble;
5578                                                final double ibx = it.bDouble;
5579                                                byte ox;
5580                                                ox = (byte) toLong(iax * ibx);
5581                                                for (int j = 0; j < is; j++) {
5582                                                        oai8data[it.oIndex + j] = ox;
5583                                                }
5584                                        }
5585                                } else {
5586                                        while (it.hasNext()) {
5587                                                final long iax = it.aLong;
5588                                                final long ibx = it.bLong;
5589                                                byte ox;
5590                                                ox = (byte) (iax * ibx);
5591                                                for (int j = 0; j < is; j++) {
5592                                                        oai8data[it.oIndex + j] = ox;
5593                                                }
5594                                        }
5595                                }
5596                        } else {
5597                                if (it.isOutputDouble()) {
5598                                        while (it.hasNext()) {
5599                                                double iax = it.aDouble;
5600                                                double ibx = it.bDouble;
5601                                                byte ox;
5602                                                ox = (byte) toLong(iax * ibx);
5603                                                oai8data[it.oIndex] = ox;
5604                                                for (int j = 1; j < is; j++) {
5605                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5606                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5607                                                        ox = (byte) toLong(iax * ibx);
5608                                                        oai8data[it.oIndex + j] = ox;
5609                                                }
5610                                        }
5611                                } else {
5612                                        while (it.hasNext()) {
5613                                                long iax = it.aLong;
5614                                                long ibx = it.bLong;
5615                                                byte ox;
5616                                                ox = (byte) (iax * ibx);
5617                                                oai8data[it.oIndex] = ox;
5618                                                for (int j = 1; j < is; j++) {
5619                                                        iax = da.getElementLongAbs(it.aIndex + j);
5620                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5621                                                        ox = (byte) (iax * ibx);
5622                                                        oai8data[it.oIndex + j] = ox;
5623                                                }
5624                                        }
5625                                }
5626                        }
5627                        break;
5628                case Dataset.ARRAYINT16:
5629                        final short[] oai16data = ((CompoundShortDataset) result).getData();
5630                        if (is == 1) {
5631                                if (it.isOutputDouble()) {
5632                                        while (it.hasNext()) {
5633                                                final double iax = it.aDouble;
5634                                                final double ibx = it.bDouble;
5635                                                short ox;
5636                                                ox = (short) toLong(iax * ibx);
5637                                                oai16data[it.oIndex] = ox;
5638                                        }
5639                                } else {
5640                                        while (it.hasNext()) {
5641                                                final long iax = it.aLong;
5642                                                final long ibx = it.bLong;
5643                                                short ox;
5644                                                ox = (short) (iax * ibx);
5645                                                oai16data[it.oIndex] = ox;
5646                                        }
5647                                }
5648                        } else if (as < bs) {
5649                                if (it.isOutputDouble()) {
5650                                        while (it.hasNext()) {
5651                                                final double iax = it.aDouble;
5652                                                double ibx = it.bDouble;
5653                                                short ox;
5654                                                ox = (short) toLong(iax * ibx);
5655                                                oai16data[it.oIndex] = ox;
5656                                                for (int j = 1; j < is; j++) {
5657                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5658                                                        ox = (short) toLong(iax * ibx);
5659                                                        oai16data[it.oIndex + j] = ox;
5660                                                }
5661                                        }
5662                                } else {
5663                                        while (it.hasNext()) {
5664                                                final long iax = it.aLong;
5665                                                long ibx = it.bLong;
5666                                                short ox;
5667                                                ox = (short) (iax * ibx);
5668                                                oai16data[it.oIndex] = ox;
5669                                                for (int j = 1; j < is; j++) {
5670                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5671                                                        ox = (short) (iax * ibx);
5672                                                        oai16data[it.oIndex + j] = ox;
5673                                                }
5674                                        }
5675                                }
5676                        } else if (as > bs) {
5677                                if (it.isOutputDouble()) {
5678                                        while (it.hasNext()) {
5679                                                double iax = it.aDouble;
5680                                                final double ibx = it.bDouble;
5681                                                short ox;
5682                                                ox = (short) toLong(iax * ibx);
5683                                                oai16data[it.oIndex] = ox;
5684                                                for (int j = 1; j < is; j++) {
5685                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5686                                                        ox = (short) toLong(iax * ibx);
5687                                                        oai16data[it.oIndex + j] = ox;
5688                                                }
5689                                        }
5690                                } else {
5691                                        while (it.hasNext()) {
5692                                                long iax = it.aLong;
5693                                                final long ibx = it.bLong;
5694                                                short ox;
5695                                                ox = (short) (iax * ibx);
5696                                                oai16data[it.oIndex] = ox;
5697                                                for (int j = 1; j < is; j++) {
5698                                                        iax = da.getElementLongAbs(it.aIndex + j);
5699                                                        ox = (short) (iax * ibx);
5700                                                        oai16data[it.oIndex + j] = ox;
5701                                                }
5702                                        }
5703                                }
5704                        } else if (as == 1) {
5705                                if (it.isOutputDouble()) {
5706                                        while (it.hasNext()) {
5707                                                final double iax = it.aDouble;
5708                                                final double ibx = it.bDouble;
5709                                                short ox;
5710                                                ox = (short) toLong(iax * ibx);
5711                                                for (int j = 0; j < is; j++) {
5712                                                        oai16data[it.oIndex + j] = ox;
5713                                                }
5714                                        }
5715                                } else {
5716                                        while (it.hasNext()) {
5717                                                final long iax = it.aLong;
5718                                                final long ibx = it.bLong;
5719                                                short ox;
5720                                                ox = (short) (iax * ibx);
5721                                                for (int j = 0; j < is; j++) {
5722                                                        oai16data[it.oIndex + j] = ox;
5723                                                }
5724                                        }
5725                                }
5726                        } else {
5727                                if (it.isOutputDouble()) {
5728                                        while (it.hasNext()) {
5729                                                double iax = it.aDouble;
5730                                                double ibx = it.bDouble;
5731                                                short ox;
5732                                                ox = (short) toLong(iax * ibx);
5733                                                oai16data[it.oIndex] = ox;
5734                                                for (int j = 1; j < is; j++) {
5735                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5736                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5737                                                        ox = (short) toLong(iax * ibx);
5738                                                        oai16data[it.oIndex + j] = ox;
5739                                                }
5740                                        }
5741                                } else {
5742                                        while (it.hasNext()) {
5743                                                long iax = it.aLong;
5744                                                long ibx = it.bLong;
5745                                                short ox;
5746                                                ox = (short) (iax * ibx);
5747                                                oai16data[it.oIndex] = ox;
5748                                                for (int j = 1; j < is; j++) {
5749                                                        iax = da.getElementLongAbs(it.aIndex + j);
5750                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5751                                                        ox = (short) (iax * ibx);
5752                                                        oai16data[it.oIndex + j] = ox;
5753                                                }
5754                                        }
5755                                }
5756                        }
5757                        break;
5758                case Dataset.ARRAYINT64:
5759                        final long[] oai64data = ((CompoundLongDataset) result).getData();
5760                        if (is == 1) {
5761                                if (it.isOutputDouble()) {
5762                                        while (it.hasNext()) {
5763                                                final double iax = it.aDouble;
5764                                                final double ibx = it.bDouble;
5765                                                long ox;
5766                                                ox = toLong(iax * ibx);
5767                                                oai64data[it.oIndex] = ox;
5768                                        }
5769                                } else {
5770                                        while (it.hasNext()) {
5771                                                final long iax = it.aLong;
5772                                                final long ibx = it.bLong;
5773                                                long ox;
5774                                                ox = (iax * ibx);
5775                                                oai64data[it.oIndex] = ox;
5776                                        }
5777                                }
5778                        } else if (as < bs) {
5779                                if (it.isOutputDouble()) {
5780                                        while (it.hasNext()) {
5781                                                final double iax = it.aDouble;
5782                                                double ibx = it.bDouble;
5783                                                long ox;
5784                                                ox = toLong(iax * ibx);
5785                                                oai64data[it.oIndex] = ox;
5786                                                for (int j = 1; j < is; j++) {
5787                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5788                                                        ox = toLong(iax * ibx);
5789                                                        oai64data[it.oIndex + j] = ox;
5790                                                }
5791                                        }
5792                                } else {
5793                                        while (it.hasNext()) {
5794                                                final long iax = it.aLong;
5795                                                long ibx = it.bLong;
5796                                                long ox;
5797                                                ox = (iax * ibx);
5798                                                oai64data[it.oIndex] = ox;
5799                                                for (int j = 1; j < is; j++) {
5800                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5801                                                        ox = (iax * ibx);
5802                                                        oai64data[it.oIndex + j] = ox;
5803                                                }
5804                                        }
5805                                }
5806                        } else if (as > bs) {
5807                                if (it.isOutputDouble()) {
5808                                        while (it.hasNext()) {
5809                                                double iax = it.aDouble;
5810                                                final double ibx = it.bDouble;
5811                                                long ox;
5812                                                ox = toLong(iax * ibx);
5813                                                oai64data[it.oIndex] = ox;
5814                                                for (int j = 1; j < is; j++) {
5815                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5816                                                        ox = toLong(iax * ibx);
5817                                                        oai64data[it.oIndex + j] = ox;
5818                                                }
5819                                        }
5820                                } else {
5821                                        while (it.hasNext()) {
5822                                                long iax = it.aLong;
5823                                                final long ibx = it.bLong;
5824                                                long ox;
5825                                                ox = (iax * ibx);
5826                                                oai64data[it.oIndex] = ox;
5827                                                for (int j = 1; j < is; j++) {
5828                                                        iax = da.getElementLongAbs(it.aIndex + j);
5829                                                        ox = (iax * ibx);
5830                                                        oai64data[it.oIndex + j] = ox;
5831                                                }
5832                                        }
5833                                }
5834                        } else if (as == 1) {
5835                                if (it.isOutputDouble()) {
5836                                        while (it.hasNext()) {
5837                                                final double iax = it.aDouble;
5838                                                final double ibx = it.bDouble;
5839                                                long ox;
5840                                                ox = toLong(iax * ibx);
5841                                                for (int j = 0; j < is; j++) {
5842                                                        oai64data[it.oIndex + j] = ox;
5843                                                }
5844                                        }
5845                                } else {
5846                                        while (it.hasNext()) {
5847                                                final long iax = it.aLong;
5848                                                final long ibx = it.bLong;
5849                                                long ox;
5850                                                ox = (iax * ibx);
5851                                                for (int j = 0; j < is; j++) {
5852                                                        oai64data[it.oIndex + j] = ox;
5853                                                }
5854                                        }
5855                                }
5856                        } else {
5857                                if (it.isOutputDouble()) {
5858                                        while (it.hasNext()) {
5859                                                double iax = it.aDouble;
5860                                                double ibx = it.bDouble;
5861                                                long ox;
5862                                                ox = toLong(iax * ibx);
5863                                                oai64data[it.oIndex] = ox;
5864                                                for (int j = 1; j < is; j++) {
5865                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5866                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5867                                                        ox = toLong(iax * ibx);
5868                                                        oai64data[it.oIndex + j] = ox;
5869                                                }
5870                                        }
5871                                } else {
5872                                        while (it.hasNext()) {
5873                                                long iax = it.aLong;
5874                                                long ibx = it.bLong;
5875                                                long ox;
5876                                                ox = (iax * ibx);
5877                                                oai64data[it.oIndex] = ox;
5878                                                for (int j = 1; j < is; j++) {
5879                                                        iax = da.getElementLongAbs(it.aIndex + j);
5880                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5881                                                        ox = (iax * ibx);
5882                                                        oai64data[it.oIndex + j] = ox;
5883                                                }
5884                                        }
5885                                }
5886                        }
5887                        break;
5888                case Dataset.ARRAYINT32:
5889                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
5890                        if (is == 1) {
5891                                if (it.isOutputDouble()) {
5892                                        while (it.hasNext()) {
5893                                                final double iax = it.aDouble;
5894                                                final double ibx = it.bDouble;
5895                                                int ox;
5896                                                ox = (int) toLong(iax * ibx);
5897                                                oai32data[it.oIndex] = ox;
5898                                        }
5899                                } else {
5900                                        while (it.hasNext()) {
5901                                                final long iax = it.aLong;
5902                                                final long ibx = it.bLong;
5903                                                int ox;
5904                                                ox = (int) (iax * ibx);
5905                                                oai32data[it.oIndex] = ox;
5906                                        }
5907                                }
5908                        } else if (as < bs) {
5909                                if (it.isOutputDouble()) {
5910                                        while (it.hasNext()) {
5911                                                final double iax = it.aDouble;
5912                                                double ibx = it.bDouble;
5913                                                int ox;
5914                                                ox = (int) toLong(iax * ibx);
5915                                                oai32data[it.oIndex] = ox;
5916                                                for (int j = 1; j < is; j++) {
5917                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5918                                                        ox = (int) toLong(iax * ibx);
5919                                                        oai32data[it.oIndex + j] = ox;
5920                                                }
5921                                        }
5922                                } else {
5923                                        while (it.hasNext()) {
5924                                                final long iax = it.aLong;
5925                                                long ibx = it.bLong;
5926                                                int ox;
5927                                                ox = (int) (iax * ibx);
5928                                                oai32data[it.oIndex] = ox;
5929                                                for (int j = 1; j < is; j++) {
5930                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5931                                                        ox = (int) (iax * ibx);
5932                                                        oai32data[it.oIndex + j] = ox;
5933                                                }
5934                                        }
5935                                }
5936                        } else if (as > bs) {
5937                                if (it.isOutputDouble()) {
5938                                        while (it.hasNext()) {
5939                                                double iax = it.aDouble;
5940                                                final double ibx = it.bDouble;
5941                                                int ox;
5942                                                ox = (int) toLong(iax * ibx);
5943                                                oai32data[it.oIndex] = ox;
5944                                                for (int j = 1; j < is; j++) {
5945                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5946                                                        ox = (int) toLong(iax * ibx);
5947                                                        oai32data[it.oIndex + j] = ox;
5948                                                }
5949                                        }
5950                                } else {
5951                                        while (it.hasNext()) {
5952                                                long iax = it.aLong;
5953                                                final long ibx = it.bLong;
5954                                                int ox;
5955                                                ox = (int) (iax * ibx);
5956                                                oai32data[it.oIndex] = ox;
5957                                                for (int j = 1; j < is; j++) {
5958                                                        iax = da.getElementLongAbs(it.aIndex + j);
5959                                                        ox = (int) (iax * ibx);
5960                                                        oai32data[it.oIndex + j] = ox;
5961                                                }
5962                                        }
5963                                }
5964                        } else if (as == 1) {
5965                                if (it.isOutputDouble()) {
5966                                        while (it.hasNext()) {
5967                                                final double iax = it.aDouble;
5968                                                final double ibx = it.bDouble;
5969                                                int ox;
5970                                                ox = (int) toLong(iax * ibx);
5971                                                for (int j = 0; j < is; j++) {
5972                                                        oai32data[it.oIndex + j] = ox;
5973                                                }
5974                                        }
5975                                } else {
5976                                        while (it.hasNext()) {
5977                                                final long iax = it.aLong;
5978                                                final long ibx = it.bLong;
5979                                                int ox;
5980                                                ox = (int) (iax * ibx);
5981                                                for (int j = 0; j < is; j++) {
5982                                                        oai32data[it.oIndex + j] = ox;
5983                                                }
5984                                        }
5985                                }
5986                        } else {
5987                                if (it.isOutputDouble()) {
5988                                        while (it.hasNext()) {
5989                                                double iax = it.aDouble;
5990                                                double ibx = it.bDouble;
5991                                                int ox;
5992                                                ox = (int) toLong(iax * ibx);
5993                                                oai32data[it.oIndex] = ox;
5994                                                for (int j = 1; j < is; j++) {
5995                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5996                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5997                                                        ox = (int) toLong(iax * ibx);
5998                                                        oai32data[it.oIndex + j] = ox;
5999                                                }
6000                                        }
6001                                } else {
6002                                        while (it.hasNext()) {
6003                                                long iax = it.aLong;
6004                                                long ibx = it.bLong;
6005                                                int ox;
6006                                                ox = (int) (iax * ibx);
6007                                                oai32data[it.oIndex] = ox;
6008                                                for (int j = 1; j < is; j++) {
6009                                                        iax = da.getElementLongAbs(it.aIndex + j);
6010                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6011                                                        ox = (int) (iax * ibx);
6012                                                        oai32data[it.oIndex + j] = ox;
6013                                                }
6014                                        }
6015                                }
6016                        }
6017                        break;
6018                case Dataset.FLOAT32:
6019                        final float[] of32data = ((FloatDataset) result).getData();
6020                        if (it.isOutputDouble()) {
6021                                while (it.hasNext()) {
6022                                        final double iax = it.aDouble;
6023                                        final double ibx = it.bDouble;
6024                                        float ox;
6025                                        ox = (float) (iax * ibx);
6026                                        of32data[it.oIndex] = ox;
6027                                }
6028                        } else {
6029                                while (it.hasNext()) {
6030                                        final long iax = it.aLong;
6031                                        final long ibx = it.bLong;
6032                                        float ox;
6033                                        ox = (iax * ibx);
6034                                        of32data[it.oIndex] = ox;
6035                                }
6036                        }
6037                        break;
6038                case Dataset.FLOAT64:
6039                        final double[] of64data = ((DoubleDataset) result).getData();
6040                        if (it.isOutputDouble()) {
6041                                while (it.hasNext()) {
6042                                        final double iax = it.aDouble;
6043                                        final double ibx = it.bDouble;
6044                                        double ox;
6045                                        ox = (iax * ibx);
6046                                        of64data[it.oIndex] = ox;
6047                                }
6048                        } else {
6049                                while (it.hasNext()) {
6050                                        final long iax = it.aLong;
6051                                        final long ibx = it.bLong;
6052                                        double ox;
6053                                        ox = (iax * ibx);
6054                                        of64data[it.oIndex] = ox;
6055                                }
6056                        }
6057                        break;
6058                case Dataset.ARRAYFLOAT32:
6059                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
6060                        if (is == 1) {
6061                                if (it.isOutputDouble()) {
6062                                        while (it.hasNext()) {
6063                                                final double iax = it.aDouble;
6064                                                final double ibx = it.bDouble;
6065                                                float ox;
6066                                                ox = (float) (iax * ibx);
6067                                                oaf32data[it.oIndex] = ox;
6068                                        }
6069                                } else {
6070                                        while (it.hasNext()) {
6071                                                final long iax = it.aLong;
6072                                                final long ibx = it.bLong;
6073                                                float ox;
6074                                                ox = (iax * ibx);
6075                                                oaf32data[it.oIndex] = ox;
6076                                        }
6077                                }
6078                        } else if (as < bs) {
6079                                if (it.isOutputDouble()) {
6080                                        while (it.hasNext()) {
6081                                                final double iax = it.aDouble;
6082                                                double ibx = it.bDouble;
6083                                                float ox;
6084                                                ox = (float) (iax * ibx);
6085                                                oaf32data[it.oIndex] = ox;
6086                                                for (int j = 1; j < is; j++) {
6087                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6088                                                        ox = (float) (iax * ibx);
6089                                                        oaf32data[it.oIndex + j] = ox;
6090                                                }
6091                                        }
6092                                } else {
6093                                        while (it.hasNext()) {
6094                                                final long iax = it.aLong;
6095                                                long ibx = it.bLong;
6096                                                float ox;
6097                                                ox = (iax * ibx);
6098                                                oaf32data[it.oIndex] = ox;
6099                                                for (int j = 1; j < is; j++) {
6100                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6101                                                        ox = (iax * ibx);
6102                                                        oaf32data[it.oIndex + j] = ox;
6103                                                }
6104                                        }
6105                                }
6106                        } else if (as > bs) {
6107                                if (it.isOutputDouble()) {
6108                                        while (it.hasNext()) {
6109                                                double iax = it.aDouble;
6110                                                final double ibx = it.bDouble;
6111                                                float ox;
6112                                                ox = (float) (iax * ibx);
6113                                                oaf32data[it.oIndex] = ox;
6114                                                for (int j = 1; j < is; j++) {
6115                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6116                                                        ox = (float) (iax * ibx);
6117                                                        oaf32data[it.oIndex + j] = ox;
6118                                                }
6119                                        }
6120                                } else {
6121                                        while (it.hasNext()) {
6122                                                long iax = it.aLong;
6123                                                final long ibx = it.bLong;
6124                                                float ox;
6125                                                ox = (iax * ibx);
6126                                                oaf32data[it.oIndex] = ox;
6127                                                for (int j = 1; j < is; j++) {
6128                                                        iax = da.getElementLongAbs(it.aIndex + j);
6129                                                        ox = (iax * ibx);
6130                                                        oaf32data[it.oIndex + j] = ox;
6131                                                }
6132                                        }
6133                                }
6134                        } else if (as == 1) {
6135                                if (it.isOutputDouble()) {
6136                                        while (it.hasNext()) {
6137                                                final double iax = it.aDouble;
6138                                                final double ibx = it.bDouble;
6139                                                float ox;
6140                                                ox = (float) (iax * ibx);
6141                                                for (int j = 0; j < is; j++) {
6142                                                        oaf32data[it.oIndex + j] = ox;
6143                                                }
6144                                        }
6145                                } else {
6146                                        while (it.hasNext()) {
6147                                                final long iax = it.aLong;
6148                                                final long ibx = it.bLong;
6149                                                float ox;
6150                                                ox = (iax * ibx);
6151                                                for (int j = 0; j < is; j++) {
6152                                                        oaf32data[it.oIndex + j] = ox;
6153                                                }
6154                                        }
6155                                }
6156                        } else {
6157                                if (it.isOutputDouble()) {
6158                                        while (it.hasNext()) {
6159                                                double iax = it.aDouble;
6160                                                double ibx = it.bDouble;
6161                                                float ox;
6162                                                ox = (float) (iax * ibx);
6163                                                oaf32data[it.oIndex] = ox;
6164                                                for (int j = 1; j < is; j++) {
6165                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6166                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6167                                                        ox = (float) (iax * ibx);
6168                                                        oaf32data[it.oIndex + j] = ox;
6169                                                }
6170                                        }
6171                                } else {
6172                                        while (it.hasNext()) {
6173                                                long iax = it.aLong;
6174                                                long ibx = it.bLong;
6175                                                float ox;
6176                                                ox = (iax * ibx);
6177                                                oaf32data[it.oIndex] = ox;
6178                                                for (int j = 1; j < is; j++) {
6179                                                        iax = da.getElementLongAbs(it.aIndex + j);
6180                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6181                                                        ox = (iax * ibx);
6182                                                        oaf32data[it.oIndex + j] = ox;
6183                                                }
6184                                        }
6185                                }
6186                        }
6187                        break;
6188                case Dataset.ARRAYFLOAT64:
6189                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
6190                        if (is == 1) {
6191                                if (it.isOutputDouble()) {
6192                                        while (it.hasNext()) {
6193                                                final double iax = it.aDouble;
6194                                                final double ibx = it.bDouble;
6195                                                double ox;
6196                                                ox = (iax * ibx);
6197                                                oaf64data[it.oIndex] = ox;
6198                                        }
6199                                } else {
6200                                        while (it.hasNext()) {
6201                                                final long iax = it.aLong;
6202                                                final long ibx = it.bLong;
6203                                                double ox;
6204                                                ox = (iax * ibx);
6205                                                oaf64data[it.oIndex] = ox;
6206                                        }
6207                                }
6208                        } else if (as < bs) {
6209                                if (it.isOutputDouble()) {
6210                                        while (it.hasNext()) {
6211                                                final double iax = it.aDouble;
6212                                                double ibx = it.bDouble;
6213                                                double ox;
6214                                                ox = (iax * ibx);
6215                                                oaf64data[it.oIndex] = ox;
6216                                                for (int j = 1; j < is; j++) {
6217                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6218                                                        ox = (iax * ibx);
6219                                                        oaf64data[it.oIndex + j] = ox;
6220                                                }
6221                                        }
6222                                } else {
6223                                        while (it.hasNext()) {
6224                                                final long iax = it.aLong;
6225                                                long ibx = it.bLong;
6226                                                double ox;
6227                                                ox = (iax * ibx);
6228                                                oaf64data[it.oIndex] = ox;
6229                                                for (int j = 1; j < is; j++) {
6230                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6231                                                        ox = (iax * ibx);
6232                                                        oaf64data[it.oIndex + j] = ox;
6233                                                }
6234                                        }
6235                                }
6236                        } else if (as > bs) {
6237                                if (it.isOutputDouble()) {
6238                                        while (it.hasNext()) {
6239                                                double iax = it.aDouble;
6240                                                final double ibx = it.bDouble;
6241                                                double ox;
6242                                                ox = (iax * ibx);
6243                                                oaf64data[it.oIndex] = ox;
6244                                                for (int j = 1; j < is; j++) {
6245                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6246                                                        ox = (iax * ibx);
6247                                                        oaf64data[it.oIndex + j] = ox;
6248                                                }
6249                                        }
6250                                } else {
6251                                        while (it.hasNext()) {
6252                                                long iax = it.aLong;
6253                                                final long ibx = it.bLong;
6254                                                double ox;
6255                                                ox = (iax * ibx);
6256                                                oaf64data[it.oIndex] = ox;
6257                                                for (int j = 1; j < is; j++) {
6258                                                        iax = da.getElementLongAbs(it.aIndex + j);
6259                                                        ox = (iax * ibx);
6260                                                        oaf64data[it.oIndex + j] = ox;
6261                                                }
6262                                        }
6263                                }
6264                        } else if (as == 1) {
6265                                if (it.isOutputDouble()) {
6266                                        while (it.hasNext()) {
6267                                                final double iax = it.aDouble;
6268                                                final double ibx = it.bDouble;
6269                                                double ox;
6270                                                ox = (iax * ibx);
6271                                                for (int j = 0; j < is; j++) {
6272                                                        oaf64data[it.oIndex + j] = ox;
6273                                                }
6274                                        }
6275                                } else {
6276                                        while (it.hasNext()) {
6277                                                final long iax = it.aLong;
6278                                                final long ibx = it.bLong;
6279                                                double ox;
6280                                                ox = (iax * ibx);
6281                                                for (int j = 0; j < is; j++) {
6282                                                        oaf64data[it.oIndex + j] = ox;
6283                                                }
6284                                        }
6285                                }
6286                        } else {
6287                                if (it.isOutputDouble()) {
6288                                        while (it.hasNext()) {
6289                                                double iax = it.aDouble;
6290                                                double ibx = it.bDouble;
6291                                                double ox;
6292                                                ox = (iax * ibx);
6293                                                oaf64data[it.oIndex] = ox;
6294                                                for (int j = 1; j < is; j++) {
6295                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6296                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6297                                                        ox = (iax * ibx);
6298                                                        oaf64data[it.oIndex + j] = ox;
6299                                                }
6300                                        }
6301                                } else {
6302                                        while (it.hasNext()) {
6303                                                long iax = it.aLong;
6304                                                long ibx = it.bLong;
6305                                                double ox;
6306                                                ox = (iax * ibx);
6307                                                oaf64data[it.oIndex] = ox;
6308                                                for (int j = 1; j < is; j++) {
6309                                                        iax = da.getElementLongAbs(it.aIndex + j);
6310                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6311                                                        ox = (iax * ibx);
6312                                                        oaf64data[it.oIndex + j] = ox;
6313                                                }
6314                                        }
6315                                }
6316                        }
6317                        break;
6318                case Dataset.COMPLEX64:
6319                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
6320                        if (!da.isComplex()) {
6321                                if (it.isOutputDouble()) {
6322                                        final double iay = 0;
6323                                        if (db.isComplex()) {
6324                                                while (it.hasNext()) {
6325                                                        final double iax = it.aDouble;
6326                                                        final double ibx = it.bDouble;
6327                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
6328                                                        float ox;
6329                                                        float oy;
6330                                                        ox = (float) (iax * ibx - iay * iby);
6331                                                        oy = (float) (iax * iby + iay * ibx);
6332                                                        oc64data[it.oIndex] = ox;
6333                                                        oc64data[it.oIndex + 1] = oy;
6334                                                }
6335                                        } else {
6336                                                while (it.hasNext()) {
6337                                                        final double iax = it.aDouble;
6338                                                        final double ibx = it.bDouble;
6339                                                        final double iby = 0;
6340                                                        float ox;
6341                                                        float oy;
6342                                                        ox = (float) (iax * ibx - iay * iby);
6343                                                        oy = (float) (iax * iby + iay * ibx);
6344                                                        oc64data[it.oIndex] = ox;
6345                                                        oc64data[it.oIndex + 1] = oy;
6346                                                }
6347                                        }
6348                                } else {
6349                                        final long iay = 0;
6350                                        while (it.hasNext()) {
6351                                                final long iax = it.aLong;
6352                                                final long ibx = it.bLong;
6353                                                final long iby = 0;
6354                                                float ox;
6355                                                float oy;
6356                                                ox = (float) (iax * ibx - iay * iby);
6357                                                oy = (float) (iax * iby + iay * ibx);
6358                                                oc64data[it.oIndex] = ox;
6359                                                oc64data[it.oIndex + 1] = oy;
6360                                        }
6361                                }
6362                        } else if (!db.isComplex()) {
6363                                final double iby = 0;
6364                                while (it.hasNext()) {
6365                                        final double iax = it.aDouble;
6366                                        final double ibx = it.bDouble;
6367                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
6368                                        float ox;
6369                                        float oy;
6370                                        ox = (float) (iax * ibx - iay * iby);
6371                                        oy = (float) (iax * iby + iay * ibx);
6372                                        oc64data[it.oIndex] = ox;
6373                                        oc64data[it.oIndex + 1] = oy;
6374                                }
6375                        } else {
6376                                while (it.hasNext()) {
6377                                        final double iax = it.aDouble;
6378                                        final double ibx = it.bDouble;
6379                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
6380                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
6381                                        float ox;
6382                                        float oy;
6383                                        ox = (float) (iax * ibx - iay * iby);
6384                                        oy = (float) (iax * iby + iay * ibx);
6385                                        oc64data[it.oIndex] = ox;
6386                                        oc64data[it.oIndex + 1] = oy;
6387                                }
6388                        }
6389                        break;
6390                case Dataset.COMPLEX128:
6391                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
6392                        if (!da.isComplex()) {
6393                                if (it.isOutputDouble()) {
6394                                        final double iay = 0;
6395                                        if (db.isComplex()) {
6396                                                while (it.hasNext()) {
6397                                                        final double iax = it.aDouble;
6398                                                        final double ibx = it.bDouble;
6399                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
6400                                                        double ox;
6401                                                        double oy;
6402                                                        ox = (iax * ibx - iay * iby);
6403                                                        oy = (iax * iby + iay * ibx);
6404                                                        oc128data[it.oIndex] = ox;
6405                                                        oc128data[it.oIndex + 1] = oy;
6406                                                }
6407                                        } else {
6408                                                while (it.hasNext()) {
6409                                                        final double iax = it.aDouble;
6410                                                        final double ibx = it.bDouble;
6411                                                        final double iby = 0;
6412                                                        double ox;
6413                                                        double oy;
6414                                                        ox = (iax * ibx - iay * iby);
6415                                                        oy = (iax * iby + iay * ibx);
6416                                                        oc128data[it.oIndex] = ox;
6417                                                        oc128data[it.oIndex + 1] = oy;
6418                                                }
6419                                        }
6420                                } else {
6421                                        final long iay = 0;
6422                                        while (it.hasNext()) {
6423                                                final long iax = it.aLong;
6424                                                final long ibx = it.bLong;
6425                                                final long iby = 0;
6426                                                double ox;
6427                                                double oy;
6428                                                ox = (iax * ibx - iay * iby);
6429                                                oy = (iax * iby + iay * ibx);
6430                                                oc128data[it.oIndex] = ox;
6431                                                oc128data[it.oIndex + 1] = oy;
6432                                        }
6433                                }
6434                        } else if (!db.isComplex()) {
6435                                final double iby = 0;
6436                                while (it.hasNext()) {
6437                                        final double iax = it.aDouble;
6438                                        final double ibx = it.bDouble;
6439                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
6440                                        double ox;
6441                                        double oy;
6442                                        ox = (iax * ibx - iay * iby);
6443                                        oy = (iax * iby + iay * ibx);
6444                                        oc128data[it.oIndex] = ox;
6445                                        oc128data[it.oIndex + 1] = oy;
6446                                }
6447                        } else {
6448                                while (it.hasNext()) {
6449                                        final double iax = it.aDouble;
6450                                        final double ibx = it.bDouble;
6451                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
6452                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
6453                                        double ox;
6454                                        double oy;
6455                                        ox = (iax * ibx - iay * iby);
6456                                        oy = (iax * iby + iay * ibx);
6457                                        oc128data[it.oIndex] = ox;
6458                                        oc128data[it.oIndex + 1] = oy;
6459                                }
6460                        }
6461                        break;
6462                default:
6463                        throw new IllegalArgumentException("multiply supports integer, compound integer, real, compound real, complex datasets only");
6464                }
6465
6466                addBinaryOperatorName(da, db, result, "*");
6467                return result;
6468        }
6469
6470        /**
6471         * divide operator
6472         * @param a
6473         * @param b
6474         * @return {@code a / b}, division of a by b
6475         */
6476        public static Dataset divide(final Object a, final Object b) {
6477                return divide(a, b, null);
6478        }
6479
6480        /**
6481         * divide operator
6482         * @param a
6483         * @param b
6484         * @param o output can be null - in which case, a new dataset is created
6485         * @return {@code a / b}, division of a by b
6486         */
6487        public static Dataset divide(final Object a, final Object b, final Dataset o) {
6488                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
6489                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
6490                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
6491                final Dataset result = it.getOutput();
6492                if (!result.isComplex()) {
6493                        boolean change = false;
6494                        if (da.isComplex()) {
6495                                da = da.getRealView();
6496                                change = true;
6497                        }
6498                        if (db.isComplex()) {
6499                                db = db.getRealView();
6500                                change = true;
6501                        }
6502                        if (change) {
6503                                it = BroadcastIterator.createIterator(da, db, result, true);
6504                        }
6505                }
6506                final int is = result.getElementsPerItem();
6507                final int as = da.getElementsPerItem();
6508                final int bs = db.getElementsPerItem();
6509                final int dt = result.getDType();
6510
6511                switch(dt) {
6512                case Dataset.INT8:
6513                        final byte[] oi8data = ((ByteDataset) result).getData();
6514                        if (it.isOutputDouble()) {
6515                                while (it.hasNext()) {
6516                                        final double iax = it.aDouble;
6517                                        final double ibx = it.bDouble;
6518                                        byte ox;
6519                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6520                                        oi8data[it.oIndex] = ox;
6521                                }
6522                        } else {
6523                                while (it.hasNext()) {
6524                                        final long iax = it.aLong;
6525                                        final long ibx = it.bLong;
6526                                        byte ox;
6527                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6528                                        oi8data[it.oIndex] = ox;
6529                                }
6530                        }
6531                        break;
6532                case Dataset.INT16:
6533                        final short[] oi16data = ((ShortDataset) result).getData();
6534                        if (it.isOutputDouble()) {
6535                                while (it.hasNext()) {
6536                                        final double iax = it.aDouble;
6537                                        final double ibx = it.bDouble;
6538                                        short ox;
6539                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6540                                        oi16data[it.oIndex] = ox;
6541                                }
6542                        } else {
6543                                while (it.hasNext()) {
6544                                        final long iax = it.aLong;
6545                                        final long ibx = it.bLong;
6546                                        short ox;
6547                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
6548                                        oi16data[it.oIndex] = ox;
6549                                }
6550                        }
6551                        break;
6552                case Dataset.INT64:
6553                        final long[] oi64data = ((LongDataset) result).getData();
6554                        if (it.isOutputDouble()) {
6555                                while (it.hasNext()) {
6556                                        final double iax = it.aDouble;
6557                                        final double ibx = it.bDouble;
6558                                        long ox;
6559                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
6560                                        oi64data[it.oIndex] = ox;
6561                                }
6562                        } else {
6563                                while (it.hasNext()) {
6564                                        final long iax = it.aLong;
6565                                        final long ibx = it.bLong;
6566                                        long ox;
6567                                        ox = (ibx == 0 ? 0 : iax / ibx);
6568                                        oi64data[it.oIndex] = ox;
6569                                }
6570                        }
6571                        break;
6572                case Dataset.INT32:
6573                        final int[] oi32data = ((IntegerDataset) result).getData();
6574                        if (it.isOutputDouble()) {
6575                                while (it.hasNext()) {
6576                                        final double iax = it.aDouble;
6577                                        final double ibx = it.bDouble;
6578                                        int ox;
6579                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
6580                                        oi32data[it.oIndex] = ox;
6581                                }
6582                        } else {
6583                                while (it.hasNext()) {
6584                                        final long iax = it.aLong;
6585                                        final long ibx = it.bLong;
6586                                        int ox;
6587                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
6588                                        oi32data[it.oIndex] = ox;
6589                                }
6590                        }
6591                        break;
6592                case Dataset.ARRAYINT8:
6593                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
6594                        if (is == 1) {
6595                                if (it.isOutputDouble()) {
6596                                        while (it.hasNext()) {
6597                                                final double iax = it.aDouble;
6598                                                final double ibx = it.bDouble;
6599                                                byte ox;
6600                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6601                                                oai8data[it.oIndex] = ox;
6602                                        }
6603                                } else {
6604                                        while (it.hasNext()) {
6605                                                final long iax = it.aLong;
6606                                                final long ibx = it.bLong;
6607                                                byte ox;
6608                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6609                                                oai8data[it.oIndex] = ox;
6610                                        }
6611                                }
6612                        } else if (as < bs) {
6613                                if (it.isOutputDouble()) {
6614                                        while (it.hasNext()) {
6615                                                final double iax = it.aDouble;
6616                                                double ibx = it.bDouble;
6617                                                byte ox;
6618                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6619                                                oai8data[it.oIndex] = ox;
6620                                                for (int j = 1; j < is; j++) {
6621                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6622                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6623                                                        oai8data[it.oIndex + j] = ox;
6624                                                }
6625                                        }
6626                                } else {
6627                                        while (it.hasNext()) {
6628                                                final long iax = it.aLong;
6629                                                long ibx = it.bLong;
6630                                                byte ox;
6631                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6632                                                oai8data[it.oIndex] = ox;
6633                                                for (int j = 1; j < is; j++) {
6634                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6635                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6636                                                        oai8data[it.oIndex + j] = ox;
6637                                                }
6638                                        }
6639                                }
6640                        } else if (as > bs) {
6641                                if (it.isOutputDouble()) {
6642                                        while (it.hasNext()) {
6643                                                double iax = it.aDouble;
6644                                                final double ibx = it.bDouble;
6645                                                byte ox;
6646                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6647                                                oai8data[it.oIndex] = ox;
6648                                                for (int j = 1; j < is; j++) {
6649                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6650                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6651                                                        oai8data[it.oIndex + j] = ox;
6652                                                }
6653                                        }
6654                                } else {
6655                                        while (it.hasNext()) {
6656                                                long iax = it.aLong;
6657                                                final long ibx = it.bLong;
6658                                                byte ox;
6659                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6660                                                oai8data[it.oIndex] = ox;
6661                                                for (int j = 1; j < is; j++) {
6662                                                        iax = da.getElementLongAbs(it.aIndex + j);
6663                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6664                                                        oai8data[it.oIndex + j] = ox;
6665                                                }
6666                                        }
6667                                }
6668                        } else if (as == 1) {
6669                                if (it.isOutputDouble()) {
6670                                        while (it.hasNext()) {
6671                                                final double iax = it.aDouble;
6672                                                final double ibx = it.bDouble;
6673                                                byte ox;
6674                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6675                                                for (int j = 0; j < is; j++) {
6676                                                        oai8data[it.oIndex + j] = ox;
6677                                                }
6678                                        }
6679                                } else {
6680                                        while (it.hasNext()) {
6681                                                final long iax = it.aLong;
6682                                                final long ibx = it.bLong;
6683                                                byte ox;
6684                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6685                                                for (int j = 0; j < is; j++) {
6686                                                        oai8data[it.oIndex + j] = ox;
6687                                                }
6688                                        }
6689                                }
6690                        } else {
6691                                if (it.isOutputDouble()) {
6692                                        while (it.hasNext()) {
6693                                                double iax = it.aDouble;
6694                                                double ibx = it.bDouble;
6695                                                byte ox;
6696                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6697                                                oai8data[it.oIndex] = ox;
6698                                                for (int j = 1; j < is; j++) {
6699                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6700                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6701                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6702                                                        oai8data[it.oIndex + j] = ox;
6703                                                }
6704                                        }
6705                                } else {
6706                                        while (it.hasNext()) {
6707                                                long iax = it.aLong;
6708                                                long ibx = it.bLong;
6709                                                byte ox;
6710                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6711                                                oai8data[it.oIndex] = ox;
6712                                                for (int j = 1; j < is; j++) {
6713                                                        iax = da.getElementLongAbs(it.aIndex + j);
6714                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6715                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6716                                                        oai8data[it.oIndex + j] = ox;
6717                                                }
6718                                        }
6719                                }
6720                        }
6721                        break;
6722                case Dataset.ARRAYINT16:
6723                        final short[] oai16data = ((CompoundShortDataset) result).getData();
6724                        if (is == 1) {
6725                                if (it.isOutputDouble()) {
6726                                        while (it.hasNext()) {
6727                                                final double iax = it.aDouble;
6728                                                final double ibx = it.bDouble;
6729                                                short ox;
6730                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6731                                                oai16data[it.oIndex] = ox;
6732                                        }
6733                                } else {
6734                                        while (it.hasNext()) {
6735                                                final long iax = it.aLong;
6736                                                final long ibx = it.bLong;
6737                                                short ox;
6738                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
6739                                                oai16data[it.oIndex] = ox;
6740                                        }
6741                                }
6742                        } else if (as < bs) {
6743                                if (it.isOutputDouble()) {
6744                                        while (it.hasNext()) {
6745                                                final double iax = it.aDouble;
6746                                                double ibx = it.bDouble;
6747                                                short ox;
6748                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6749                                                oai16data[it.oIndex] = ox;
6750                                                for (int j = 1; j < is; j++) {
6751                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6752                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6753                                                        oai16data[it.oIndex + j] = ox;
6754                                                }
6755                                        }
6756                                } else {
6757                                        while (it.hasNext()) {
6758                                                final long iax = it.aLong;
6759                                                long ibx = it.bLong;
6760                                                short ox;
6761                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
6762                                                oai16data[it.oIndex] = ox;
6763                                                for (int j = 1; j < is; j++) {
6764                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6765                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
6766                                                        oai16data[it.oIndex + j] = ox;
6767                                                }
6768                                        }
6769                                }
6770                        } else if (as > bs) {
6771                                if (it.isOutputDouble()) {
6772                                        while (it.hasNext()) {
6773                                                double iax = it.aDouble;
6774                                                final double ibx = it.bDouble;
6775                                                short ox;
6776                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6777                                                oai16data[it.oIndex] = ox;
6778                                                for (int j = 1; j < is; j++) {
6779                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6780                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6781                                                        oai16data[it.oIndex + j] = ox;
6782                                                }
6783                                        }
6784                                } else {
6785                                        while (it.hasNext()) {
6786                                                long iax = it.aLong;
6787                                                final long ibx = it.bLong;
6788                                                short ox;
6789                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
6790                                                oai16data[it.oIndex] = ox;
6791                                                for (int j = 1; j < is; j++) {
6792                                                        iax = da.getElementLongAbs(it.aIndex + j);
6793                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
6794                                                        oai16data[it.oIndex + j] = ox;
6795                                                }
6796                                        }
6797                                }
6798                        } else if (as == 1) {
6799                                if (it.isOutputDouble()) {
6800                                        while (it.hasNext()) {
6801                                                final double iax = it.aDouble;
6802                                                final double ibx = it.bDouble;
6803                                                short ox;
6804                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6805                                                for (int j = 0; j < is; j++) {
6806                                                        oai16data[it.oIndex + j] = ox;
6807                                                }
6808                                        }
6809                                } else {
6810                                        while (it.hasNext()) {
6811                                                final long iax = it.aLong;
6812                                                final long ibx = it.bLong;
6813                                                short ox;
6814                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
6815                                                for (int j = 0; j < is; j++) {
6816                                                        oai16data[it.oIndex + j] = ox;
6817                                                }
6818                                        }
6819                                }
6820                        } else {
6821                                if (it.isOutputDouble()) {
6822                                        while (it.hasNext()) {
6823                                                double iax = it.aDouble;
6824                                                double ibx = it.bDouble;
6825                                                short ox;
6826                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6827                                                oai16data[it.oIndex] = ox;
6828                                                for (int j = 1; j < is; j++) {
6829                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6830                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6831                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6832                                                        oai16data[it.oIndex + j] = ox;
6833                                                }
6834                                        }
6835                                } else {
6836                                        while (it.hasNext()) {
6837                                                long iax = it.aLong;
6838                                                long ibx = it.bLong;
6839                                                short ox;
6840                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
6841                                                oai16data[it.oIndex] = ox;
6842                                                for (int j = 1; j < is; j++) {
6843                                                        iax = da.getElementLongAbs(it.aIndex + j);
6844                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6845                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
6846                                                        oai16data[it.oIndex + j] = ox;
6847                                                }
6848                                        }
6849                                }
6850                        }
6851                        break;
6852                case Dataset.ARRAYINT64:
6853                        final long[] oai64data = ((CompoundLongDataset) result).getData();
6854                        if (is == 1) {
6855                                if (it.isOutputDouble()) {
6856                                        while (it.hasNext()) {
6857                                                final double iax = it.aDouble;
6858                                                final double ibx = it.bDouble;
6859                                                long ox;
6860                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
6861                                                oai64data[it.oIndex] = ox;
6862                                        }
6863                                } else {
6864                                        while (it.hasNext()) {
6865                                                final long iax = it.aLong;
6866                                                final long ibx = it.bLong;
6867                                                long ox;
6868                                                ox = (ibx == 0 ? 0 : iax / ibx);
6869                                                oai64data[it.oIndex] = ox;
6870                                        }
6871                                }
6872                        } else if (as < bs) {
6873                                if (it.isOutputDouble()) {
6874                                        while (it.hasNext()) {
6875                                                final double iax = it.aDouble;
6876                                                double ibx = it.bDouble;
6877                                                long ox;
6878                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
6879                                                oai64data[it.oIndex] = ox;
6880                                                for (int j = 1; j < is; j++) {
6881                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6882                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
6883                                                        oai64data[it.oIndex + j] = ox;
6884                                                }
6885                                        }
6886                                } else {
6887                                        while (it.hasNext()) {
6888                                                final long iax = it.aLong;
6889                                                long ibx = it.bLong;
6890                                                long ox;
6891                                                ox = (ibx == 0 ? 0 : iax / ibx);
6892                                                oai64data[it.oIndex] = ox;
6893                                                for (int j = 1; j < is; j++) {
6894                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6895                                                        ox = (ibx == 0 ? 0 : iax / ibx);
6896                                                        oai64data[it.oIndex + j] = ox;
6897                                                }
6898                                        }
6899                                }
6900                        } else if (as > bs) {
6901                                if (it.isOutputDouble()) {
6902                                        while (it.hasNext()) {
6903                                                double iax = it.aDouble;
6904                                                final double ibx = it.bDouble;
6905                                                long ox;
6906                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
6907                                                oai64data[it.oIndex] = ox;
6908                                                for (int j = 1; j < is; j++) {
6909                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6910                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
6911                                                        oai64data[it.oIndex + j] = ox;
6912                                                }
6913                                        }
6914                                } else {
6915                                        while (it.hasNext()) {
6916                                                long iax = it.aLong;
6917                                                final long ibx = it.bLong;
6918                                                long ox;
6919                                                ox = (ibx == 0 ? 0 : iax / ibx);
6920                                                oai64data[it.oIndex] = ox;
6921                                                for (int j = 1; j < is; j++) {
6922                                                        iax = da.getElementLongAbs(it.aIndex + j);
6923                                                        ox = (ibx == 0 ? 0 : iax / ibx);
6924                                                        oai64data[it.oIndex + j] = ox;
6925                                                }
6926                                        }
6927                                }
6928                        } else if (as == 1) {
6929                                if (it.isOutputDouble()) {
6930                                        while (it.hasNext()) {
6931                                                final double iax = it.aDouble;
6932                                                final double ibx = it.bDouble;
6933                                                long ox;
6934                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
6935                                                for (int j = 0; j < is; j++) {
6936                                                        oai64data[it.oIndex + j] = ox;
6937                                                }
6938                                        }
6939                                } else {
6940                                        while (it.hasNext()) {
6941                                                final long iax = it.aLong;
6942                                                final long ibx = it.bLong;
6943                                                long ox;
6944                                                ox = (ibx == 0 ? 0 : iax / ibx);
6945                                                for (int j = 0; j < is; j++) {
6946                                                        oai64data[it.oIndex + j] = ox;
6947                                                }
6948                                        }
6949                                }
6950                        } else {
6951                                if (it.isOutputDouble()) {
6952                                        while (it.hasNext()) {
6953                                                double iax = it.aDouble;
6954                                                double ibx = it.bDouble;
6955                                                long ox;
6956                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
6957                                                oai64data[it.oIndex] = ox;
6958                                                for (int j = 1; j < is; j++) {
6959                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6960                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6961                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
6962                                                        oai64data[it.oIndex + j] = ox;
6963                                                }
6964                                        }
6965                                } else {
6966                                        while (it.hasNext()) {
6967                                                long iax = it.aLong;
6968                                                long ibx = it.bLong;
6969                                                long ox;
6970                                                ox = (ibx == 0 ? 0 : iax / ibx);
6971                                                oai64data[it.oIndex] = ox;
6972                                                for (int j = 1; j < is; j++) {
6973                                                        iax = da.getElementLongAbs(it.aIndex + j);
6974                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6975                                                        ox = (ibx == 0 ? 0 : iax / ibx);
6976                                                        oai64data[it.oIndex + j] = ox;
6977                                                }
6978                                        }
6979                                }
6980                        }
6981                        break;
6982                case Dataset.ARRAYINT32:
6983                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
6984                        if (is == 1) {
6985                                if (it.isOutputDouble()) {
6986                                        while (it.hasNext()) {
6987                                                final double iax = it.aDouble;
6988                                                final double ibx = it.bDouble;
6989                                                int ox;
6990                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
6991                                                oai32data[it.oIndex] = ox;
6992                                        }
6993                                } else {
6994                                        while (it.hasNext()) {
6995                                                final long iax = it.aLong;
6996                                                final long ibx = it.bLong;
6997                                                int ox;
6998                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
6999                                                oai32data[it.oIndex] = ox;
7000                                        }
7001                                }
7002                        } else if (as < bs) {
7003                                if (it.isOutputDouble()) {
7004                                        while (it.hasNext()) {
7005                                                final double iax = it.aDouble;
7006                                                double ibx = it.bDouble;
7007                                                int ox;
7008                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7009                                                oai32data[it.oIndex] = ox;
7010                                                for (int j = 1; j < is; j++) {
7011                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7012                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7013                                                        oai32data[it.oIndex + j] = ox;
7014                                                }
7015                                        }
7016                                } else {
7017                                        while (it.hasNext()) {
7018                                                final long iax = it.aLong;
7019                                                long ibx = it.bLong;
7020                                                int ox;
7021                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
7022                                                oai32data[it.oIndex] = ox;
7023                                                for (int j = 1; j < is; j++) {
7024                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7025                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
7026                                                        oai32data[it.oIndex + j] = ox;
7027                                                }
7028                                        }
7029                                }
7030                        } else if (as > bs) {
7031                                if (it.isOutputDouble()) {
7032                                        while (it.hasNext()) {
7033                                                double iax = it.aDouble;
7034                                                final double ibx = it.bDouble;
7035                                                int ox;
7036                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7037                                                oai32data[it.oIndex] = ox;
7038                                                for (int j = 1; j < is; j++) {
7039                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7040                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7041                                                        oai32data[it.oIndex + j] = ox;
7042                                                }
7043                                        }
7044                                } else {
7045                                        while (it.hasNext()) {
7046                                                long iax = it.aLong;
7047                                                final long ibx = it.bLong;
7048                                                int ox;
7049                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
7050                                                oai32data[it.oIndex] = ox;
7051                                                for (int j = 1; j < is; j++) {
7052                                                        iax = da.getElementLongAbs(it.aIndex + j);
7053                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
7054                                                        oai32data[it.oIndex + j] = ox;
7055                                                }
7056                                        }
7057                                }
7058                        } else if (as == 1) {
7059                                if (it.isOutputDouble()) {
7060                                        while (it.hasNext()) {
7061                                                final double iax = it.aDouble;
7062                                                final double ibx = it.bDouble;
7063                                                int ox;
7064                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7065                                                for (int j = 0; j < is; j++) {
7066                                                        oai32data[it.oIndex + j] = ox;
7067                                                }
7068                                        }
7069                                } else {
7070                                        while (it.hasNext()) {
7071                                                final long iax = it.aLong;
7072                                                final long ibx = it.bLong;
7073                                                int ox;
7074                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
7075                                                for (int j = 0; j < is; j++) {
7076                                                        oai32data[it.oIndex + j] = ox;
7077                                                }
7078                                        }
7079                                }
7080                        } else {
7081                                if (it.isOutputDouble()) {
7082                                        while (it.hasNext()) {
7083                                                double iax = it.aDouble;
7084                                                double ibx = it.bDouble;
7085                                                int ox;
7086                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7087                                                oai32data[it.oIndex] = ox;
7088                                                for (int j = 1; j < is; j++) {
7089                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7090                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7091                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7092                                                        oai32data[it.oIndex + j] = ox;
7093                                                }
7094                                        }
7095                                } else {
7096                                        while (it.hasNext()) {
7097                                                long iax = it.aLong;
7098                                                long ibx = it.bLong;
7099                                                int ox;
7100                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
7101                                                oai32data[it.oIndex] = ox;
7102                                                for (int j = 1; j < is; j++) {
7103                                                        iax = da.getElementLongAbs(it.aIndex + j);
7104                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7105                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
7106                                                        oai32data[it.oIndex + j] = ox;
7107                                                }
7108                                        }
7109                                }
7110                        }
7111                        break;
7112                case Dataset.FLOAT32:
7113                        final float[] of32data = ((FloatDataset) result).getData();
7114                        if (it.isOutputDouble()) {
7115                                while (it.hasNext()) {
7116                                        final double iax = it.aDouble;
7117                                        final double ibx = it.bDouble;
7118                                        float ox;
7119                                        ox = (float) (iax / ibx);
7120                                        of32data[it.oIndex] = ox;
7121                                }
7122                        } else {
7123                                while (it.hasNext()) {
7124                                        final long iax = it.aLong;
7125                                        final long ibx = it.bLong;
7126                                        float ox;
7127                                        ox = (iax / ibx);
7128                                        of32data[it.oIndex] = ox;
7129                                }
7130                        }
7131                        break;
7132                case Dataset.FLOAT64:
7133                        final double[] of64data = ((DoubleDataset) result).getData();
7134                        if (it.isOutputDouble()) {
7135                                while (it.hasNext()) {
7136                                        final double iax = it.aDouble;
7137                                        final double ibx = it.bDouble;
7138                                        double ox;
7139                                        ox = (iax / ibx);
7140                                        of64data[it.oIndex] = ox;
7141                                }
7142                        } else {
7143                                while (it.hasNext()) {
7144                                        final long iax = it.aLong;
7145                                        final long ibx = it.bLong;
7146                                        double ox;
7147                                        ox = (iax / ibx);
7148                                        of64data[it.oIndex] = ox;
7149                                }
7150                        }
7151                        break;
7152                case Dataset.ARRAYFLOAT32:
7153                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
7154                        if (is == 1) {
7155                                if (it.isOutputDouble()) {
7156                                        while (it.hasNext()) {
7157                                                final double iax = it.aDouble;
7158                                                final double ibx = it.bDouble;
7159                                                float ox;
7160                                                ox = (float) (iax / ibx);
7161                                                oaf32data[it.oIndex] = ox;
7162                                        }
7163                                } else {
7164                                        while (it.hasNext()) {
7165                                                final long iax = it.aLong;
7166                                                final long ibx = it.bLong;
7167                                                float ox;
7168                                                ox = (iax / ibx);
7169                                                oaf32data[it.oIndex] = ox;
7170                                        }
7171                                }
7172                        } else if (as < bs) {
7173                                if (it.isOutputDouble()) {
7174                                        while (it.hasNext()) {
7175                                                final double iax = it.aDouble;
7176                                                double ibx = it.bDouble;
7177                                                float ox;
7178                                                ox = (float) (iax / ibx);
7179                                                oaf32data[it.oIndex] = ox;
7180                                                for (int j = 1; j < is; j++) {
7181                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7182                                                        ox = (float) (iax / ibx);
7183                                                        oaf32data[it.oIndex + j] = ox;
7184                                                }
7185                                        }
7186                                } else {
7187                                        while (it.hasNext()) {
7188                                                final long iax = it.aLong;
7189                                                long ibx = it.bLong;
7190                                                float ox;
7191                                                ox = (iax / ibx);
7192                                                oaf32data[it.oIndex] = ox;
7193                                                for (int j = 1; j < is; j++) {
7194                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7195                                                        ox = (iax / ibx);
7196                                                        oaf32data[it.oIndex + j] = ox;
7197                                                }
7198                                        }
7199                                }
7200                        } else if (as > bs) {
7201                                if (it.isOutputDouble()) {
7202                                        while (it.hasNext()) {
7203                                                double iax = it.aDouble;
7204                                                final double ibx = it.bDouble;
7205                                                float ox;
7206                                                ox = (float) (iax / ibx);
7207                                                oaf32data[it.oIndex] = ox;
7208                                                for (int j = 1; j < is; j++) {
7209                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7210                                                        ox = (float) (iax / ibx);
7211                                                        oaf32data[it.oIndex + j] = ox;
7212                                                }
7213                                        }
7214                                } else {
7215                                        while (it.hasNext()) {
7216                                                long iax = it.aLong;
7217                                                final long ibx = it.bLong;
7218                                                float ox;
7219                                                ox = (iax / ibx);
7220                                                oaf32data[it.oIndex] = ox;
7221                                                for (int j = 1; j < is; j++) {
7222                                                        iax = da.getElementLongAbs(it.aIndex + j);
7223                                                        ox = (iax / ibx);
7224                                                        oaf32data[it.oIndex + j] = ox;
7225                                                }
7226                                        }
7227                                }
7228                        } else if (as == 1) {
7229                                if (it.isOutputDouble()) {
7230                                        while (it.hasNext()) {
7231                                                final double iax = it.aDouble;
7232                                                final double ibx = it.bDouble;
7233                                                float ox;
7234                                                ox = (float) (iax / ibx);
7235                                                for (int j = 0; j < is; j++) {
7236                                                        oaf32data[it.oIndex + j] = ox;
7237                                                }
7238                                        }
7239                                } else {
7240                                        while (it.hasNext()) {
7241                                                final long iax = it.aLong;
7242                                                final long ibx = it.bLong;
7243                                                float ox;
7244                                                ox = (iax / ibx);
7245                                                for (int j = 0; j < is; j++) {
7246                                                        oaf32data[it.oIndex + j] = ox;
7247                                                }
7248                                        }
7249                                }
7250                        } else {
7251                                if (it.isOutputDouble()) {
7252                                        while (it.hasNext()) {
7253                                                double iax = it.aDouble;
7254                                                double ibx = it.bDouble;
7255                                                float ox;
7256                                                ox = (float) (iax / ibx);
7257                                                oaf32data[it.oIndex] = ox;
7258                                                for (int j = 1; j < is; j++) {
7259                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7260                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7261                                                        ox = (float) (iax / ibx);
7262                                                        oaf32data[it.oIndex + j] = ox;
7263                                                }
7264                                        }
7265                                } else {
7266                                        while (it.hasNext()) {
7267                                                long iax = it.aLong;
7268                                                long ibx = it.bLong;
7269                                                float ox;
7270                                                ox = (iax / ibx);
7271                                                oaf32data[it.oIndex] = ox;
7272                                                for (int j = 1; j < is; j++) {
7273                                                        iax = da.getElementLongAbs(it.aIndex + j);
7274                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7275                                                        ox = (iax / ibx);
7276                                                        oaf32data[it.oIndex + j] = ox;
7277                                                }
7278                                        }
7279                                }
7280                        }
7281                        break;
7282                case Dataset.ARRAYFLOAT64:
7283                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
7284                        if (is == 1) {
7285                                if (it.isOutputDouble()) {
7286                                        while (it.hasNext()) {
7287                                                final double iax = it.aDouble;
7288                                                final double ibx = it.bDouble;
7289                                                double ox;
7290                                                ox = (iax / ibx);
7291                                                oaf64data[it.oIndex] = ox;
7292                                        }
7293                                } else {
7294                                        while (it.hasNext()) {
7295                                                final long iax = it.aLong;
7296                                                final long ibx = it.bLong;
7297                                                double ox;
7298                                                ox = (iax / ibx);
7299                                                oaf64data[it.oIndex] = ox;
7300                                        }
7301                                }
7302                        } else if (as < bs) {
7303                                if (it.isOutputDouble()) {
7304                                        while (it.hasNext()) {
7305                                                final double iax = it.aDouble;
7306                                                double ibx = it.bDouble;
7307                                                double ox;
7308                                                ox = (iax / ibx);
7309                                                oaf64data[it.oIndex] = ox;
7310                                                for (int j = 1; j < is; j++) {
7311                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7312                                                        ox = (iax / ibx);
7313                                                        oaf64data[it.oIndex + j] = ox;
7314                                                }
7315                                        }
7316                                } else {
7317                                        while (it.hasNext()) {
7318                                                final long iax = it.aLong;
7319                                                long ibx = it.bLong;
7320                                                double ox;
7321                                                ox = (iax / ibx);
7322                                                oaf64data[it.oIndex] = ox;
7323                                                for (int j = 1; j < is; j++) {
7324                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7325                                                        ox = (iax / ibx);
7326                                                        oaf64data[it.oIndex + j] = ox;
7327                                                }
7328                                        }
7329                                }
7330                        } else if (as > bs) {
7331                                if (it.isOutputDouble()) {
7332                                        while (it.hasNext()) {
7333                                                double iax = it.aDouble;
7334                                                final double ibx = it.bDouble;
7335                                                double ox;
7336                                                ox = (iax / ibx);
7337                                                oaf64data[it.oIndex] = ox;
7338                                                for (int j = 1; j < is; j++) {
7339                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7340                                                        ox = (iax / ibx);
7341                                                        oaf64data[it.oIndex + j] = ox;
7342                                                }
7343                                        }
7344                                } else {
7345                                        while (it.hasNext()) {
7346                                                long iax = it.aLong;
7347                                                final long ibx = it.bLong;
7348                                                double ox;
7349                                                ox = (iax / ibx);
7350                                                oaf64data[it.oIndex] = ox;
7351                                                for (int j = 1; j < is; j++) {
7352                                                        iax = da.getElementLongAbs(it.aIndex + j);
7353                                                        ox = (iax / ibx);
7354                                                        oaf64data[it.oIndex + j] = ox;
7355                                                }
7356                                        }
7357                                }
7358                        } else if (as == 1) {
7359                                if (it.isOutputDouble()) {
7360                                        while (it.hasNext()) {
7361                                                final double iax = it.aDouble;
7362                                                final double ibx = it.bDouble;
7363                                                double ox;
7364                                                ox = (iax / ibx);
7365                                                for (int j = 0; j < is; j++) {
7366                                                        oaf64data[it.oIndex + j] = ox;
7367                                                }
7368                                        }
7369                                } else {
7370                                        while (it.hasNext()) {
7371                                                final long iax = it.aLong;
7372                                                final long ibx = it.bLong;
7373                                                double ox;
7374                                                ox = (iax / ibx);
7375                                                for (int j = 0; j < is; j++) {
7376                                                        oaf64data[it.oIndex + j] = ox;
7377                                                }
7378                                        }
7379                                }
7380                        } else {
7381                                if (it.isOutputDouble()) {
7382                                        while (it.hasNext()) {
7383                                                double iax = it.aDouble;
7384                                                double ibx = it.bDouble;
7385                                                double ox;
7386                                                ox = (iax / ibx);
7387                                                oaf64data[it.oIndex] = ox;
7388                                                for (int j = 1; j < is; j++) {
7389                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7390                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7391                                                        ox = (iax / ibx);
7392                                                        oaf64data[it.oIndex + j] = ox;
7393                                                }
7394                                        }
7395                                } else {
7396                                        while (it.hasNext()) {
7397                                                long iax = it.aLong;
7398                                                long ibx = it.bLong;
7399                                                double ox;
7400                                                ox = (iax / ibx);
7401                                                oaf64data[it.oIndex] = ox;
7402                                                for (int j = 1; j < is; j++) {
7403                                                        iax = da.getElementLongAbs(it.aIndex + j);
7404                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7405                                                        ox = (iax / ibx);
7406                                                        oaf64data[it.oIndex + j] = ox;
7407                                                }
7408                                        }
7409                                }
7410                        }
7411                        break;
7412                case Dataset.COMPLEX64:
7413                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
7414                        if (!da.isComplex()) {
7415                                if (it.isOutputDouble()) {
7416                                        final double iay = 0;
7417                                        if (db.isComplex()) {
7418                                                while (it.hasNext()) {
7419                                                        final double iax = it.aDouble;
7420                                                        final double ibx = it.bDouble;
7421                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
7422                                                        float ox;
7423                                                        float oy;
7424                                                        float q;
7425                                                        float den;
7426                                                        if (iby == 0) {
7427                                                                ox = (float) (iax / ibx);
7428                                                                oy = (float) (iay / ibx);
7429                                                        } else if (ibx == 0) {
7430                                                                ox = (float) (iay / iby);
7431                                                                oy = (float) (-iax / iby);
7432                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
7433                                                                q = (float) (ibx / iby);
7434                                                                den = (float) (ibx * q + iby);
7435                                                                ox = (float) ((iax * q + iay) / den);
7436                                                                oy = (float) ((iay * q - ibx) / den);
7437                                                        } else {
7438                                                                q = (float) (iby / ibx);
7439                                                                den = (float) (iby * q + ibx);
7440                                                                ox = (float) ((iay * q + iax) / den);
7441                                                                oy = (float) ((iay - iax * q) / den);
7442                                                        }
7443                                                        oc64data[it.oIndex] = ox;
7444                                                        oc64data[it.oIndex + 1] = oy;
7445                                                }
7446                                        } else {
7447                                                while (it.hasNext()) {
7448                                                        final double iax = it.aDouble;
7449                                                        final double ibx = it.bDouble;
7450                                                        final double iby = 0;
7451                                                        float ox;
7452                                                        float oy;
7453                                                        float q;
7454                                                        float den;
7455                                                        if (iby == 0) {
7456                                                                ox = (float) (iax / ibx);
7457                                                                oy = (float) (iay / ibx);
7458                                                        } else if (ibx == 0) {
7459                                                                ox = (float) (iay / iby);
7460                                                                oy = (float) (-iax / iby);
7461                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
7462                                                                q = (float) (ibx / iby);
7463                                                                den = (float) (ibx * q + iby);
7464                                                                ox = (float) ((iax * q + iay) / den);
7465                                                                oy = (float) ((iay * q - ibx) / den);
7466                                                        } else {
7467                                                                q = (float) (iby / ibx);
7468                                                                den = (float) (iby * q + ibx);
7469                                                                ox = (float) ((iay * q + iax) / den);
7470                                                                oy = (float) ((iay - iax * q) / den);
7471                                                        }
7472                                                        oc64data[it.oIndex] = ox;
7473                                                        oc64data[it.oIndex + 1] = oy;
7474                                                }
7475                                        }
7476                                } else {
7477                                        final long iay = 0;
7478                                        while (it.hasNext()) {
7479                                                final long iax = it.aLong;
7480                                                final long ibx = it.bLong;
7481                                                final long iby = 0;
7482                                                float ox;
7483                                                float oy;
7484                                                float q;
7485                                                float den;
7486                                                if (iby == 0) {
7487                                                        ox = (float) (iax / ibx);
7488                                                        oy = (float) (iay / ibx);
7489                                                } else if (ibx == 0) {
7490                                                        ox = (float) (iay / iby);
7491                                                        oy = (float) (-iax / iby);
7492                                                } else if (Math.abs(ibx) < Math.abs(iby)) {
7493                                                        q = (float) (ibx / iby);
7494                                                        den = (float) (ibx * q + iby);
7495                                                        ox = (float) ((iax * q + iay) / den);
7496                                                        oy = (float) ((iay * q - ibx) / den);
7497                                                } else {
7498                                                        q = (float) (iby / ibx);
7499                                                        den = (float) (iby * q + ibx);
7500                                                        ox = (float) ((iay * q + iax) / den);
7501                                                        oy = (float) ((iay - iax * q) / den);
7502                                                }
7503                                                oc64data[it.oIndex] = ox;
7504                                                oc64data[it.oIndex + 1] = oy;
7505                                        }
7506                                }
7507                        } else if (!db.isComplex()) {
7508                                final double iby = 0;
7509                                while (it.hasNext()) {
7510                                        final double iax = it.aDouble;
7511                                        final double ibx = it.bDouble;
7512                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
7513                                        float ox;
7514                                        float oy;
7515                                        float q;
7516                                        float den;
7517                                        if (iby == 0) {
7518                                                ox = (float) (iax / ibx);
7519                                                oy = (float) (iay / ibx);
7520                                        } else if (ibx == 0) {
7521                                                ox = (float) (iay / iby);
7522                                                oy = (float) (-iax / iby);
7523                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
7524                                                q = (float) (ibx / iby);
7525                                                den = (float) (ibx * q + iby);
7526                                                ox = (float) ((iax * q + iay) / den);
7527                                                oy = (float) ((iay * q - ibx) / den);
7528                                        } else {
7529                                                q = (float) (iby / ibx);
7530                                                den = (float) (iby * q + ibx);
7531                                                ox = (float) ((iay * q + iax) / den);
7532                                                oy = (float) ((iay - iax * q) / den);
7533                                        }
7534                                        oc64data[it.oIndex] = ox;
7535                                        oc64data[it.oIndex + 1] = oy;
7536                                }
7537                        } else {
7538                                while (it.hasNext()) {
7539                                        final double iax = it.aDouble;
7540                                        final double ibx = it.bDouble;
7541                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
7542                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
7543                                        float ox;
7544                                        float oy;
7545                                        float q;
7546                                        float den;
7547                                        if (iby == 0) {
7548                                                ox = (float) (iax / ibx);
7549                                                oy = (float) (iay / ibx);
7550                                        } else if (ibx == 0) {
7551                                                ox = (float) (iay / iby);
7552                                                oy = (float) (-iax / iby);
7553                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
7554                                                q = (float) (ibx / iby);
7555                                                den = (float) (ibx * q + iby);
7556                                                ox = (float) ((iax * q + iay) / den);
7557                                                oy = (float) ((iay * q - ibx) / den);
7558                                        } else {
7559                                                q = (float) (iby / ibx);
7560                                                den = (float) (iby * q + ibx);
7561                                                ox = (float) ((iay * q + iax) / den);
7562                                                oy = (float) ((iay - iax * q) / den);
7563                                        }
7564                                        oc64data[it.oIndex] = ox;
7565                                        oc64data[it.oIndex + 1] = oy;
7566                                }
7567                        }
7568                        break;
7569                case Dataset.COMPLEX128:
7570                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
7571                        if (!da.isComplex()) {
7572                                if (it.isOutputDouble()) {
7573                                        final double iay = 0;
7574                                        if (db.isComplex()) {
7575                                                while (it.hasNext()) {
7576                                                        final double iax = it.aDouble;
7577                                                        final double ibx = it.bDouble;
7578                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
7579                                                        double ox;
7580                                                        double oy;
7581                                                        double q;
7582                                                        double den;
7583                                                        if (iby == 0) {
7584                                                                ox = (iax / ibx);
7585                                                                oy = (iay / ibx);
7586                                                        } else if (ibx == 0) {
7587                                                                ox = (iay / iby);
7588                                                                oy = (-iax / iby);
7589                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
7590                                                                q = (ibx / iby);
7591                                                                den = (ibx * q + iby);
7592                                                                ox = ((iax * q + iay) / den);
7593                                                                oy = ((iay * q - ibx) / den);
7594                                                        } else {
7595                                                                q = (iby / ibx);
7596                                                                den = (iby * q + ibx);
7597                                                                ox = ((iay * q + iax) / den);
7598                                                                oy = ((iay - iax * q) / den);
7599                                                        }
7600                                                        oc128data[it.oIndex] = ox;
7601                                                        oc128data[it.oIndex + 1] = oy;
7602                                                }
7603                                        } else {
7604                                                while (it.hasNext()) {
7605                                                        final double iax = it.aDouble;
7606                                                        final double ibx = it.bDouble;
7607                                                        final double iby = 0;
7608                                                        double ox;
7609                                                        double oy;
7610                                                        double q;
7611                                                        double den;
7612                                                        if (iby == 0) {
7613                                                                ox = (iax / ibx);
7614                                                                oy = (iay / ibx);
7615                                                        } else if (ibx == 0) {
7616                                                                ox = (iay / iby);
7617                                                                oy = (-iax / iby);
7618                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
7619                                                                q = (ibx / iby);
7620                                                                den = (ibx * q + iby);
7621                                                                ox = ((iax * q + iay) / den);
7622                                                                oy = ((iay * q - ibx) / den);
7623                                                        } else {
7624                                                                q = (iby / ibx);
7625                                                                den = (iby * q + ibx);
7626                                                                ox = ((iay * q + iax) / den);
7627                                                                oy = ((iay - iax * q) / den);
7628                                                        }
7629                                                        oc128data[it.oIndex] = ox;
7630                                                        oc128data[it.oIndex + 1] = oy;
7631                                                }
7632                                        }
7633                                } else {
7634                                        final long iay = 0;
7635                                        while (it.hasNext()) {
7636                                                final long iax = it.aLong;
7637                                                final long ibx = it.bLong;
7638                                                final long iby = 0;
7639                                                double ox;
7640                                                double oy;
7641                                                double q;
7642                                                double den;
7643                                                if (iby == 0) {
7644                                                        ox = (iax / ibx);
7645                                                        oy = (iay / ibx);
7646                                                } else if (ibx == 0) {
7647                                                        ox = (iay / iby);
7648                                                        oy = (-iax / iby);
7649                                                } else if (Math.abs(ibx) < Math.abs(iby)) {
7650                                                        q = (ibx / iby);
7651                                                        den = (ibx * q + iby);
7652                                                        ox = ((iax * q + iay) / den);
7653                                                        oy = ((iay * q - ibx) / den);
7654                                                } else {
7655                                                        q = (iby / ibx);
7656                                                        den = (iby * q + ibx);
7657                                                        ox = ((iay * q + iax) / den);
7658                                                        oy = ((iay - iax * q) / den);
7659                                                }
7660                                                oc128data[it.oIndex] = ox;
7661                                                oc128data[it.oIndex + 1] = oy;
7662                                        }
7663                                }
7664                        } else if (!db.isComplex()) {
7665                                final double iby = 0;
7666                                while (it.hasNext()) {
7667                                        final double iax = it.aDouble;
7668                                        final double ibx = it.bDouble;
7669                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
7670                                        double ox;
7671                                        double oy;
7672                                        double q;
7673                                        double den;
7674                                        if (iby == 0) {
7675                                                ox = (iax / ibx);
7676                                                oy = (iay / ibx);
7677                                        } else if (ibx == 0) {
7678                                                ox = (iay / iby);
7679                                                oy = (-iax / iby);
7680                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
7681                                                q = (ibx / iby);
7682                                                den = (ibx * q + iby);
7683                                                ox = ((iax * q + iay) / den);
7684                                                oy = ((iay * q - ibx) / den);
7685                                        } else {
7686                                                q = (iby / ibx);
7687                                                den = (iby * q + ibx);
7688                                                ox = ((iay * q + iax) / den);
7689                                                oy = ((iay - iax * q) / den);
7690                                        }
7691                                        oc128data[it.oIndex] = ox;
7692                                        oc128data[it.oIndex + 1] = oy;
7693                                }
7694                        } else {
7695                                while (it.hasNext()) {
7696                                        final double iax = it.aDouble;
7697                                        final double ibx = it.bDouble;
7698                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
7699                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
7700                                        double ox;
7701                                        double oy;
7702                                        double q;
7703                                        double den;
7704                                        if (iby == 0) {
7705                                                ox = (iax / ibx);
7706                                                oy = (iay / ibx);
7707                                        } else if (ibx == 0) {
7708                                                ox = (iay / iby);
7709                                                oy = (-iax / iby);
7710                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
7711                                                q = (ibx / iby);
7712                                                den = (ibx * q + iby);
7713                                                ox = ((iax * q + iay) / den);
7714                                                oy = ((iay * q - ibx) / den);
7715                                        } else {
7716                                                q = (iby / ibx);
7717                                                den = (iby * q + ibx);
7718                                                ox = ((iay * q + iax) / den);
7719                                                oy = ((iay - iax * q) / den);
7720                                        }
7721                                        oc128data[it.oIndex] = ox;
7722                                        oc128data[it.oIndex + 1] = oy;
7723                                }
7724                        }
7725                        break;
7726                default:
7727                        throw new IllegalArgumentException("divide supports integer, compound integer, real, compound real, complex datasets only");
7728                }
7729
7730                addBinaryOperatorName(da, db, result, "/");
7731                return result;
7732        }
7733
7734        /**
7735         * dividez operator
7736         * @param a
7737         * @param b
7738         * @return {@code a / b}, division of a by b
7739         */
7740        public static Dataset dividez(final Object a, final Object b) {
7741                return dividez(a, b, null);
7742        }
7743
7744        /**
7745         * dividez operator
7746         * @param a
7747         * @param b
7748         * @param o output can be null - in which case, a new dataset is created
7749         * @return {@code a / b}, division of a by b
7750         */
7751        public static Dataset dividez(final Object a, final Object b, final Dataset o) {
7752                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
7753                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
7754                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
7755                final Dataset result = it.getOutput();
7756                if (!result.isComplex()) {
7757                        boolean change = false;
7758                        if (da.isComplex()) {
7759                                da = da.getRealView();
7760                                change = true;
7761                        }
7762                        if (db.isComplex()) {
7763                                db = db.getRealView();
7764                                change = true;
7765                        }
7766                        if (change) {
7767                                it = BroadcastIterator.createIterator(da, db, result, true);
7768                        }
7769                }
7770                final int is = result.getElementsPerItem();
7771                final int as = da.getElementsPerItem();
7772                final int bs = db.getElementsPerItem();
7773                final int dt = result.getDType();
7774
7775                switch(dt) {
7776                case Dataset.INT8:
7777                        final byte[] oi8data = ((ByteDataset) result).getData();
7778                        if (it.isOutputDouble()) {
7779                                while (it.hasNext()) {
7780                                        final double iax = it.aDouble;
7781                                        final double ibx = it.bDouble;
7782                                        byte ox;
7783                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7784                                        oi8data[it.oIndex] = ox;
7785                                }
7786                        } else {
7787                                while (it.hasNext()) {
7788                                        final long iax = it.aLong;
7789                                        final long ibx = it.bLong;
7790                                        byte ox;
7791                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7792                                        oi8data[it.oIndex] = ox;
7793                                }
7794                        }
7795                        break;
7796                case Dataset.INT16:
7797                        final short[] oi16data = ((ShortDataset) result).getData();
7798                        if (it.isOutputDouble()) {
7799                                while (it.hasNext()) {
7800                                        final double iax = it.aDouble;
7801                                        final double ibx = it.bDouble;
7802                                        short ox;
7803                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
7804                                        oi16data[it.oIndex] = ox;
7805                                }
7806                        } else {
7807                                while (it.hasNext()) {
7808                                        final long iax = it.aLong;
7809                                        final long ibx = it.bLong;
7810                                        short ox;
7811                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
7812                                        oi16data[it.oIndex] = ox;
7813                                }
7814                        }
7815                        break;
7816                case Dataset.INT64:
7817                        final long[] oi64data = ((LongDataset) result).getData();
7818                        if (it.isOutputDouble()) {
7819                                while (it.hasNext()) {
7820                                        final double iax = it.aDouble;
7821                                        final double ibx = it.bDouble;
7822                                        long ox;
7823                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
7824                                        oi64data[it.oIndex] = ox;
7825                                }
7826                        } else {
7827                                while (it.hasNext()) {
7828                                        final long iax = it.aLong;
7829                                        final long ibx = it.bLong;
7830                                        long ox;
7831                                        ox = (ibx == 0 ? 0 : iax / ibx);
7832                                        oi64data[it.oIndex] = ox;
7833                                }
7834                        }
7835                        break;
7836                case Dataset.INT32:
7837                        final int[] oi32data = ((IntegerDataset) result).getData();
7838                        if (it.isOutputDouble()) {
7839                                while (it.hasNext()) {
7840                                        final double iax = it.aDouble;
7841                                        final double ibx = it.bDouble;
7842                                        int ox;
7843                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7844                                        oi32data[it.oIndex] = ox;
7845                                }
7846                        } else {
7847                                while (it.hasNext()) {
7848                                        final long iax = it.aLong;
7849                                        final long ibx = it.bLong;
7850                                        int ox;
7851                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
7852                                        oi32data[it.oIndex] = ox;
7853                                }
7854                        }
7855                        break;
7856                case Dataset.ARRAYINT8:
7857                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
7858                        if (is == 1) {
7859                                if (it.isOutputDouble()) {
7860                                        while (it.hasNext()) {
7861                                                final double iax = it.aDouble;
7862                                                final double ibx = it.bDouble;
7863                                                byte ox;
7864                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7865                                                oai8data[it.oIndex] = ox;
7866                                        }
7867                                } else {
7868                                        while (it.hasNext()) {
7869                                                final long iax = it.aLong;
7870                                                final long ibx = it.bLong;
7871                                                byte ox;
7872                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7873                                                oai8data[it.oIndex] = ox;
7874                                        }
7875                                }
7876                        } else if (as < bs) {
7877                                if (it.isOutputDouble()) {
7878                                        while (it.hasNext()) {
7879                                                final double iax = it.aDouble;
7880                                                double ibx = it.bDouble;
7881                                                byte ox;
7882                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7883                                                oai8data[it.oIndex] = ox;
7884                                                for (int j = 1; j < is; j++) {
7885                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7886                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7887                                                        oai8data[it.oIndex + j] = ox;
7888                                                }
7889                                        }
7890                                } else {
7891                                        while (it.hasNext()) {
7892                                                final long iax = it.aLong;
7893                                                long ibx = it.bLong;
7894                                                byte ox;
7895                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7896                                                oai8data[it.oIndex] = ox;
7897                                                for (int j = 1; j < is; j++) {
7898                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7899                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7900                                                        oai8data[it.oIndex + j] = ox;
7901                                                }
7902                                        }
7903                                }
7904                        } else if (as > bs) {
7905                                if (it.isOutputDouble()) {
7906                                        while (it.hasNext()) {
7907                                                double iax = it.aDouble;
7908                                                final double ibx = it.bDouble;
7909                                                byte ox;
7910                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7911                                                oai8data[it.oIndex] = ox;
7912                                                for (int j = 1; j < is; j++) {
7913                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7914                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7915                                                        oai8data[it.oIndex + j] = ox;
7916                                                }
7917                                        }
7918                                } else {
7919                                        while (it.hasNext()) {
7920                                                long iax = it.aLong;
7921                                                final long ibx = it.bLong;
7922                                                byte ox;
7923                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7924                                                oai8data[it.oIndex] = ox;
7925                                                for (int j = 1; j < is; j++) {
7926                                                        iax = da.getElementLongAbs(it.aIndex + j);
7927                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7928                                                        oai8data[it.oIndex + j] = ox;
7929                                                }
7930                                        }
7931                                }
7932                        } else if (as == 1) {
7933                                if (it.isOutputDouble()) {
7934                                        while (it.hasNext()) {
7935                                                final double iax = it.aDouble;
7936                                                final double ibx = it.bDouble;
7937                                                byte ox;
7938                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7939                                                for (int j = 0; j < is; j++) {
7940                                                        oai8data[it.oIndex + j] = ox;
7941                                                }
7942                                        }
7943                                } else {
7944                                        while (it.hasNext()) {
7945                                                final long iax = it.aLong;
7946                                                final long ibx = it.bLong;
7947                                                byte ox;
7948                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7949                                                for (int j = 0; j < is; j++) {
7950                                                        oai8data[it.oIndex + j] = ox;
7951                                                }
7952                                        }
7953                                }
7954                        } else {
7955                                if (it.isOutputDouble()) {
7956                                        while (it.hasNext()) {
7957                                                double iax = it.aDouble;
7958                                                double ibx = it.bDouble;
7959                                                byte ox;
7960                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7961                                                oai8data[it.oIndex] = ox;
7962                                                for (int j = 1; j < is; j++) {
7963                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7964                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7965                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7966                                                        oai8data[it.oIndex + j] = ox;
7967                                                }
7968                                        }
7969                                } else {
7970                                        while (it.hasNext()) {
7971                                                long iax = it.aLong;
7972                                                long ibx = it.bLong;
7973                                                byte ox;
7974                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7975                                                oai8data[it.oIndex] = ox;
7976                                                for (int j = 1; j < is; j++) {
7977                                                        iax = da.getElementLongAbs(it.aIndex + j);
7978                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7979                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7980                                                        oai8data[it.oIndex + j] = ox;
7981                                                }
7982                                        }
7983                                }
7984                        }
7985                        break;
7986                case Dataset.ARRAYINT16:
7987                        final short[] oai16data = ((CompoundShortDataset) result).getData();
7988                        if (is == 1) {
7989                                if (it.isOutputDouble()) {
7990                                        while (it.hasNext()) {
7991                                                final double iax = it.aDouble;
7992                                                final double ibx = it.bDouble;
7993                                                short ox;
7994                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
7995                                                oai16data[it.oIndex] = ox;
7996                                        }
7997                                } else {
7998                                        while (it.hasNext()) {
7999                                                final long iax = it.aLong;
8000                                                final long ibx = it.bLong;
8001                                                short ox;
8002                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
8003                                                oai16data[it.oIndex] = ox;
8004                                        }
8005                                }
8006                        } else if (as < bs) {
8007                                if (it.isOutputDouble()) {
8008                                        while (it.hasNext()) {
8009                                                final double iax = it.aDouble;
8010                                                double ibx = it.bDouble;
8011                                                short ox;
8012                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
8013                                                oai16data[it.oIndex] = ox;
8014                                                for (int j = 1; j < is; j++) {
8015                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8016                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
8017                                                        oai16data[it.oIndex + j] = ox;
8018                                                }
8019                                        }
8020                                } else {
8021                                        while (it.hasNext()) {
8022                                                final long iax = it.aLong;
8023                                                long ibx = it.bLong;
8024                                                short ox;
8025                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
8026                                                oai16data[it.oIndex] = ox;
8027                                                for (int j = 1; j < is; j++) {
8028                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8029                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
8030                                                        oai16data[it.oIndex + j] = ox;
8031                                                }
8032                                        }
8033                                }
8034                        } else if (as > bs) {
8035                                if (it.isOutputDouble()) {
8036                                        while (it.hasNext()) {
8037                                                double iax = it.aDouble;
8038                                                final double ibx = it.bDouble;
8039                                                short ox;
8040                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
8041                                                oai16data[it.oIndex] = ox;
8042                                                for (int j = 1; j < is; j++) {
8043                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8044                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
8045                                                        oai16data[it.oIndex + j] = ox;
8046                                                }
8047                                        }
8048                                } else {
8049                                        while (it.hasNext()) {
8050                                                long iax = it.aLong;
8051                                                final long ibx = it.bLong;
8052                                                short ox;
8053                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
8054                                                oai16data[it.oIndex] = ox;
8055                                                for (int j = 1; j < is; j++) {
8056                                                        iax = da.getElementLongAbs(it.aIndex + j);
8057                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
8058                                                        oai16data[it.oIndex + j] = ox;
8059                                                }
8060                                        }
8061                                }
8062                        } else if (as == 1) {
8063                                if (it.isOutputDouble()) {
8064                                        while (it.hasNext()) {
8065                                                final double iax = it.aDouble;
8066                                                final double ibx = it.bDouble;
8067                                                short ox;
8068                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
8069                                                for (int j = 0; j < is; j++) {
8070                                                        oai16data[it.oIndex + j] = ox;
8071                                                }
8072                                        }
8073                                } else {
8074                                        while (it.hasNext()) {
8075                                                final long iax = it.aLong;
8076                                                final long ibx = it.bLong;
8077                                                short ox;
8078                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
8079                                                for (int j = 0; j < is; j++) {
8080                                                        oai16data[it.oIndex + j] = ox;
8081                                                }
8082                                        }
8083                                }
8084                        } else {
8085                                if (it.isOutputDouble()) {
8086                                        while (it.hasNext()) {
8087                                                double iax = it.aDouble;
8088                                                double ibx = it.bDouble;
8089                                                short ox;
8090                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
8091                                                oai16data[it.oIndex] = ox;
8092                                                for (int j = 1; j < is; j++) {
8093                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8094                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8095                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
8096                                                        oai16data[it.oIndex + j] = ox;
8097                                                }
8098                                        }
8099                                } else {
8100                                        while (it.hasNext()) {
8101                                                long iax = it.aLong;
8102                                                long ibx = it.bLong;
8103                                                short ox;
8104                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
8105                                                oai16data[it.oIndex] = ox;
8106                                                for (int j = 1; j < is; j++) {
8107                                                        iax = da.getElementLongAbs(it.aIndex + j);
8108                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8109                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
8110                                                        oai16data[it.oIndex + j] = ox;
8111                                                }
8112                                        }
8113                                }
8114                        }
8115                        break;
8116                case Dataset.ARRAYINT64:
8117                        final long[] oai64data = ((CompoundLongDataset) result).getData();
8118                        if (is == 1) {
8119                                if (it.isOutputDouble()) {
8120                                        while (it.hasNext()) {
8121                                                final double iax = it.aDouble;
8122                                                final double ibx = it.bDouble;
8123                                                long ox;
8124                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
8125                                                oai64data[it.oIndex] = ox;
8126                                        }
8127                                } else {
8128                                        while (it.hasNext()) {
8129                                                final long iax = it.aLong;
8130                                                final long ibx = it.bLong;
8131                                                long ox;
8132                                                ox = (ibx == 0 ? 0 : iax / ibx);
8133                                                oai64data[it.oIndex] = ox;
8134                                        }
8135                                }
8136                        } else if (as < bs) {
8137                                if (it.isOutputDouble()) {
8138                                        while (it.hasNext()) {
8139                                                final double iax = it.aDouble;
8140                                                double ibx = it.bDouble;
8141                                                long ox;
8142                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
8143                                                oai64data[it.oIndex] = ox;
8144                                                for (int j = 1; j < is; j++) {
8145                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8146                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
8147                                                        oai64data[it.oIndex + j] = ox;
8148                                                }
8149                                        }
8150                                } else {
8151                                        while (it.hasNext()) {
8152                                                final long iax = it.aLong;
8153                                                long ibx = it.bLong;
8154                                                long ox;
8155                                                ox = (ibx == 0 ? 0 : iax / ibx);
8156                                                oai64data[it.oIndex] = ox;
8157                                                for (int j = 1; j < is; j++) {
8158                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8159                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8160                                                        oai64data[it.oIndex + j] = ox;
8161                                                }
8162                                        }
8163                                }
8164                        } else if (as > bs) {
8165                                if (it.isOutputDouble()) {
8166                                        while (it.hasNext()) {
8167                                                double iax = it.aDouble;
8168                                                final double ibx = it.bDouble;
8169                                                long ox;
8170                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
8171                                                oai64data[it.oIndex] = ox;
8172                                                for (int j = 1; j < is; j++) {
8173                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8174                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
8175                                                        oai64data[it.oIndex + j] = ox;
8176                                                }
8177                                        }
8178                                } else {
8179                                        while (it.hasNext()) {
8180                                                long iax = it.aLong;
8181                                                final long ibx = it.bLong;
8182                                                long ox;
8183                                                ox = (ibx == 0 ? 0 : iax / ibx);
8184                                                oai64data[it.oIndex] = ox;
8185                                                for (int j = 1; j < is; j++) {
8186                                                        iax = da.getElementLongAbs(it.aIndex + j);
8187                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8188                                                        oai64data[it.oIndex + j] = ox;
8189                                                }
8190                                        }
8191                                }
8192                        } else if (as == 1) {
8193                                if (it.isOutputDouble()) {
8194                                        while (it.hasNext()) {
8195                                                final double iax = it.aDouble;
8196                                                final double ibx = it.bDouble;
8197                                                long ox;
8198                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
8199                                                for (int j = 0; j < is; j++) {
8200                                                        oai64data[it.oIndex + j] = ox;
8201                                                }
8202                                        }
8203                                } else {
8204                                        while (it.hasNext()) {
8205                                                final long iax = it.aLong;
8206                                                final long ibx = it.bLong;
8207                                                long ox;
8208                                                ox = (ibx == 0 ? 0 : iax / ibx);
8209                                                for (int j = 0; j < is; j++) {
8210                                                        oai64data[it.oIndex + j] = ox;
8211                                                }
8212                                        }
8213                                }
8214                        } else {
8215                                if (it.isOutputDouble()) {
8216                                        while (it.hasNext()) {
8217                                                double iax = it.aDouble;
8218                                                double ibx = it.bDouble;
8219                                                long ox;
8220                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
8221                                                oai64data[it.oIndex] = ox;
8222                                                for (int j = 1; j < is; j++) {
8223                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8224                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8225                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
8226                                                        oai64data[it.oIndex + j] = ox;
8227                                                }
8228                                        }
8229                                } else {
8230                                        while (it.hasNext()) {
8231                                                long iax = it.aLong;
8232                                                long ibx = it.bLong;
8233                                                long ox;
8234                                                ox = (ibx == 0 ? 0 : iax / ibx);
8235                                                oai64data[it.oIndex] = ox;
8236                                                for (int j = 1; j < is; j++) {
8237                                                        iax = da.getElementLongAbs(it.aIndex + j);
8238                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8239                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8240                                                        oai64data[it.oIndex + j] = ox;
8241                                                }
8242                                        }
8243                                }
8244                        }
8245                        break;
8246                case Dataset.ARRAYINT32:
8247                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
8248                        if (is == 1) {
8249                                if (it.isOutputDouble()) {
8250                                        while (it.hasNext()) {
8251                                                final double iax = it.aDouble;
8252                                                final double ibx = it.bDouble;
8253                                                int ox;
8254                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8255                                                oai32data[it.oIndex] = ox;
8256                                        }
8257                                } else {
8258                                        while (it.hasNext()) {
8259                                                final long iax = it.aLong;
8260                                                final long ibx = it.bLong;
8261                                                int ox;
8262                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
8263                                                oai32data[it.oIndex] = ox;
8264                                        }
8265                                }
8266                        } else if (as < bs) {
8267                                if (it.isOutputDouble()) {
8268                                        while (it.hasNext()) {
8269                                                final double iax = it.aDouble;
8270                                                double ibx = it.bDouble;
8271                                                int ox;
8272                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8273                                                oai32data[it.oIndex] = ox;
8274                                                for (int j = 1; j < is; j++) {
8275                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8276                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8277                                                        oai32data[it.oIndex + j] = ox;
8278                                                }
8279                                        }
8280                                } else {
8281                                        while (it.hasNext()) {
8282                                                final long iax = it.aLong;
8283                                                long ibx = it.bLong;
8284                                                int ox;
8285                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
8286                                                oai32data[it.oIndex] = ox;
8287                                                for (int j = 1; j < is; j++) {
8288                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8289                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
8290                                                        oai32data[it.oIndex + j] = ox;
8291                                                }
8292                                        }
8293                                }
8294                        } else if (as > bs) {
8295                                if (it.isOutputDouble()) {
8296                                        while (it.hasNext()) {
8297                                                double iax = it.aDouble;
8298                                                final double ibx = it.bDouble;
8299                                                int ox;
8300                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8301                                                oai32data[it.oIndex] = ox;
8302                                                for (int j = 1; j < is; j++) {
8303                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8304                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8305                                                        oai32data[it.oIndex + j] = ox;
8306                                                }
8307                                        }
8308                                } else {
8309                                        while (it.hasNext()) {
8310                                                long iax = it.aLong;
8311                                                final long ibx = it.bLong;
8312                                                int ox;
8313                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
8314                                                oai32data[it.oIndex] = ox;
8315                                                for (int j = 1; j < is; j++) {
8316                                                        iax = da.getElementLongAbs(it.aIndex + j);
8317                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
8318                                                        oai32data[it.oIndex + j] = ox;
8319                                                }
8320                                        }
8321                                }
8322                        } else if (as == 1) {
8323                                if (it.isOutputDouble()) {
8324                                        while (it.hasNext()) {
8325                                                final double iax = it.aDouble;
8326                                                final double ibx = it.bDouble;
8327                                                int ox;
8328                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8329                                                for (int j = 0; j < is; j++) {
8330                                                        oai32data[it.oIndex + j] = ox;
8331                                                }
8332                                        }
8333                                } else {
8334                                        while (it.hasNext()) {
8335                                                final long iax = it.aLong;
8336                                                final long ibx = it.bLong;
8337                                                int ox;
8338                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
8339                                                for (int j = 0; j < is; j++) {
8340                                                        oai32data[it.oIndex + j] = ox;
8341                                                }
8342                                        }
8343                                }
8344                        } else {
8345                                if (it.isOutputDouble()) {
8346                                        while (it.hasNext()) {
8347                                                double iax = it.aDouble;
8348                                                double ibx = it.bDouble;
8349                                                int ox;
8350                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8351                                                oai32data[it.oIndex] = ox;
8352                                                for (int j = 1; j < is; j++) {
8353                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8354                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8355                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8356                                                        oai32data[it.oIndex + j] = ox;
8357                                                }
8358                                        }
8359                                } else {
8360                                        while (it.hasNext()) {
8361                                                long iax = it.aLong;
8362                                                long ibx = it.bLong;
8363                                                int ox;
8364                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
8365                                                oai32data[it.oIndex] = ox;
8366                                                for (int j = 1; j < is; j++) {
8367                                                        iax = da.getElementLongAbs(it.aIndex + j);
8368                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8369                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
8370                                                        oai32data[it.oIndex + j] = ox;
8371                                                }
8372                                        }
8373                                }
8374                        }
8375                        break;
8376                case Dataset.FLOAT32:
8377                        final float[] of32data = ((FloatDataset) result).getData();
8378                        if (it.isOutputDouble()) {
8379                                while (it.hasNext()) {
8380                                        final double iax = it.aDouble;
8381                                        final double ibx = it.bDouble;
8382                                        float ox;
8383                                        ox = (float) (ibx == 0 ? 0 : iax / ibx);
8384                                        of32data[it.oIndex] = ox;
8385                                }
8386                        } else {
8387                                while (it.hasNext()) {
8388                                        final long iax = it.aLong;
8389                                        final long ibx = it.bLong;
8390                                        float ox;
8391                                        ox = (ibx == 0 ? 0 : iax / ibx);
8392                                        of32data[it.oIndex] = ox;
8393                                }
8394                        }
8395                        break;
8396                case Dataset.FLOAT64:
8397                        final double[] of64data = ((DoubleDataset) result).getData();
8398                        if (it.isOutputDouble()) {
8399                                while (it.hasNext()) {
8400                                        final double iax = it.aDouble;
8401                                        final double ibx = it.bDouble;
8402                                        double ox;
8403                                        ox = (ibx == 0 ? 0 : iax / ibx);
8404                                        of64data[it.oIndex] = ox;
8405                                }
8406                        } else {
8407                                while (it.hasNext()) {
8408                                        final long iax = it.aLong;
8409                                        final long ibx = it.bLong;
8410                                        double ox;
8411                                        ox = (ibx == 0 ? 0 : iax / ibx);
8412                                        of64data[it.oIndex] = ox;
8413                                }
8414                        }
8415                        break;
8416                case Dataset.ARRAYFLOAT32:
8417                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
8418                        if (is == 1) {
8419                                if (it.isOutputDouble()) {
8420                                        while (it.hasNext()) {
8421                                                final double iax = it.aDouble;
8422                                                final double ibx = it.bDouble;
8423                                                float ox;
8424                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
8425                                                oaf32data[it.oIndex] = ox;
8426                                        }
8427                                } else {
8428                                        while (it.hasNext()) {
8429                                                final long iax = it.aLong;
8430                                                final long ibx = it.bLong;
8431                                                float ox;
8432                                                ox = (ibx == 0 ? 0 : iax / ibx);
8433                                                oaf32data[it.oIndex] = ox;
8434                                        }
8435                                }
8436                        } else if (as < bs) {
8437                                if (it.isOutputDouble()) {
8438                                        while (it.hasNext()) {
8439                                                final double iax = it.aDouble;
8440                                                double ibx = it.bDouble;
8441                                                float ox;
8442                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
8443                                                oaf32data[it.oIndex] = ox;
8444                                                for (int j = 1; j < is; j++) {
8445                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8446                                                        ox = (float) (ibx == 0 ? 0 : iax / ibx);
8447                                                        oaf32data[it.oIndex + j] = ox;
8448                                                }
8449                                        }
8450                                } else {
8451                                        while (it.hasNext()) {
8452                                                final long iax = it.aLong;
8453                                                long ibx = it.bLong;
8454                                                float ox;
8455                                                ox = (ibx == 0 ? 0 : iax / ibx);
8456                                                oaf32data[it.oIndex] = ox;
8457                                                for (int j = 1; j < is; j++) {
8458                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8459                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8460                                                        oaf32data[it.oIndex + j] = ox;
8461                                                }
8462                                        }
8463                                }
8464                        } else if (as > bs) {
8465                                if (it.isOutputDouble()) {
8466                                        while (it.hasNext()) {
8467                                                double iax = it.aDouble;
8468                                                final double ibx = it.bDouble;
8469                                                float ox;
8470                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
8471                                                oaf32data[it.oIndex] = ox;
8472                                                for (int j = 1; j < is; j++) {
8473                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8474                                                        ox = (float) (ibx == 0 ? 0 : iax / ibx);
8475                                                        oaf32data[it.oIndex + j] = ox;
8476                                                }
8477                                        }
8478                                } else {
8479                                        while (it.hasNext()) {
8480                                                long iax = it.aLong;
8481                                                final long ibx = it.bLong;
8482                                                float ox;
8483                                                ox = (ibx == 0 ? 0 : iax / ibx);
8484                                                oaf32data[it.oIndex] = ox;
8485                                                for (int j = 1; j < is; j++) {
8486                                                        iax = da.getElementLongAbs(it.aIndex + j);
8487                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8488                                                        oaf32data[it.oIndex + j] = ox;
8489                                                }
8490                                        }
8491                                }
8492                        } else if (as == 1) {
8493                                if (it.isOutputDouble()) {
8494                                        while (it.hasNext()) {
8495                                                final double iax = it.aDouble;
8496                                                final double ibx = it.bDouble;
8497                                                float ox;
8498                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
8499                                                for (int j = 0; j < is; j++) {
8500                                                        oaf32data[it.oIndex + j] = ox;
8501                                                }
8502                                        }
8503                                } else {
8504                                        while (it.hasNext()) {
8505                                                final long iax = it.aLong;
8506                                                final long ibx = it.bLong;
8507                                                float ox;
8508                                                ox = (ibx == 0 ? 0 : iax / ibx);
8509                                                for (int j = 0; j < is; j++) {
8510                                                        oaf32data[it.oIndex + j] = ox;
8511                                                }
8512                                        }
8513                                }
8514                        } else {
8515                                if (it.isOutputDouble()) {
8516                                        while (it.hasNext()) {
8517                                                double iax = it.aDouble;
8518                                                double ibx = it.bDouble;
8519                                                float ox;
8520                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
8521                                                oaf32data[it.oIndex] = ox;
8522                                                for (int j = 1; j < is; j++) {
8523                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8524                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8525                                                        ox = (float) (ibx == 0 ? 0 : iax / ibx);
8526                                                        oaf32data[it.oIndex + j] = ox;
8527                                                }
8528                                        }
8529                                } else {
8530                                        while (it.hasNext()) {
8531                                                long iax = it.aLong;
8532                                                long ibx = it.bLong;
8533                                                float ox;
8534                                                ox = (ibx == 0 ? 0 : iax / ibx);
8535                                                oaf32data[it.oIndex] = ox;
8536                                                for (int j = 1; j < is; j++) {
8537                                                        iax = da.getElementLongAbs(it.aIndex + j);
8538                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8539                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8540                                                        oaf32data[it.oIndex + j] = ox;
8541                                                }
8542                                        }
8543                                }
8544                        }
8545                        break;
8546                case Dataset.ARRAYFLOAT64:
8547                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
8548                        if (is == 1) {
8549                                if (it.isOutputDouble()) {
8550                                        while (it.hasNext()) {
8551                                                final double iax = it.aDouble;
8552                                                final double ibx = it.bDouble;
8553                                                double ox;
8554                                                ox = (ibx == 0 ? 0 : iax / ibx);
8555                                                oaf64data[it.oIndex] = ox;
8556                                        }
8557                                } else {
8558                                        while (it.hasNext()) {
8559                                                final long iax = it.aLong;
8560                                                final long ibx = it.bLong;
8561                                                double ox;
8562                                                ox = (ibx == 0 ? 0 : iax / ibx);
8563                                                oaf64data[it.oIndex] = ox;
8564                                        }
8565                                }
8566                        } else if (as < bs) {
8567                                if (it.isOutputDouble()) {
8568                                        while (it.hasNext()) {
8569                                                final double iax = it.aDouble;
8570                                                double ibx = it.bDouble;
8571                                                double ox;
8572                                                ox = (ibx == 0 ? 0 : iax / ibx);
8573                                                oaf64data[it.oIndex] = ox;
8574                                                for (int j = 1; j < is; j++) {
8575                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8576                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8577                                                        oaf64data[it.oIndex + j] = ox;
8578                                                }
8579                                        }
8580                                } else {
8581                                        while (it.hasNext()) {
8582                                                final long iax = it.aLong;
8583                                                long ibx = it.bLong;
8584                                                double ox;
8585                                                ox = (ibx == 0 ? 0 : iax / ibx);
8586                                                oaf64data[it.oIndex] = ox;
8587                                                for (int j = 1; j < is; j++) {
8588                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8589                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8590                                                        oaf64data[it.oIndex + j] = ox;
8591                                                }
8592                                        }
8593                                }
8594                        } else if (as > bs) {
8595                                if (it.isOutputDouble()) {
8596                                        while (it.hasNext()) {
8597                                                double iax = it.aDouble;
8598                                                final double ibx = it.bDouble;
8599                                                double ox;
8600                                                ox = (ibx == 0 ? 0 : iax / ibx);
8601                                                oaf64data[it.oIndex] = ox;
8602                                                for (int j = 1; j < is; j++) {
8603                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8604                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8605                                                        oaf64data[it.oIndex + j] = ox;
8606                                                }
8607                                        }
8608                                } else {
8609                                        while (it.hasNext()) {
8610                                                long iax = it.aLong;
8611                                                final long ibx = it.bLong;
8612                                                double ox;
8613                                                ox = (ibx == 0 ? 0 : iax / ibx);
8614                                                oaf64data[it.oIndex] = ox;
8615                                                for (int j = 1; j < is; j++) {
8616                                                        iax = da.getElementLongAbs(it.aIndex + j);
8617                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8618                                                        oaf64data[it.oIndex + j] = ox;
8619                                                }
8620                                        }
8621                                }
8622                        } else if (as == 1) {
8623                                if (it.isOutputDouble()) {
8624                                        while (it.hasNext()) {
8625                                                final double iax = it.aDouble;
8626                                                final double ibx = it.bDouble;
8627                                                double ox;
8628                                                ox = (ibx == 0 ? 0 : iax / ibx);
8629                                                for (int j = 0; j < is; j++) {
8630                                                        oaf64data[it.oIndex + j] = ox;
8631                                                }
8632                                        }
8633                                } else {
8634                                        while (it.hasNext()) {
8635                                                final long iax = it.aLong;
8636                                                final long ibx = it.bLong;
8637                                                double ox;
8638                                                ox = (ibx == 0 ? 0 : iax / ibx);
8639                                                for (int j = 0; j < is; j++) {
8640                                                        oaf64data[it.oIndex + j] = ox;
8641                                                }
8642                                        }
8643                                }
8644                        } else {
8645                                if (it.isOutputDouble()) {
8646                                        while (it.hasNext()) {
8647                                                double iax = it.aDouble;
8648                                                double ibx = it.bDouble;
8649                                                double ox;
8650                                                ox = (ibx == 0 ? 0 : iax / ibx);
8651                                                oaf64data[it.oIndex] = ox;
8652                                                for (int j = 1; j < is; j++) {
8653                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8654                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8655                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8656                                                        oaf64data[it.oIndex + j] = ox;
8657                                                }
8658                                        }
8659                                } else {
8660                                        while (it.hasNext()) {
8661                                                long iax = it.aLong;
8662                                                long ibx = it.bLong;
8663                                                double ox;
8664                                                ox = (ibx == 0 ? 0 : iax / ibx);
8665                                                oaf64data[it.oIndex] = ox;
8666                                                for (int j = 1; j < is; j++) {
8667                                                        iax = da.getElementLongAbs(it.aIndex + j);
8668                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8669                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8670                                                        oaf64data[it.oIndex + j] = ox;
8671                                                }
8672                                        }
8673                                }
8674                        }
8675                        break;
8676                case Dataset.COMPLEX64:
8677                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
8678                        if (!da.isComplex()) {
8679                                if (it.isOutputDouble()) {
8680                                        final double iay = 0;
8681                                        if (db.isComplex()) {
8682                                                while (it.hasNext()) {
8683                                                        final double iax = it.aDouble;
8684                                                        final double ibx = it.bDouble;
8685                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
8686                                                        float ox;
8687                                                        float oy;
8688                                                        float q;
8689                                                        float den;
8690                                                        if (ibx == 0 && iby == 0) {
8691                                                                ox = 0;
8692                                                                oy = 0;
8693                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
8694                                                                q = (float) (ibx / iby);
8695                                                                den = (float) (ibx * q + iby);
8696                                                                ox = (float) ((iax * q + iay) / den);
8697                                                                oy = (float) ((iay * q - ibx) / den);
8698                                                        } else {
8699                                                                q = (float) (iby / ibx);
8700                                                                den = (float) (iby * q + ibx);
8701                                                                ox = (float) ((iay * q + iax) / den);
8702                                                                oy = (float) ((iay - iax * q) / den);
8703                                                        }
8704                                                        oc64data[it.oIndex] = ox;
8705                                                        oc64data[it.oIndex + 1] = oy;
8706                                                }
8707                                        } else {
8708                                                while (it.hasNext()) {
8709                                                        final double iax = it.aDouble;
8710                                                        final double ibx = it.bDouble;
8711                                                        final double iby = 0;
8712                                                        float ox;
8713                                                        float oy;
8714                                                        float q;
8715                                                        float den;
8716                                                        if (ibx == 0 && iby == 0) {
8717                                                                ox = 0;
8718                                                                oy = 0;
8719                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
8720                                                                q = (float) (ibx / iby);
8721                                                                den = (float) (ibx * q + iby);
8722                                                                ox = (float) ((iax * q + iay) / den);
8723                                                                oy = (float) ((iay * q - ibx) / den);
8724                                                        } else {
8725                                                                q = (float) (iby / ibx);
8726                                                                den = (float) (iby * q + ibx);
8727                                                                ox = (float) ((iay * q + iax) / den);
8728                                                                oy = (float) ((iay - iax * q) / den);
8729                                                        }
8730                                                        oc64data[it.oIndex] = ox;
8731                                                        oc64data[it.oIndex + 1] = oy;
8732                                                }
8733                                        }
8734                                } else {
8735                                        final long iay = 0;
8736                                        while (it.hasNext()) {
8737                                                final long iax = it.aLong;
8738                                                final long ibx = it.bLong;
8739                                                final long iby = 0;
8740                                                float ox;
8741                                                float oy;
8742                                                float q;
8743                                                float den;
8744                                                if (ibx == 0 && iby == 0) {
8745                                                        ox = 0;
8746                                                        oy = 0;
8747                                                } else if (Math.abs(ibx) < Math.abs(iby)) {
8748                                                        q = (float) (ibx / iby);
8749                                                        den = (float) (ibx * q + iby);
8750                                                        ox = (float) ((iax * q + iay) / den);
8751                                                        oy = (float) ((iay * q - ibx) / den);
8752                                                } else {
8753                                                        q = (float) (iby / ibx);
8754                                                        den = (float) (iby * q + ibx);
8755                                                        ox = (float) ((iay * q + iax) / den);
8756                                                        oy = (float) ((iay - iax * q) / den);
8757                                                }
8758                                                oc64data[it.oIndex] = ox;
8759                                                oc64data[it.oIndex + 1] = oy;
8760                                        }
8761                                }
8762                        } else if (!db.isComplex()) {
8763                                final double iby = 0;
8764                                while (it.hasNext()) {
8765                                        final double iax = it.aDouble;
8766                                        final double ibx = it.bDouble;
8767                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
8768                                        float ox;
8769                                        float oy;
8770                                        float q;
8771                                        float den;
8772                                        if (ibx == 0 && iby == 0) {
8773                                                ox = 0;
8774                                                oy = 0;
8775                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
8776                                                q = (float) (ibx / iby);
8777                                                den = (float) (ibx * q + iby);
8778                                                ox = (float) ((iax * q + iay) / den);
8779                                                oy = (float) ((iay * q - ibx) / den);
8780                                        } else {
8781                                                q = (float) (iby / ibx);
8782                                                den = (float) (iby * q + ibx);
8783                                                ox = (float) ((iay * q + iax) / den);
8784                                                oy = (float) ((iay - iax * q) / den);
8785                                        }
8786                                        oc64data[it.oIndex] = ox;
8787                                        oc64data[it.oIndex + 1] = oy;
8788                                }
8789                        } else {
8790                                while (it.hasNext()) {
8791                                        final double iax = it.aDouble;
8792                                        final double ibx = it.bDouble;
8793                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
8794                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
8795                                        float ox;
8796                                        float oy;
8797                                        float q;
8798                                        float den;
8799                                        if (ibx == 0 && iby == 0) {
8800                                                ox = 0;
8801                                                oy = 0;
8802                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
8803                                                q = (float) (ibx / iby);
8804                                                den = (float) (ibx * q + iby);
8805                                                ox = (float) ((iax * q + iay) / den);
8806                                                oy = (float) ((iay * q - ibx) / den);
8807                                        } else {
8808                                                q = (float) (iby / ibx);
8809                                                den = (float) (iby * q + ibx);
8810                                                ox = (float) ((iay * q + iax) / den);
8811                                                oy = (float) ((iay - iax * q) / den);
8812                                        }
8813                                        oc64data[it.oIndex] = ox;
8814                                        oc64data[it.oIndex + 1] = oy;
8815                                }
8816                        }
8817                        break;
8818                case Dataset.COMPLEX128:
8819                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
8820                        if (!da.isComplex()) {
8821                                if (it.isOutputDouble()) {
8822                                        final double iay = 0;
8823                                        if (db.isComplex()) {
8824                                                while (it.hasNext()) {
8825                                                        final double iax = it.aDouble;
8826                                                        final double ibx = it.bDouble;
8827                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
8828                                                        double ox;
8829                                                        double oy;
8830                                                        double q;
8831                                                        double den;
8832                                                        if (ibx == 0 && iby == 0) {
8833                                                                ox = 0;
8834                                                                oy = 0;
8835                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
8836                                                                q = (ibx / iby);
8837                                                                den = (ibx * q + iby);
8838                                                                ox = ((iax * q + iay) / den);
8839                                                                oy = ((iay * q - ibx) / den);
8840                                                        } else {
8841                                                                q = (iby / ibx);
8842                                                                den = (iby * q + ibx);
8843                                                                ox = ((iay * q + iax) / den);
8844                                                                oy = ((iay - iax * q) / den);
8845                                                        }
8846                                                        oc128data[it.oIndex] = ox;
8847                                                        oc128data[it.oIndex + 1] = oy;
8848                                                }
8849                                        } else {
8850                                                while (it.hasNext()) {
8851                                                        final double iax = it.aDouble;
8852                                                        final double ibx = it.bDouble;
8853                                                        final double iby = 0;
8854                                                        double ox;
8855                                                        double oy;
8856                                                        double q;
8857                                                        double den;
8858                                                        if (ibx == 0 && iby == 0) {
8859                                                                ox = 0;
8860                                                                oy = 0;
8861                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
8862                                                                q = (ibx / iby);
8863                                                                den = (ibx * q + iby);
8864                                                                ox = ((iax * q + iay) / den);
8865                                                                oy = ((iay * q - ibx) / den);
8866                                                        } else {
8867                                                                q = (iby / ibx);
8868                                                                den = (iby * q + ibx);
8869                                                                ox = ((iay * q + iax) / den);
8870                                                                oy = ((iay - iax * q) / den);
8871                                                        }
8872                                                        oc128data[it.oIndex] = ox;
8873                                                        oc128data[it.oIndex + 1] = oy;
8874                                                }
8875                                        }
8876                                } else {
8877                                        final long iay = 0;
8878                                        while (it.hasNext()) {
8879                                                final long iax = it.aLong;
8880                                                final long ibx = it.bLong;
8881                                                final long iby = 0;
8882                                                double ox;
8883                                                double oy;
8884                                                double q;
8885                                                double den;
8886                                                if (ibx == 0 && iby == 0) {
8887                                                        ox = 0;
8888                                                        oy = 0;
8889                                                } else if (Math.abs(ibx) < Math.abs(iby)) {
8890                                                        q = (ibx / iby);
8891                                                        den = (ibx * q + iby);
8892                                                        ox = ((iax * q + iay) / den);
8893                                                        oy = ((iay * q - ibx) / den);
8894                                                } else {
8895                                                        q = (iby / ibx);
8896                                                        den = (iby * q + ibx);
8897                                                        ox = ((iay * q + iax) / den);
8898                                                        oy = ((iay - iax * q) / den);
8899                                                }
8900                                                oc128data[it.oIndex] = ox;
8901                                                oc128data[it.oIndex + 1] = oy;
8902                                        }
8903                                }
8904                        } else if (!db.isComplex()) {
8905                                final double iby = 0;
8906                                while (it.hasNext()) {
8907                                        final double iax = it.aDouble;
8908                                        final double ibx = it.bDouble;
8909                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
8910                                        double ox;
8911                                        double oy;
8912                                        double q;
8913                                        double den;
8914                                        if (ibx == 0 && iby == 0) {
8915                                                ox = 0;
8916                                                oy = 0;
8917                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
8918                                                q = (ibx / iby);
8919                                                den = (ibx * q + iby);
8920                                                ox = ((iax * q + iay) / den);
8921                                                oy = ((iay * q - ibx) / den);
8922                                        } else {
8923                                                q = (iby / ibx);
8924                                                den = (iby * q + ibx);
8925                                                ox = ((iay * q + iax) / den);
8926                                                oy = ((iay - iax * q) / den);
8927                                        }
8928                                        oc128data[it.oIndex] = ox;
8929                                        oc128data[it.oIndex + 1] = oy;
8930                                }
8931                        } else {
8932                                while (it.hasNext()) {
8933                                        final double iax = it.aDouble;
8934                                        final double ibx = it.bDouble;
8935                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
8936                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
8937                                        double ox;
8938                                        double oy;
8939                                        double q;
8940                                        double den;
8941                                        if (ibx == 0 && iby == 0) {
8942                                                ox = 0;
8943                                                oy = 0;
8944                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
8945                                                q = (ibx / iby);
8946                                                den = (ibx * q + iby);
8947                                                ox = ((iax * q + iay) / den);
8948                                                oy = ((iay * q - ibx) / den);
8949                                        } else {
8950                                                q = (iby / ibx);
8951                                                den = (iby * q + ibx);
8952                                                ox = ((iay * q + iax) / den);
8953                                                oy = ((iay - iax * q) / den);
8954                                        }
8955                                        oc128data[it.oIndex] = ox;
8956                                        oc128data[it.oIndex + 1] = oy;
8957                                }
8958                        }
8959                        break;
8960                default:
8961                        throw new IllegalArgumentException("dividez supports integer, compound integer, real, compound real, complex datasets only");
8962                }
8963
8964                addBinaryOperatorName(da, db, result, "/");
8965                return result;
8966        }
8967
8968        /**
8969         * divideTowardsFloor operator
8970         * @param a
8971         * @param b
8972         * @return {@code a / b}, division of a by b but rounded towards negative infinity
8973         */
8974        public static Dataset divideTowardsFloor(final Object a, final Object b) {
8975                return divideTowardsFloor(a, b, null);
8976        }
8977
8978        /**
8979         * divideTowardsFloor operator
8980         * @param a
8981         * @param b
8982         * @param o output can be null - in which case, a new dataset is created
8983         * @return {@code a / b}, division of a by b but rounded towards negative infinity
8984         */
8985        public static Dataset divideTowardsFloor(final Object a, final Object b, final Dataset o) {
8986                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
8987                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
8988                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
8989                final Dataset result = it.getOutput();
8990                if (!result.isComplex()) {
8991                        boolean change = false;
8992                        if (da.isComplex()) {
8993                                da = da.getRealView();
8994                                change = true;
8995                        }
8996                        if (db.isComplex()) {
8997                                db = db.getRealView();
8998                                change = true;
8999                        }
9000                        if (change) {
9001                                it = BroadcastIterator.createIterator(da, db, result, true);
9002                        }
9003                }
9004                final int is = result.getElementsPerItem();
9005                final int as = da.getElementsPerItem();
9006                final int bs = db.getElementsPerItem();
9007                final int dt = result.getDType();
9008
9009                switch(dt) {
9010                case Dataset.INT8:
9011                        final byte[] oi8data = ((ByteDataset) result).getData();
9012                        if (it.isOutputDouble()) {
9013                                while (it.hasNext()) {
9014                                        final double iax = it.aDouble;
9015                                        final double ibx = it.bDouble;
9016                                        byte ox;
9017                                        if (ibx == 0) {
9018                                                ox = 0;
9019                                        } else {
9020                                                ox = (byte) toLong(iax / ibx);
9021                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9022                                                        ox--;
9023                                                }
9024                                        }
9025                                        oi8data[it.oIndex] = ox;
9026                                }
9027                        } else {
9028                                while (it.hasNext()) {
9029                                        final long iax = it.aLong;
9030                                        final long ibx = it.bLong;
9031                                        byte ox;
9032                                        if (ibx == 0) {
9033                                                ox = 0;
9034                                        } else {
9035                                                ox = (byte) (iax / ibx);
9036                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9037                                                        ox--;
9038                                                }
9039                                        }
9040                                        oi8data[it.oIndex] = ox;
9041                                }
9042                        }
9043                        break;
9044                case Dataset.INT16:
9045                        final short[] oi16data = ((ShortDataset) result).getData();
9046                        if (it.isOutputDouble()) {
9047                                while (it.hasNext()) {
9048                                        final double iax = it.aDouble;
9049                                        final double ibx = it.bDouble;
9050                                        short ox;
9051                                        if (ibx == 0) {
9052                                                ox = 0;
9053                                        } else {
9054                                                ox = (short) toLong(iax / ibx);
9055                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9056                                                        ox--;
9057                                                }
9058                                        }
9059                                        oi16data[it.oIndex] = ox;
9060                                }
9061                        } else {
9062                                while (it.hasNext()) {
9063                                        final long iax = it.aLong;
9064                                        final long ibx = it.bLong;
9065                                        short ox;
9066                                        if (ibx == 0) {
9067                                                ox = 0;
9068                                        } else {
9069                                                ox = (short) (iax / ibx);
9070                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9071                                                        ox--;
9072                                                }
9073                                        }
9074                                        oi16data[it.oIndex] = ox;
9075                                }
9076                        }
9077                        break;
9078                case Dataset.INT64:
9079                        final long[] oi64data = ((LongDataset) result).getData();
9080                        if (it.isOutputDouble()) {
9081                                while (it.hasNext()) {
9082                                        final double iax = it.aDouble;
9083                                        final double ibx = it.bDouble;
9084                                        long ox;
9085                                        if (ibx == 0) {
9086                                                ox = 0;
9087                                        } else {
9088                                                ox = toLong(iax / ibx);
9089                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9090                                                        ox--;
9091                                                }
9092                                        }
9093                                        oi64data[it.oIndex] = ox;
9094                                }
9095                        } else {
9096                                while (it.hasNext()) {
9097                                        final long iax = it.aLong;
9098                                        final long ibx = it.bLong;
9099                                        long ox;
9100                                        if (ibx == 0) {
9101                                                ox = 0;
9102                                        } else {
9103                                                ox = (iax / ibx);
9104                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9105                                                        ox--;
9106                                                }
9107                                        }
9108                                        oi64data[it.oIndex] = ox;
9109                                }
9110                        }
9111                        break;
9112                case Dataset.INT32:
9113                        final int[] oi32data = ((IntegerDataset) result).getData();
9114                        if (it.isOutputDouble()) {
9115                                while (it.hasNext()) {
9116                                        final double iax = it.aDouble;
9117                                        final double ibx = it.bDouble;
9118                                        int ox;
9119                                        if (ibx == 0) {
9120                                                ox = 0;
9121                                        } else {
9122                                                ox = (int) toLong(iax / ibx);
9123                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9124                                                        ox--;
9125                                                }
9126                                        }
9127                                        oi32data[it.oIndex] = ox;
9128                                }
9129                        } else {
9130                                while (it.hasNext()) {
9131                                        final long iax = it.aLong;
9132                                        final long ibx = it.bLong;
9133                                        int ox;
9134                                        if (ibx == 0) {
9135                                                ox = 0;
9136                                        } else {
9137                                                ox = (int) (iax / ibx);
9138                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9139                                                        ox--;
9140                                                }
9141                                        }
9142                                        oi32data[it.oIndex] = ox;
9143                                }
9144                        }
9145                        break;
9146                case Dataset.ARRAYINT8:
9147                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
9148                        if (is == 1) {
9149                                if (it.isOutputDouble()) {
9150                                        while (it.hasNext()) {
9151                                                final double iax = it.aDouble;
9152                                                final double ibx = it.bDouble;
9153                                                byte ox;
9154                                                if (ibx == 0) {
9155                                                        ox = 0;
9156                                                } else {
9157                                                        ox = (byte) toLong(iax / ibx);
9158                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9159                                                                ox--;
9160                                                        }
9161                                                }
9162                                                oai8data[it.oIndex] = ox;
9163                                        }
9164                                } else {
9165                                        while (it.hasNext()) {
9166                                                final long iax = it.aLong;
9167                                                final long ibx = it.bLong;
9168                                                byte ox;
9169                                                if (ibx == 0) {
9170                                                        ox = 0;
9171                                                } else {
9172                                                        ox = (byte) (iax / ibx);
9173                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9174                                                                ox--;
9175                                                        }
9176                                                }
9177                                                oai8data[it.oIndex] = ox;
9178                                        }
9179                                }
9180                        } else if (as < bs) {
9181                                if (it.isOutputDouble()) {
9182                                        while (it.hasNext()) {
9183                                                final double iax = it.aDouble;
9184                                                double ibx = it.bDouble;
9185                                                byte ox;
9186                                                if (ibx == 0) {
9187                                                        ox = 0;
9188                                                } else {
9189                                                        ox = (byte) toLong(iax / ibx);
9190                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9191                                                                ox--;
9192                                                        }
9193                                                }
9194                                                oai8data[it.oIndex] = ox;
9195                                                for (int j = 1; j < is; j++) {
9196                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9197                                                        if (ibx == 0) {
9198                                                                ox = 0;
9199                                                        } else {
9200                                                                ox = (byte) toLong(iax / ibx);
9201                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9202                                                                        ox--;
9203                                                                }
9204                                                        }
9205                                                        oai8data[it.oIndex + j] = ox;
9206                                                }
9207                                        }
9208                                } else {
9209                                        while (it.hasNext()) {
9210                                                final long iax = it.aLong;
9211                                                long ibx = it.bLong;
9212                                                byte ox;
9213                                                if (ibx == 0) {
9214                                                        ox = 0;
9215                                                } else {
9216                                                        ox = (byte) (iax / ibx);
9217                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9218                                                                ox--;
9219                                                        }
9220                                                }
9221                                                oai8data[it.oIndex] = ox;
9222                                                for (int j = 1; j < is; j++) {
9223                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9224                                                        if (ibx == 0) {
9225                                                                ox = 0;
9226                                                        } else {
9227                                                                ox = (byte) (iax / ibx);
9228                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9229                                                                        ox--;
9230                                                                }
9231                                                        }
9232                                                        oai8data[it.oIndex + j] = ox;
9233                                                }
9234                                        }
9235                                }
9236                        } else if (as > bs) {
9237                                if (it.isOutputDouble()) {
9238                                        while (it.hasNext()) {
9239                                                double iax = it.aDouble;
9240                                                final double ibx = it.bDouble;
9241                                                byte ox;
9242                                                if (ibx == 0) {
9243                                                        ox = 0;
9244                                                } else {
9245                                                        ox = (byte) toLong(iax / ibx);
9246                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9247                                                                ox--;
9248                                                        }
9249                                                }
9250                                                oai8data[it.oIndex] = ox;
9251                                                for (int j = 1; j < is; j++) {
9252                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9253                                                        if (ibx == 0) {
9254                                                                ox = 0;
9255                                                        } else {
9256                                                                ox = (byte) toLong(iax / ibx);
9257                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9258                                                                        ox--;
9259                                                                }
9260                                                        }
9261                                                        oai8data[it.oIndex + j] = ox;
9262                                                }
9263                                        }
9264                                } else {
9265                                        while (it.hasNext()) {
9266                                                long iax = it.aLong;
9267                                                final long ibx = it.bLong;
9268                                                byte ox;
9269                                                if (ibx == 0) {
9270                                                        ox = 0;
9271                                                } else {
9272                                                        ox = (byte) (iax / ibx);
9273                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9274                                                                ox--;
9275                                                        }
9276                                                }
9277                                                oai8data[it.oIndex] = ox;
9278                                                for (int j = 1; j < is; j++) {
9279                                                        iax = da.getElementLongAbs(it.aIndex + j);
9280                                                        if (ibx == 0) {
9281                                                                ox = 0;
9282                                                        } else {
9283                                                                ox = (byte) (iax / ibx);
9284                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9285                                                                        ox--;
9286                                                                }
9287                                                        }
9288                                                        oai8data[it.oIndex + j] = ox;
9289                                                }
9290                                        }
9291                                }
9292                        } else if (as == 1) {
9293                                if (it.isOutputDouble()) {
9294                                        while (it.hasNext()) {
9295                                                final double iax = it.aDouble;
9296                                                final double ibx = it.bDouble;
9297                                                byte ox;
9298                                                if (ibx == 0) {
9299                                                        ox = 0;
9300                                                } else {
9301                                                        ox = (byte) toLong(iax / ibx);
9302                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9303                                                                ox--;
9304                                                        }
9305                                                }
9306                                                for (int j = 0; j < is; j++) {
9307                                                        oai8data[it.oIndex + j] = ox;
9308                                                }
9309                                        }
9310                                } else {
9311                                        while (it.hasNext()) {
9312                                                final long iax = it.aLong;
9313                                                final long ibx = it.bLong;
9314                                                byte ox;
9315                                                if (ibx == 0) {
9316                                                        ox = 0;
9317                                                } else {
9318                                                        ox = (byte) (iax / ibx);
9319                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9320                                                                ox--;
9321                                                        }
9322                                                }
9323                                                for (int j = 0; j < is; j++) {
9324                                                        oai8data[it.oIndex + j] = ox;
9325                                                }
9326                                        }
9327                                }
9328                        } else {
9329                                if (it.isOutputDouble()) {
9330                                        while (it.hasNext()) {
9331                                                double iax = it.aDouble;
9332                                                double ibx = it.bDouble;
9333                                                byte ox;
9334                                                if (ibx == 0) {
9335                                                        ox = 0;
9336                                                } else {
9337                                                        ox = (byte) toLong(iax / ibx);
9338                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9339                                                                ox--;
9340                                                        }
9341                                                }
9342                                                oai8data[it.oIndex] = ox;
9343                                                for (int j = 1; j < is; j++) {
9344                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9345                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9346                                                        if (ibx == 0) {
9347                                                                ox = 0;
9348                                                        } else {
9349                                                                ox = (byte) toLong(iax / ibx);
9350                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9351                                                                        ox--;
9352                                                                }
9353                                                        }
9354                                                        oai8data[it.oIndex + j] = ox;
9355                                                }
9356                                        }
9357                                } else {
9358                                        while (it.hasNext()) {
9359                                                long iax = it.aLong;
9360                                                long ibx = it.bLong;
9361                                                byte ox;
9362                                                if (ibx == 0) {
9363                                                        ox = 0;
9364                                                } else {
9365                                                        ox = (byte) (iax / ibx);
9366                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9367                                                                ox--;
9368                                                        }
9369                                                }
9370                                                oai8data[it.oIndex] = ox;
9371                                                for (int j = 1; j < is; j++) {
9372                                                        iax = da.getElementLongAbs(it.aIndex + j);
9373                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9374                                                        if (ibx == 0) {
9375                                                                ox = 0;
9376                                                        } else {
9377                                                                ox = (byte) (iax / ibx);
9378                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9379                                                                        ox--;
9380                                                                }
9381                                                        }
9382                                                        oai8data[it.oIndex + j] = ox;
9383                                                }
9384                                        }
9385                                }
9386                        }
9387                        break;
9388                case Dataset.ARRAYINT16:
9389                        final short[] oai16data = ((CompoundShortDataset) result).getData();
9390                        if (is == 1) {
9391                                if (it.isOutputDouble()) {
9392                                        while (it.hasNext()) {
9393                                                final double iax = it.aDouble;
9394                                                final double ibx = it.bDouble;
9395                                                short ox;
9396                                                if (ibx == 0) {
9397                                                        ox = 0;
9398                                                } else {
9399                                                        ox = (short) toLong(iax / ibx);
9400                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9401                                                                ox--;
9402                                                        }
9403                                                }
9404                                                oai16data[it.oIndex] = ox;
9405                                        }
9406                                } else {
9407                                        while (it.hasNext()) {
9408                                                final long iax = it.aLong;
9409                                                final long ibx = it.bLong;
9410                                                short ox;
9411                                                if (ibx == 0) {
9412                                                        ox = 0;
9413                                                } else {
9414                                                        ox = (short) (iax / ibx);
9415                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9416                                                                ox--;
9417                                                        }
9418                                                }
9419                                                oai16data[it.oIndex] = ox;
9420                                        }
9421                                }
9422                        } else if (as < bs) {
9423                                if (it.isOutputDouble()) {
9424                                        while (it.hasNext()) {
9425                                                final double iax = it.aDouble;
9426                                                double ibx = it.bDouble;
9427                                                short ox;
9428                                                if (ibx == 0) {
9429                                                        ox = 0;
9430                                                } else {
9431                                                        ox = (short) toLong(iax / ibx);
9432                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9433                                                                ox--;
9434                                                        }
9435                                                }
9436                                                oai16data[it.oIndex] = ox;
9437                                                for (int j = 1; j < is; j++) {
9438                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9439                                                        if (ibx == 0) {
9440                                                                ox = 0;
9441                                                        } else {
9442                                                                ox = (short) toLong(iax / ibx);
9443                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9444                                                                        ox--;
9445                                                                }
9446                                                        }
9447                                                        oai16data[it.oIndex + j] = ox;
9448                                                }
9449                                        }
9450                                } else {
9451                                        while (it.hasNext()) {
9452                                                final long iax = it.aLong;
9453                                                long ibx = it.bLong;
9454                                                short ox;
9455                                                if (ibx == 0) {
9456                                                        ox = 0;
9457                                                } else {
9458                                                        ox = (short) (iax / ibx);
9459                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9460                                                                ox--;
9461                                                        }
9462                                                }
9463                                                oai16data[it.oIndex] = ox;
9464                                                for (int j = 1; j < is; j++) {
9465                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9466                                                        if (ibx == 0) {
9467                                                                ox = 0;
9468                                                        } else {
9469                                                                ox = (short) (iax / ibx);
9470                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9471                                                                        ox--;
9472                                                                }
9473                                                        }
9474                                                        oai16data[it.oIndex + j] = ox;
9475                                                }
9476                                        }
9477                                }
9478                        } else if (as > bs) {
9479                                if (it.isOutputDouble()) {
9480                                        while (it.hasNext()) {
9481                                                double iax = it.aDouble;
9482                                                final double ibx = it.bDouble;
9483                                                short ox;
9484                                                if (ibx == 0) {
9485                                                        ox = 0;
9486                                                } else {
9487                                                        ox = (short) toLong(iax / ibx);
9488                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9489                                                                ox--;
9490                                                        }
9491                                                }
9492                                                oai16data[it.oIndex] = ox;
9493                                                for (int j = 1; j < is; j++) {
9494                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9495                                                        if (ibx == 0) {
9496                                                                ox = 0;
9497                                                        } else {
9498                                                                ox = (short) toLong(iax / ibx);
9499                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9500                                                                        ox--;
9501                                                                }
9502                                                        }
9503                                                        oai16data[it.oIndex + j] = ox;
9504                                                }
9505                                        }
9506                                } else {
9507                                        while (it.hasNext()) {
9508                                                long iax = it.aLong;
9509                                                final long ibx = it.bLong;
9510                                                short ox;
9511                                                if (ibx == 0) {
9512                                                        ox = 0;
9513                                                } else {
9514                                                        ox = (short) (iax / ibx);
9515                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9516                                                                ox--;
9517                                                        }
9518                                                }
9519                                                oai16data[it.oIndex] = ox;
9520                                                for (int j = 1; j < is; j++) {
9521                                                        iax = da.getElementLongAbs(it.aIndex + j);
9522                                                        if (ibx == 0) {
9523                                                                ox = 0;
9524                                                        } else {
9525                                                                ox = (short) (iax / ibx);
9526                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9527                                                                        ox--;
9528                                                                }
9529                                                        }
9530                                                        oai16data[it.oIndex + j] = ox;
9531                                                }
9532                                        }
9533                                }
9534                        } else if (as == 1) {
9535                                if (it.isOutputDouble()) {
9536                                        while (it.hasNext()) {
9537                                                final double iax = it.aDouble;
9538                                                final double ibx = it.bDouble;
9539                                                short ox;
9540                                                if (ibx == 0) {
9541                                                        ox = 0;
9542                                                } else {
9543                                                        ox = (short) toLong(iax / ibx);
9544                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9545                                                                ox--;
9546                                                        }
9547                                                }
9548                                                for (int j = 0; j < is; j++) {
9549                                                        oai16data[it.oIndex + j] = ox;
9550                                                }
9551                                        }
9552                                } else {
9553                                        while (it.hasNext()) {
9554                                                final long iax = it.aLong;
9555                                                final long ibx = it.bLong;
9556                                                short ox;
9557                                                if (ibx == 0) {
9558                                                        ox = 0;
9559                                                } else {
9560                                                        ox = (short) (iax / ibx);
9561                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9562                                                                ox--;
9563                                                        }
9564                                                }
9565                                                for (int j = 0; j < is; j++) {
9566                                                        oai16data[it.oIndex + j] = ox;
9567                                                }
9568                                        }
9569                                }
9570                        } else {
9571                                if (it.isOutputDouble()) {
9572                                        while (it.hasNext()) {
9573                                                double iax = it.aDouble;
9574                                                double ibx = it.bDouble;
9575                                                short ox;
9576                                                if (ibx == 0) {
9577                                                        ox = 0;
9578                                                } else {
9579                                                        ox = (short) toLong(iax / ibx);
9580                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9581                                                                ox--;
9582                                                        }
9583                                                }
9584                                                oai16data[it.oIndex] = ox;
9585                                                for (int j = 1; j < is; j++) {
9586                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9587                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9588                                                        if (ibx == 0) {
9589                                                                ox = 0;
9590                                                        } else {
9591                                                                ox = (short) toLong(iax / ibx);
9592                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9593                                                                        ox--;
9594                                                                }
9595                                                        }
9596                                                        oai16data[it.oIndex + j] = ox;
9597                                                }
9598                                        }
9599                                } else {
9600                                        while (it.hasNext()) {
9601                                                long iax = it.aLong;
9602                                                long ibx = it.bLong;
9603                                                short ox;
9604                                                if (ibx == 0) {
9605                                                        ox = 0;
9606                                                } else {
9607                                                        ox = (short) (iax / ibx);
9608                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9609                                                                ox--;
9610                                                        }
9611                                                }
9612                                                oai16data[it.oIndex] = ox;
9613                                                for (int j = 1; j < is; j++) {
9614                                                        iax = da.getElementLongAbs(it.aIndex + j);
9615                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9616                                                        if (ibx == 0) {
9617                                                                ox = 0;
9618                                                        } else {
9619                                                                ox = (short) (iax / ibx);
9620                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9621                                                                        ox--;
9622                                                                }
9623                                                        }
9624                                                        oai16data[it.oIndex + j] = ox;
9625                                                }
9626                                        }
9627                                }
9628                        }
9629                        break;
9630                case Dataset.ARRAYINT64:
9631                        final long[] oai64data = ((CompoundLongDataset) result).getData();
9632                        if (is == 1) {
9633                                if (it.isOutputDouble()) {
9634                                        while (it.hasNext()) {
9635                                                final double iax = it.aDouble;
9636                                                final double ibx = it.bDouble;
9637                                                long ox;
9638                                                if (ibx == 0) {
9639                                                        ox = 0;
9640                                                } else {
9641                                                        ox = toLong(iax / ibx);
9642                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9643                                                                ox--;
9644                                                        }
9645                                                }
9646                                                oai64data[it.oIndex] = ox;
9647                                        }
9648                                } else {
9649                                        while (it.hasNext()) {
9650                                                final long iax = it.aLong;
9651                                                final long ibx = it.bLong;
9652                                                long ox;
9653                                                if (ibx == 0) {
9654                                                        ox = 0;
9655                                                } else {
9656                                                        ox = (iax / ibx);
9657                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9658                                                                ox--;
9659                                                        }
9660                                                }
9661                                                oai64data[it.oIndex] = ox;
9662                                        }
9663                                }
9664                        } else if (as < bs) {
9665                                if (it.isOutputDouble()) {
9666                                        while (it.hasNext()) {
9667                                                final double iax = it.aDouble;
9668                                                double ibx = it.bDouble;
9669                                                long ox;
9670                                                if (ibx == 0) {
9671                                                        ox = 0;
9672                                                } else {
9673                                                        ox = toLong(iax / ibx);
9674                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9675                                                                ox--;
9676                                                        }
9677                                                }
9678                                                oai64data[it.oIndex] = ox;
9679                                                for (int j = 1; j < is; j++) {
9680                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9681                                                        if (ibx == 0) {
9682                                                                ox = 0;
9683                                                        } else {
9684                                                                ox = toLong(iax / ibx);
9685                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9686                                                                        ox--;
9687                                                                }
9688                                                        }
9689                                                        oai64data[it.oIndex + j] = ox;
9690                                                }
9691                                        }
9692                                } else {
9693                                        while (it.hasNext()) {
9694                                                final long iax = it.aLong;
9695                                                long ibx = it.bLong;
9696                                                long ox;
9697                                                if (ibx == 0) {
9698                                                        ox = 0;
9699                                                } else {
9700                                                        ox = (iax / ibx);
9701                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9702                                                                ox--;
9703                                                        }
9704                                                }
9705                                                oai64data[it.oIndex] = ox;
9706                                                for (int j = 1; j < is; j++) {
9707                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9708                                                        if (ibx == 0) {
9709                                                                ox = 0;
9710                                                        } else {
9711                                                                ox = (iax / ibx);
9712                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9713                                                                        ox--;
9714                                                                }
9715                                                        }
9716                                                        oai64data[it.oIndex + j] = ox;
9717                                                }
9718                                        }
9719                                }
9720                        } else if (as > bs) {
9721                                if (it.isOutputDouble()) {
9722                                        while (it.hasNext()) {
9723                                                double iax = it.aDouble;
9724                                                final double ibx = it.bDouble;
9725                                                long ox;
9726                                                if (ibx == 0) {
9727                                                        ox = 0;
9728                                                } else {
9729                                                        ox = toLong(iax / ibx);
9730                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9731                                                                ox--;
9732                                                        }
9733                                                }
9734                                                oai64data[it.oIndex] = ox;
9735                                                for (int j = 1; j < is; j++) {
9736                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9737                                                        if (ibx == 0) {
9738                                                                ox = 0;
9739                                                        } else {
9740                                                                ox = toLong(iax / ibx);
9741                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9742                                                                        ox--;
9743                                                                }
9744                                                        }
9745                                                        oai64data[it.oIndex + j] = ox;
9746                                                }
9747                                        }
9748                                } else {
9749                                        while (it.hasNext()) {
9750                                                long iax = it.aLong;
9751                                                final long ibx = it.bLong;
9752                                                long ox;
9753                                                if (ibx == 0) {
9754                                                        ox = 0;
9755                                                } else {
9756                                                        ox = (iax / ibx);
9757                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9758                                                                ox--;
9759                                                        }
9760                                                }
9761                                                oai64data[it.oIndex] = ox;
9762                                                for (int j = 1; j < is; j++) {
9763                                                        iax = da.getElementLongAbs(it.aIndex + j);
9764                                                        if (ibx == 0) {
9765                                                                ox = 0;
9766                                                        } else {
9767                                                                ox = (iax / ibx);
9768                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9769                                                                        ox--;
9770                                                                }
9771                                                        }
9772                                                        oai64data[it.oIndex + j] = ox;
9773                                                }
9774                                        }
9775                                }
9776                        } else if (as == 1) {
9777                                if (it.isOutputDouble()) {
9778                                        while (it.hasNext()) {
9779                                                final double iax = it.aDouble;
9780                                                final double ibx = it.bDouble;
9781                                                long ox;
9782                                                if (ibx == 0) {
9783                                                        ox = 0;
9784                                                } else {
9785                                                        ox = toLong(iax / ibx);
9786                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9787                                                                ox--;
9788                                                        }
9789                                                }
9790                                                for (int j = 0; j < is; j++) {
9791                                                        oai64data[it.oIndex + j] = ox;
9792                                                }
9793                                        }
9794                                } else {
9795                                        while (it.hasNext()) {
9796                                                final long iax = it.aLong;
9797                                                final long ibx = it.bLong;
9798                                                long ox;
9799                                                if (ibx == 0) {
9800                                                        ox = 0;
9801                                                } else {
9802                                                        ox = (iax / ibx);
9803                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9804                                                                ox--;
9805                                                        }
9806                                                }
9807                                                for (int j = 0; j < is; j++) {
9808                                                        oai64data[it.oIndex + j] = ox;
9809                                                }
9810                                        }
9811                                }
9812                        } else {
9813                                if (it.isOutputDouble()) {
9814                                        while (it.hasNext()) {
9815                                                double iax = it.aDouble;
9816                                                double ibx = it.bDouble;
9817                                                long ox;
9818                                                if (ibx == 0) {
9819                                                        ox = 0;
9820                                                } else {
9821                                                        ox = toLong(iax / ibx);
9822                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9823                                                                ox--;
9824                                                        }
9825                                                }
9826                                                oai64data[it.oIndex] = ox;
9827                                                for (int j = 1; j < is; j++) {
9828                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9829                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9830                                                        if (ibx == 0) {
9831                                                                ox = 0;
9832                                                        } else {
9833                                                                ox = toLong(iax / ibx);
9834                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9835                                                                        ox--;
9836                                                                }
9837                                                        }
9838                                                        oai64data[it.oIndex + j] = ox;
9839                                                }
9840                                        }
9841                                } else {
9842                                        while (it.hasNext()) {
9843                                                long iax = it.aLong;
9844                                                long ibx = it.bLong;
9845                                                long ox;
9846                                                if (ibx == 0) {
9847                                                        ox = 0;
9848                                                } else {
9849                                                        ox = (iax / ibx);
9850                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9851                                                                ox--;
9852                                                        }
9853                                                }
9854                                                oai64data[it.oIndex] = ox;
9855                                                for (int j = 1; j < is; j++) {
9856                                                        iax = da.getElementLongAbs(it.aIndex + j);
9857                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9858                                                        if (ibx == 0) {
9859                                                                ox = 0;
9860                                                        } else {
9861                                                                ox = (iax / ibx);
9862                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9863                                                                        ox--;
9864                                                                }
9865                                                        }
9866                                                        oai64data[it.oIndex + j] = ox;
9867                                                }
9868                                        }
9869                                }
9870                        }
9871                        break;
9872                case Dataset.ARRAYINT32:
9873                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
9874                        if (is == 1) {
9875                                if (it.isOutputDouble()) {
9876                                        while (it.hasNext()) {
9877                                                final double iax = it.aDouble;
9878                                                final double ibx = it.bDouble;
9879                                                int ox;
9880                                                if (ibx == 0) {
9881                                                        ox = 0;
9882                                                } else {
9883                                                        ox = (int) toLong(iax / ibx);
9884                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9885                                                                ox--;
9886                                                        }
9887                                                }
9888                                                oai32data[it.oIndex] = ox;
9889                                        }
9890                                } else {
9891                                        while (it.hasNext()) {
9892                                                final long iax = it.aLong;
9893                                                final long ibx = it.bLong;
9894                                                int ox;
9895                                                if (ibx == 0) {
9896                                                        ox = 0;
9897                                                } else {
9898                                                        ox = (int) (iax / ibx);
9899                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9900                                                                ox--;
9901                                                        }
9902                                                }
9903                                                oai32data[it.oIndex] = ox;
9904                                        }
9905                                }
9906                        } else if (as < bs) {
9907                                if (it.isOutputDouble()) {
9908                                        while (it.hasNext()) {
9909                                                final double iax = it.aDouble;
9910                                                double ibx = it.bDouble;
9911                                                int ox;
9912                                                if (ibx == 0) {
9913                                                        ox = 0;
9914                                                } else {
9915                                                        ox = (int) toLong(iax / ibx);
9916                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9917                                                                ox--;
9918                                                        }
9919                                                }
9920                                                oai32data[it.oIndex] = ox;
9921                                                for (int j = 1; j < is; j++) {
9922                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9923                                                        if (ibx == 0) {
9924                                                                ox = 0;
9925                                                        } else {
9926                                                                ox = (int) toLong(iax / ibx);
9927                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9928                                                                        ox--;
9929                                                                }
9930                                                        }
9931                                                        oai32data[it.oIndex + j] = ox;
9932                                                }
9933                                        }
9934                                } else {
9935                                        while (it.hasNext()) {
9936                                                final long iax = it.aLong;
9937                                                long ibx = it.bLong;
9938                                                int ox;
9939                                                if (ibx == 0) {
9940                                                        ox = 0;
9941                                                } else {
9942                                                        ox = (int) (iax / ibx);
9943                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9944                                                                ox--;
9945                                                        }
9946                                                }
9947                                                oai32data[it.oIndex] = ox;
9948                                                for (int j = 1; j < is; j++) {
9949                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9950                                                        if (ibx == 0) {
9951                                                                ox = 0;
9952                                                        } else {
9953                                                                ox = (int) (iax / ibx);
9954                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9955                                                                        ox--;
9956                                                                }
9957                                                        }
9958                                                        oai32data[it.oIndex + j] = ox;
9959                                                }
9960                                        }
9961                                }
9962                        } else if (as > bs) {
9963                                if (it.isOutputDouble()) {
9964                                        while (it.hasNext()) {
9965                                                double iax = it.aDouble;
9966                                                final double ibx = it.bDouble;
9967                                                int ox;
9968                                                if (ibx == 0) {
9969                                                        ox = 0;
9970                                                } else {
9971                                                        ox = (int) toLong(iax / ibx);
9972                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9973                                                                ox--;
9974                                                        }
9975                                                }
9976                                                oai32data[it.oIndex] = ox;
9977                                                for (int j = 1; j < is; j++) {
9978                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9979                                                        if (ibx == 0) {
9980                                                                ox = 0;
9981                                                        } else {
9982                                                                ox = (int) toLong(iax / ibx);
9983                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9984                                                                        ox--;
9985                                                                }
9986                                                        }
9987                                                        oai32data[it.oIndex + j] = ox;
9988                                                }
9989                                        }
9990                                } else {
9991                                        while (it.hasNext()) {
9992                                                long iax = it.aLong;
9993                                                final long ibx = it.bLong;
9994                                                int ox;
9995                                                if (ibx == 0) {
9996                                                        ox = 0;
9997                                                } else {
9998                                                        ox = (int) (iax / ibx);
9999                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
10000                                                                ox--;
10001                                                        }
10002                                                }
10003                                                oai32data[it.oIndex] = ox;
10004                                                for (int j = 1; j < is; j++) {
10005                                                        iax = da.getElementLongAbs(it.aIndex + j);
10006                                                        if (ibx == 0) {
10007                                                                ox = 0;
10008                                                        } else {
10009                                                                ox = (int) (iax / ibx);
10010                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
10011                                                                        ox--;
10012                                                                }
10013                                                        }
10014                                                        oai32data[it.oIndex + j] = ox;
10015                                                }
10016                                        }
10017                                }
10018                        } else if (as == 1) {
10019                                if (it.isOutputDouble()) {
10020                                        while (it.hasNext()) {
10021                                                final double iax = it.aDouble;
10022                                                final double ibx = it.bDouble;
10023                                                int ox;
10024                                                if (ibx == 0) {
10025                                                        ox = 0;
10026                                                } else {
10027                                                        ox = (int) toLong(iax / ibx);
10028                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
10029                                                                ox--;
10030                                                        }
10031                                                }
10032                                                for (int j = 0; j < is; j++) {
10033                                                        oai32data[it.oIndex + j] = ox;
10034                                                }
10035                                        }
10036                                } else {
10037                                        while (it.hasNext()) {
10038                                                final long iax = it.aLong;
10039                                                final long ibx = it.bLong;
10040                                                int ox;
10041                                                if (ibx == 0) {
10042                                                        ox = 0;
10043                                                } else {
10044                                                        ox = (int) (iax / ibx);
10045                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
10046                                                                ox--;
10047                                                        }
10048                                                }
10049                                                for (int j = 0; j < is; j++) {
10050                                                        oai32data[it.oIndex + j] = ox;
10051                                                }
10052                                        }
10053                                }
10054                        } else {
10055                                if (it.isOutputDouble()) {
10056                                        while (it.hasNext()) {
10057                                                double iax = it.aDouble;
10058                                                double ibx = it.bDouble;
10059                                                int ox;
10060                                                if (ibx == 0) {
10061                                                        ox = 0;
10062                                                } else {
10063                                                        ox = (int) toLong(iax / ibx);
10064                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
10065                                                                ox--;
10066                                                        }
10067                                                }
10068                                                oai32data[it.oIndex] = ox;
10069                                                for (int j = 1; j < is; j++) {
10070                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10071                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10072                                                        if (ibx == 0) {
10073                                                                ox = 0;
10074                                                        } else {
10075                                                                ox = (int) toLong(iax / ibx);
10076                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
10077                                                                        ox--;
10078                                                                }
10079                                                        }
10080                                                        oai32data[it.oIndex + j] = ox;
10081                                                }
10082                                        }
10083                                } else {
10084                                        while (it.hasNext()) {
10085                                                long iax = it.aLong;
10086                                                long ibx = it.bLong;
10087                                                int ox;
10088                                                if (ibx == 0) {
10089                                                        ox = 0;
10090                                                } else {
10091                                                        ox = (int) (iax / ibx);
10092                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
10093                                                                ox--;
10094                                                        }
10095                                                }
10096                                                oai32data[it.oIndex] = ox;
10097                                                for (int j = 1; j < is; j++) {
10098                                                        iax = da.getElementLongAbs(it.aIndex + j);
10099                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10100                                                        if (ibx == 0) {
10101                                                                ox = 0;
10102                                                        } else {
10103                                                                ox = (int) (iax / ibx);
10104                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
10105                                                                        ox--;
10106                                                                }
10107                                                        }
10108                                                        oai32data[it.oIndex + j] = ox;
10109                                                }
10110                                        }
10111                                }
10112                        }
10113                        break;
10114                case Dataset.FLOAT32:
10115                        final float[] of32data = ((FloatDataset) result).getData();
10116                        if (it.isOutputDouble()) {
10117                                while (it.hasNext()) {
10118                                        final double iax = it.aDouble;
10119                                        final double ibx = it.bDouble;
10120                                        float ox;
10121                                        ox = (float) (iax / ibx);
10122                                        of32data[it.oIndex] = ox;
10123                                }
10124                        } else {
10125                                while (it.hasNext()) {
10126                                        final long iax = it.aLong;
10127                                        final long ibx = it.bLong;
10128                                        float ox;
10129                                        ox = (iax / ibx);
10130                                        of32data[it.oIndex] = ox;
10131                                }
10132                        }
10133                        break;
10134                case Dataset.FLOAT64:
10135                        final double[] of64data = ((DoubleDataset) result).getData();
10136                        if (it.isOutputDouble()) {
10137                                while (it.hasNext()) {
10138                                        final double iax = it.aDouble;
10139                                        final double ibx = it.bDouble;
10140                                        double ox;
10141                                        ox = (iax / ibx);
10142                                        of64data[it.oIndex] = ox;
10143                                }
10144                        } else {
10145                                while (it.hasNext()) {
10146                                        final long iax = it.aLong;
10147                                        final long ibx = it.bLong;
10148                                        double ox;
10149                                        ox = (iax / ibx);
10150                                        of64data[it.oIndex] = ox;
10151                                }
10152                        }
10153                        break;
10154                case Dataset.ARRAYFLOAT32:
10155                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
10156                        if (is == 1) {
10157                                if (it.isOutputDouble()) {
10158                                        while (it.hasNext()) {
10159                                                final double iax = it.aDouble;
10160                                                final double ibx = it.bDouble;
10161                                                float ox;
10162                                                ox = (float) (iax / ibx);
10163                                                oaf32data[it.oIndex] = ox;
10164                                        }
10165                                } else {
10166                                        while (it.hasNext()) {
10167                                                final long iax = it.aLong;
10168                                                final long ibx = it.bLong;
10169                                                float ox;
10170                                                ox = (iax / ibx);
10171                                                oaf32data[it.oIndex] = ox;
10172                                        }
10173                                }
10174                        } else if (as < bs) {
10175                                if (it.isOutputDouble()) {
10176                                        while (it.hasNext()) {
10177                                                final double iax = it.aDouble;
10178                                                double ibx = it.bDouble;
10179                                                float ox;
10180                                                ox = (float) (iax / ibx);
10181                                                oaf32data[it.oIndex] = ox;
10182                                                for (int j = 1; j < is; j++) {
10183                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10184                                                        ox = (float) (iax / ibx);
10185                                                        oaf32data[it.oIndex + j] = ox;
10186                                                }
10187                                        }
10188                                } else {
10189                                        while (it.hasNext()) {
10190                                                final long iax = it.aLong;
10191                                                long ibx = it.bLong;
10192                                                float ox;
10193                                                ox = (iax / ibx);
10194                                                oaf32data[it.oIndex] = ox;
10195                                                for (int j = 1; j < is; j++) {
10196                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10197                                                        ox = (iax / ibx);
10198                                                        oaf32data[it.oIndex + j] = ox;
10199                                                }
10200                                        }
10201                                }
10202                        } else if (as > bs) {
10203                                if (it.isOutputDouble()) {
10204                                        while (it.hasNext()) {
10205                                                double iax = it.aDouble;
10206                                                final double ibx = it.bDouble;
10207                                                float ox;
10208                                                ox = (float) (iax / ibx);
10209                                                oaf32data[it.oIndex] = ox;
10210                                                for (int j = 1; j < is; j++) {
10211                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10212                                                        ox = (float) (iax / ibx);
10213                                                        oaf32data[it.oIndex + j] = ox;
10214                                                }
10215                                        }
10216                                } else {
10217                                        while (it.hasNext()) {
10218                                                long iax = it.aLong;
10219                                                final long ibx = it.bLong;
10220                                                float ox;
10221                                                ox = (iax / ibx);
10222                                                oaf32data[it.oIndex] = ox;
10223                                                for (int j = 1; j < is; j++) {
10224                                                        iax = da.getElementLongAbs(it.aIndex + j);
10225                                                        ox = (iax / ibx);
10226                                                        oaf32data[it.oIndex + j] = ox;
10227                                                }
10228                                        }
10229                                }
10230                        } else if (as == 1) {
10231                                if (it.isOutputDouble()) {
10232                                        while (it.hasNext()) {
10233                                                final double iax = it.aDouble;
10234                                                final double ibx = it.bDouble;
10235                                                float ox;
10236                                                ox = (float) (iax / ibx);
10237                                                for (int j = 0; j < is; j++) {
10238                                                        oaf32data[it.oIndex + j] = ox;
10239                                                }
10240                                        }
10241                                } else {
10242                                        while (it.hasNext()) {
10243                                                final long iax = it.aLong;
10244                                                final long ibx = it.bLong;
10245                                                float ox;
10246                                                ox = (iax / ibx);
10247                                                for (int j = 0; j < is; j++) {
10248                                                        oaf32data[it.oIndex + j] = ox;
10249                                                }
10250                                        }
10251                                }
10252                        } else {
10253                                if (it.isOutputDouble()) {
10254                                        while (it.hasNext()) {
10255                                                double iax = it.aDouble;
10256                                                double ibx = it.bDouble;
10257                                                float ox;
10258                                                ox = (float) (iax / ibx);
10259                                                oaf32data[it.oIndex] = ox;
10260                                                for (int j = 1; j < is; j++) {
10261                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10262                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10263                                                        ox = (float) (iax / ibx);
10264                                                        oaf32data[it.oIndex + j] = ox;
10265                                                }
10266                                        }
10267                                } else {
10268                                        while (it.hasNext()) {
10269                                                long iax = it.aLong;
10270                                                long ibx = it.bLong;
10271                                                float ox;
10272                                                ox = (iax / ibx);
10273                                                oaf32data[it.oIndex] = ox;
10274                                                for (int j = 1; j < is; j++) {
10275                                                        iax = da.getElementLongAbs(it.aIndex + j);
10276                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10277                                                        ox = (iax / ibx);
10278                                                        oaf32data[it.oIndex + j] = ox;
10279                                                }
10280                                        }
10281                                }
10282                        }
10283                        break;
10284                case Dataset.ARRAYFLOAT64:
10285                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
10286                        if (is == 1) {
10287                                if (it.isOutputDouble()) {
10288                                        while (it.hasNext()) {
10289                                                final double iax = it.aDouble;
10290                                                final double ibx = it.bDouble;
10291                                                double ox;
10292                                                ox = (iax / ibx);
10293                                                oaf64data[it.oIndex] = ox;
10294                                        }
10295                                } else {
10296                                        while (it.hasNext()) {
10297                                                final long iax = it.aLong;
10298                                                final long ibx = it.bLong;
10299                                                double ox;
10300                                                ox = (iax / ibx);
10301                                                oaf64data[it.oIndex] = ox;
10302                                        }
10303                                }
10304                        } else if (as < bs) {
10305                                if (it.isOutputDouble()) {
10306                                        while (it.hasNext()) {
10307                                                final double iax = it.aDouble;
10308                                                double ibx = it.bDouble;
10309                                                double ox;
10310                                                ox = (iax / ibx);
10311                                                oaf64data[it.oIndex] = ox;
10312                                                for (int j = 1; j < is; j++) {
10313                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10314                                                        ox = (iax / ibx);
10315                                                        oaf64data[it.oIndex + j] = ox;
10316                                                }
10317                                        }
10318                                } else {
10319                                        while (it.hasNext()) {
10320                                                final long iax = it.aLong;
10321                                                long ibx = it.bLong;
10322                                                double ox;
10323                                                ox = (iax / ibx);
10324                                                oaf64data[it.oIndex] = ox;
10325                                                for (int j = 1; j < is; j++) {
10326                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10327                                                        ox = (iax / ibx);
10328                                                        oaf64data[it.oIndex + j] = ox;
10329                                                }
10330                                        }
10331                                }
10332                        } else if (as > bs) {
10333                                if (it.isOutputDouble()) {
10334                                        while (it.hasNext()) {
10335                                                double iax = it.aDouble;
10336                                                final double ibx = it.bDouble;
10337                                                double ox;
10338                                                ox = (iax / ibx);
10339                                                oaf64data[it.oIndex] = ox;
10340                                                for (int j = 1; j < is; j++) {
10341                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10342                                                        ox = (iax / ibx);
10343                                                        oaf64data[it.oIndex + j] = ox;
10344                                                }
10345                                        }
10346                                } else {
10347                                        while (it.hasNext()) {
10348                                                long iax = it.aLong;
10349                                                final long ibx = it.bLong;
10350                                                double ox;
10351                                                ox = (iax / ibx);
10352                                                oaf64data[it.oIndex] = ox;
10353                                                for (int j = 1; j < is; j++) {
10354                                                        iax = da.getElementLongAbs(it.aIndex + j);
10355                                                        ox = (iax / ibx);
10356                                                        oaf64data[it.oIndex + j] = ox;
10357                                                }
10358                                        }
10359                                }
10360                        } else if (as == 1) {
10361                                if (it.isOutputDouble()) {
10362                                        while (it.hasNext()) {
10363                                                final double iax = it.aDouble;
10364                                                final double ibx = it.bDouble;
10365                                                double ox;
10366                                                ox = (iax / ibx);
10367                                                for (int j = 0; j < is; j++) {
10368                                                        oaf64data[it.oIndex + j] = ox;
10369                                                }
10370                                        }
10371                                } else {
10372                                        while (it.hasNext()) {
10373                                                final long iax = it.aLong;
10374                                                final long ibx = it.bLong;
10375                                                double ox;
10376                                                ox = (iax / ibx);
10377                                                for (int j = 0; j < is; j++) {
10378                                                        oaf64data[it.oIndex + j] = ox;
10379                                                }
10380                                        }
10381                                }
10382                        } else {
10383                                if (it.isOutputDouble()) {
10384                                        while (it.hasNext()) {
10385                                                double iax = it.aDouble;
10386                                                double ibx = it.bDouble;
10387                                                double ox;
10388                                                ox = (iax / ibx);
10389                                                oaf64data[it.oIndex] = ox;
10390                                                for (int j = 1; j < is; j++) {
10391                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10392                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10393                                                        ox = (iax / ibx);
10394                                                        oaf64data[it.oIndex + j] = ox;
10395                                                }
10396                                        }
10397                                } else {
10398                                        while (it.hasNext()) {
10399                                                long iax = it.aLong;
10400                                                long ibx = it.bLong;
10401                                                double ox;
10402                                                ox = (iax / ibx);
10403                                                oaf64data[it.oIndex] = ox;
10404                                                for (int j = 1; j < is; j++) {
10405                                                        iax = da.getElementLongAbs(it.aIndex + j);
10406                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10407                                                        ox = (iax / ibx);
10408                                                        oaf64data[it.oIndex + j] = ox;
10409                                                }
10410                                        }
10411                                }
10412                        }
10413                        break;
10414                case Dataset.COMPLEX64:
10415                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
10416                        if (!da.isComplex()) {
10417                                if (it.isOutputDouble()) {
10418                                        final double iay = 0;
10419                                        if (db.isComplex()) {
10420                                                while (it.hasNext()) {
10421                                                        final double iax = it.aDouble;
10422                                                        final double ibx = it.bDouble;
10423                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
10424                                                        float ox;
10425                                                        float oy;
10426                                                        float q;
10427                                                        float den;
10428                                                        if (iby == 0) {
10429                                                                ox = (float) (iax / ibx);
10430                                                                oy = (float) (iay / ibx);
10431                                                        } else if (ibx == 0) {
10432                                                                ox = (float) (iay / iby);
10433                                                                oy = (float) (-iax / iby);
10434                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
10435                                                                q = (float) (ibx / iby);
10436                                                                den = (float) (ibx * q + iby);
10437                                                                ox = (float) ((iax * q + iay) / den);
10438                                                                oy = (float) ((iay * q - ibx) / den);
10439                                                        } else {
10440                                                                q = (float) (iby / ibx);
10441                                                                den = (float) (iby * q + ibx);
10442                                                                ox = (float) ((iay * q + iax) / den);
10443                                                                oy = (float) ((iay - iax * q) / den);
10444                                                        }
10445                                                        oc64data[it.oIndex] = ox;
10446                                                        oc64data[it.oIndex + 1] = oy;
10447                                                }
10448                                        } else {
10449                                                while (it.hasNext()) {
10450                                                        final double iax = it.aDouble;
10451                                                        final double ibx = it.bDouble;
10452                                                        final double iby = 0;
10453                                                        float ox;
10454                                                        float oy;
10455                                                        float q;
10456                                                        float den;
10457                                                        if (iby == 0) {
10458                                                                ox = (float) (iax / ibx);
10459                                                                oy = (float) (iay / ibx);
10460                                                        } else if (ibx == 0) {
10461                                                                ox = (float) (iay / iby);
10462                                                                oy = (float) (-iax / iby);
10463                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
10464                                                                q = (float) (ibx / iby);
10465                                                                den = (float) (ibx * q + iby);
10466                                                                ox = (float) ((iax * q + iay) / den);
10467                                                                oy = (float) ((iay * q - ibx) / den);
10468                                                        } else {
10469                                                                q = (float) (iby / ibx);
10470                                                                den = (float) (iby * q + ibx);
10471                                                                ox = (float) ((iay * q + iax) / den);
10472                                                                oy = (float) ((iay - iax * q) / den);
10473                                                        }
10474                                                        oc64data[it.oIndex] = ox;
10475                                                        oc64data[it.oIndex + 1] = oy;
10476                                                }
10477                                        }
10478                                } else {
10479                                        final long iay = 0;
10480                                        while (it.hasNext()) {
10481                                                final long iax = it.aLong;
10482                                                final long ibx = it.bLong;
10483                                                final long iby = 0;
10484                                                float ox;
10485                                                float oy;
10486                                                float q;
10487                                                float den;
10488                                                if (iby == 0) {
10489                                                        ox = (float) (iax / ibx);
10490                                                        oy = (float) (iay / ibx);
10491                                                } else if (ibx == 0) {
10492                                                        ox = (float) (iay / iby);
10493                                                        oy = (float) (-iax / iby);
10494                                                } else if (Math.abs(ibx) < Math.abs(iby)) {
10495                                                        q = (float) (ibx / iby);
10496                                                        den = (float) (ibx * q + iby);
10497                                                        ox = (float) ((iax * q + iay) / den);
10498                                                        oy = (float) ((iay * q - ibx) / den);
10499                                                } else {
10500                                                        q = (float) (iby / ibx);
10501                                                        den = (float) (iby * q + ibx);
10502                                                        ox = (float) ((iay * q + iax) / den);
10503                                                        oy = (float) ((iay - iax * q) / den);
10504                                                }
10505                                                oc64data[it.oIndex] = ox;
10506                                                oc64data[it.oIndex + 1] = oy;
10507                                        }
10508                                }
10509                        } else if (!db.isComplex()) {
10510                                final double iby = 0;
10511                                while (it.hasNext()) {
10512                                        final double iax = it.aDouble;
10513                                        final double ibx = it.bDouble;
10514                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
10515                                        float ox;
10516                                        float oy;
10517                                        float q;
10518                                        float den;
10519                                        if (iby == 0) {
10520                                                ox = (float) (iax / ibx);
10521                                                oy = (float) (iay / ibx);
10522                                        } else if (ibx == 0) {
10523                                                ox = (float) (iay / iby);
10524                                                oy = (float) (-iax / iby);
10525                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
10526                                                q = (float) (ibx / iby);
10527                                                den = (float) (ibx * q + iby);
10528                                                ox = (float) ((iax * q + iay) / den);
10529                                                oy = (float) ((iay * q - ibx) / den);
10530                                        } else {
10531                                                q = (float) (iby / ibx);
10532                                                den = (float) (iby * q + ibx);
10533                                                ox = (float) ((iay * q + iax) / den);
10534                                                oy = (float) ((iay - iax * q) / den);
10535                                        }
10536                                        oc64data[it.oIndex] = ox;
10537                                        oc64data[it.oIndex + 1] = oy;
10538                                }
10539                        } else {
10540                                while (it.hasNext()) {
10541                                        final double iax = it.aDouble;
10542                                        final double ibx = it.bDouble;
10543                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
10544                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
10545                                        float ox;
10546                                        float oy;
10547                                        float q;
10548                                        float den;
10549                                        if (iby == 0) {
10550                                                ox = (float) (iax / ibx);
10551                                                oy = (float) (iay / ibx);
10552                                        } else if (ibx == 0) {
10553                                                ox = (float) (iay / iby);
10554                                                oy = (float) (-iax / iby);
10555                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
10556                                                q = (float) (ibx / iby);
10557                                                den = (float) (ibx * q + iby);
10558                                                ox = (float) ((iax * q + iay) / den);
10559                                                oy = (float) ((iay * q - ibx) / den);
10560                                        } else {
10561                                                q = (float) (iby / ibx);
10562                                                den = (float) (iby * q + ibx);
10563                                                ox = (float) ((iay * q + iax) / den);
10564                                                oy = (float) ((iay - iax * q) / den);
10565                                        }
10566                                        oc64data[it.oIndex] = ox;
10567                                        oc64data[it.oIndex + 1] = oy;
10568                                }
10569                        }
10570                        break;
10571                case Dataset.COMPLEX128:
10572                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
10573                        if (!da.isComplex()) {
10574                                if (it.isOutputDouble()) {
10575                                        final double iay = 0;
10576                                        if (db.isComplex()) {
10577                                                while (it.hasNext()) {
10578                                                        final double iax = it.aDouble;
10579                                                        final double ibx = it.bDouble;
10580                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
10581                                                        double ox;
10582                                                        double oy;
10583                                                        double q;
10584                                                        double den;
10585                                                        if (iby == 0) {
10586                                                                ox = (iax / ibx);
10587                                                                oy = (iay / ibx);
10588                                                        } else if (ibx == 0) {
10589                                                                ox = (iay / iby);
10590                                                                oy = (-iax / iby);
10591                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
10592                                                                q = (ibx / iby);
10593                                                                den = (ibx * q + iby);
10594                                                                ox = ((iax * q + iay) / den);
10595                                                                oy = ((iay * q - ibx) / den);
10596                                                        } else {
10597                                                                q = (iby / ibx);
10598                                                                den = (iby * q + ibx);
10599                                                                ox = ((iay * q + iax) / den);
10600                                                                oy = ((iay - iax * q) / den);
10601                                                        }
10602                                                        oc128data[it.oIndex] = ox;
10603                                                        oc128data[it.oIndex + 1] = oy;
10604                                                }
10605                                        } else {
10606                                                while (it.hasNext()) {
10607                                                        final double iax = it.aDouble;
10608                                                        final double ibx = it.bDouble;
10609                                                        final double iby = 0;
10610                                                        double ox;
10611                                                        double oy;
10612                                                        double q;
10613                                                        double den;
10614                                                        if (iby == 0) {
10615                                                                ox = (iax / ibx);
10616                                                                oy = (iay / ibx);
10617                                                        } else if (ibx == 0) {
10618                                                                ox = (iay / iby);
10619                                                                oy = (-iax / iby);
10620                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
10621                                                                q = (ibx / iby);
10622                                                                den = (ibx * q + iby);
10623                                                                ox = ((iax * q + iay) / den);
10624                                                                oy = ((iay * q - ibx) / den);
10625                                                        } else {
10626                                                                q = (iby / ibx);
10627                                                                den = (iby * q + ibx);
10628                                                                ox = ((iay * q + iax) / den);
10629                                                                oy = ((iay - iax * q) / den);
10630                                                        }
10631                                                        oc128data[it.oIndex] = ox;
10632                                                        oc128data[it.oIndex + 1] = oy;
10633                                                }
10634                                        }
10635                                } else {
10636                                        final long iay = 0;
10637                                        while (it.hasNext()) {
10638                                                final long iax = it.aLong;
10639                                                final long ibx = it.bLong;
10640                                                final long iby = 0;
10641                                                double ox;
10642                                                double oy;
10643                                                double q;
10644                                                double den;
10645                                                if (iby == 0) {
10646                                                        ox = (iax / ibx);
10647                                                        oy = (iay / ibx);
10648                                                } else if (ibx == 0) {
10649                                                        ox = (iay / iby);
10650                                                        oy = (-iax / iby);
10651                                                } else if (Math.abs(ibx) < Math.abs(iby)) {
10652                                                        q = (ibx / iby);
10653                                                        den = (ibx * q + iby);
10654                                                        ox = ((iax * q + iay) / den);
10655                                                        oy = ((iay * q - ibx) / den);
10656                                                } else {
10657                                                        q = (iby / ibx);
10658                                                        den = (iby * q + ibx);
10659                                                        ox = ((iay * q + iax) / den);
10660                                                        oy = ((iay - iax * q) / den);
10661                                                }
10662                                                oc128data[it.oIndex] = ox;
10663                                                oc128data[it.oIndex + 1] = oy;
10664                                        }
10665                                }
10666                        } else if (!db.isComplex()) {
10667                                final double iby = 0;
10668                                while (it.hasNext()) {
10669                                        final double iax = it.aDouble;
10670                                        final double ibx = it.bDouble;
10671                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
10672                                        double ox;
10673                                        double oy;
10674                                        double q;
10675                                        double den;
10676                                        if (iby == 0) {
10677                                                ox = (iax / ibx);
10678                                                oy = (iay / ibx);
10679                                        } else if (ibx == 0) {
10680                                                ox = (iay / iby);
10681                                                oy = (-iax / iby);
10682                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
10683                                                q = (ibx / iby);
10684                                                den = (ibx * q + iby);
10685                                                ox = ((iax * q + iay) / den);
10686                                                oy = ((iay * q - ibx) / den);
10687                                        } else {
10688                                                q = (iby / ibx);
10689                                                den = (iby * q + ibx);
10690                                                ox = ((iay * q + iax) / den);
10691                                                oy = ((iay - iax * q) / den);
10692                                        }
10693                                        oc128data[it.oIndex] = ox;
10694                                        oc128data[it.oIndex + 1] = oy;
10695                                }
10696                        } else {
10697                                while (it.hasNext()) {
10698                                        final double iax = it.aDouble;
10699                                        final double ibx = it.bDouble;
10700                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
10701                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
10702                                        double ox;
10703                                        double oy;
10704                                        double q;
10705                                        double den;
10706                                        if (iby == 0) {
10707                                                ox = (iax / ibx);
10708                                                oy = (iay / ibx);
10709                                        } else if (ibx == 0) {
10710                                                ox = (iay / iby);
10711                                                oy = (-iax / iby);
10712                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
10713                                                q = (ibx / iby);
10714                                                den = (ibx * q + iby);
10715                                                ox = ((iax * q + iay) / den);
10716                                                oy = ((iay * q - ibx) / den);
10717                                        } else {
10718                                                q = (iby / ibx);
10719                                                den = (iby * q + ibx);
10720                                                ox = ((iay * q + iax) / den);
10721                                                oy = ((iay - iax * q) / den);
10722                                        }
10723                                        oc128data[it.oIndex] = ox;
10724                                        oc128data[it.oIndex + 1] = oy;
10725                                }
10726                        }
10727                        break;
10728                default:
10729                        throw new IllegalArgumentException("divideTowardsFloor supports integer, compound integer, real, compound real, complex datasets only");
10730                }
10731
10732                addBinaryOperatorName(da, db, result, "/");
10733                return result;
10734        }
10735
10736        /**
10737         * power operator
10738         * @param a
10739         * @param b
10740         * @return {@code a ** b}, raise a to power of b
10741         */
10742        public static Dataset power(final Object a, final Object b) {
10743                return power(a, b, null);
10744        }
10745
10746        /**
10747         * power operator
10748         * @param a
10749         * @param b
10750         * @param o output can be null - in which case, a new dataset is created
10751         * @return {@code a ** b}, raise a to power of b
10752         */
10753        public static Dataset power(final Object a, final Object b, final Dataset o) {
10754                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
10755                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
10756                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
10757                final Dataset result = it.getOutput();
10758                if (!result.isComplex()) {
10759                        boolean change = false;
10760                        if (da.isComplex()) {
10761                                da = da.getRealView();
10762                                change = true;
10763                        }
10764                        if (db.isComplex()) {
10765                                db = db.getRealView();
10766                                change = true;
10767                        }
10768                        if (change) {
10769                                it = BroadcastIterator.createIterator(da, db, result, true);
10770                        }
10771                }
10772                final int is = result.getElementsPerItem();
10773                final int as = da.getElementsPerItem();
10774                final int bs = db.getElementsPerItem();
10775                final int dt = result.getDType();
10776
10777                switch(dt) {
10778                case Dataset.INT8:
10779                        final byte[] oi8data = ((ByteDataset) result).getData();
10780                        if (it.isOutputDouble()) {
10781                                while (it.hasNext()) {
10782                                        final double iax = it.aDouble;
10783                                        final double ibx = it.bDouble;
10784                                        byte ox;
10785                                        ox = (byte) toLong(Math.pow(iax, ibx));
10786                                        oi8data[it.oIndex] = ox;
10787                                }
10788                        } else {
10789                                while (it.hasNext()) {
10790                                        final long iax = it.aLong;
10791                                        final long ibx = it.bLong;
10792                                        byte ox;
10793                                        ox = (byte) toLong(Math.pow(iax, ibx));
10794                                        oi8data[it.oIndex] = ox;
10795                                }
10796                        }
10797                        break;
10798                case Dataset.INT16:
10799                        final short[] oi16data = ((ShortDataset) result).getData();
10800                        if (it.isOutputDouble()) {
10801                                while (it.hasNext()) {
10802                                        final double iax = it.aDouble;
10803                                        final double ibx = it.bDouble;
10804                                        short ox;
10805                                        ox = (short) toLong(Math.pow(iax, ibx));
10806                                        oi16data[it.oIndex] = ox;
10807                                }
10808                        } else {
10809                                while (it.hasNext()) {
10810                                        final long iax = it.aLong;
10811                                        final long ibx = it.bLong;
10812                                        short ox;
10813                                        ox = (short) toLong(Math.pow(iax, ibx));
10814                                        oi16data[it.oIndex] = ox;
10815                                }
10816                        }
10817                        break;
10818                case Dataset.INT64:
10819                        final long[] oi64data = ((LongDataset) result).getData();
10820                        if (it.isOutputDouble()) {
10821                                while (it.hasNext()) {
10822                                        final double iax = it.aDouble;
10823                                        final double ibx = it.bDouble;
10824                                        long ox;
10825                                        ox = toLong(Math.pow(iax, ibx));
10826                                        oi64data[it.oIndex] = ox;
10827                                }
10828                        } else {
10829                                while (it.hasNext()) {
10830                                        final long iax = it.aLong;
10831                                        final long ibx = it.bLong;
10832                                        long ox;
10833                                        ox = toLong(Math.pow(iax, ibx));
10834                                        oi64data[it.oIndex] = ox;
10835                                }
10836                        }
10837                        break;
10838                case Dataset.INT32:
10839                        final int[] oi32data = ((IntegerDataset) result).getData();
10840                        if (it.isOutputDouble()) {
10841                                while (it.hasNext()) {
10842                                        final double iax = it.aDouble;
10843                                        final double ibx = it.bDouble;
10844                                        int ox;
10845                                        ox = (int) toLong(Math.pow(iax, ibx));
10846                                        oi32data[it.oIndex] = ox;
10847                                }
10848                        } else {
10849                                while (it.hasNext()) {
10850                                        final long iax = it.aLong;
10851                                        final long ibx = it.bLong;
10852                                        int ox;
10853                                        ox = (int) toLong(Math.pow(iax, ibx));
10854                                        oi32data[it.oIndex] = ox;
10855                                }
10856                        }
10857                        break;
10858                case Dataset.ARRAYINT8:
10859                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
10860                        if (is == 1) {
10861                                if (it.isOutputDouble()) {
10862                                        while (it.hasNext()) {
10863                                                final double iax = it.aDouble;
10864                                                final double ibx = it.bDouble;
10865                                                byte ox;
10866                                                ox = (byte) toLong(Math.pow(iax, ibx));
10867                                                oai8data[it.oIndex] = ox;
10868                                        }
10869                                } else {
10870                                        while (it.hasNext()) {
10871                                                final long iax = it.aLong;
10872                                                final long ibx = it.bLong;
10873                                                byte ox;
10874                                                ox = (byte) toLong(Math.pow(iax, ibx));
10875                                                oai8data[it.oIndex] = ox;
10876                                        }
10877                                }
10878                        } else if (as < bs) {
10879                                if (it.isOutputDouble()) {
10880                                        while (it.hasNext()) {
10881                                                final double iax = it.aDouble;
10882                                                double ibx = it.bDouble;
10883                                                byte ox;
10884                                                ox = (byte) toLong(Math.pow(iax, ibx));
10885                                                oai8data[it.oIndex] = ox;
10886                                                for (int j = 1; j < is; j++) {
10887                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10888                                                        ox = (byte) toLong(Math.pow(iax, ibx));
10889                                                        oai8data[it.oIndex + j] = ox;
10890                                                }
10891                                        }
10892                                } else {
10893                                        while (it.hasNext()) {
10894                                                final long iax = it.aLong;
10895                                                long ibx = it.bLong;
10896                                                byte ox;
10897                                                ox = (byte) toLong(Math.pow(iax, ibx));
10898                                                oai8data[it.oIndex] = ox;
10899                                                for (int j = 1; j < is; j++) {
10900                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10901                                                        ox = (byte) toLong(Math.pow(iax, ibx));
10902                                                        oai8data[it.oIndex + j] = ox;
10903                                                }
10904                                        }
10905                                }
10906                        } else if (as > bs) {
10907                                if (it.isOutputDouble()) {
10908                                        while (it.hasNext()) {
10909                                                double iax = it.aDouble;
10910                                                final double ibx = it.bDouble;
10911                                                byte ox;
10912                                                ox = (byte) toLong(Math.pow(iax, ibx));
10913                                                oai8data[it.oIndex] = ox;
10914                                                for (int j = 1; j < is; j++) {
10915                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10916                                                        ox = (byte) toLong(Math.pow(iax, ibx));
10917                                                        oai8data[it.oIndex + j] = ox;
10918                                                }
10919                                        }
10920                                } else {
10921                                        while (it.hasNext()) {
10922                                                long iax = it.aLong;
10923                                                final long ibx = it.bLong;
10924                                                byte ox;
10925                                                ox = (byte) toLong(Math.pow(iax, ibx));
10926                                                oai8data[it.oIndex] = ox;
10927                                                for (int j = 1; j < is; j++) {
10928                                                        iax = da.getElementLongAbs(it.aIndex + j);
10929                                                        ox = (byte) toLong(Math.pow(iax, ibx));
10930                                                        oai8data[it.oIndex + j] = ox;
10931                                                }
10932                                        }
10933                                }
10934                        } else if (as == 1) {
10935                                if (it.isOutputDouble()) {
10936                                        while (it.hasNext()) {
10937                                                final double iax = it.aDouble;
10938                                                final double ibx = it.bDouble;
10939                                                byte ox;
10940                                                ox = (byte) toLong(Math.pow(iax, ibx));
10941                                                for (int j = 0; j < is; j++) {
10942                                                        oai8data[it.oIndex + j] = ox;
10943                                                }
10944                                        }
10945                                } else {
10946                                        while (it.hasNext()) {
10947                                                final long iax = it.aLong;
10948                                                final long ibx = it.bLong;
10949                                                byte ox;
10950                                                ox = (byte) toLong(Math.pow(iax, ibx));
10951                                                for (int j = 0; j < is; j++) {
10952                                                        oai8data[it.oIndex + j] = ox;
10953                                                }
10954                                        }
10955                                }
10956                        } else {
10957                                if (it.isOutputDouble()) {
10958                                        while (it.hasNext()) {
10959                                                double iax = it.aDouble;
10960                                                double ibx = it.bDouble;
10961                                                byte ox;
10962                                                ox = (byte) toLong(Math.pow(iax, ibx));
10963                                                oai8data[it.oIndex] = ox;
10964                                                for (int j = 1; j < is; j++) {
10965                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10966                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10967                                                        ox = (byte) toLong(Math.pow(iax, ibx));
10968                                                        oai8data[it.oIndex + j] = ox;
10969                                                }
10970                                        }
10971                                } else {
10972                                        while (it.hasNext()) {
10973                                                long iax = it.aLong;
10974                                                long ibx = it.bLong;
10975                                                byte ox;
10976                                                ox = (byte) toLong(Math.pow(iax, ibx));
10977                                                oai8data[it.oIndex] = ox;
10978                                                for (int j = 1; j < is; j++) {
10979                                                        iax = da.getElementLongAbs(it.aIndex + j);
10980                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10981                                                        ox = (byte) toLong(Math.pow(iax, ibx));
10982                                                        oai8data[it.oIndex + j] = ox;
10983                                                }
10984                                        }
10985                                }
10986                        }
10987                        break;
10988                case Dataset.ARRAYINT16:
10989                        final short[] oai16data = ((CompoundShortDataset) result).getData();
10990                        if (is == 1) {
10991                                if (it.isOutputDouble()) {
10992                                        while (it.hasNext()) {
10993                                                final double iax = it.aDouble;
10994                                                final double ibx = it.bDouble;
10995                                                short ox;
10996                                                ox = (short) toLong(Math.pow(iax, ibx));
10997                                                oai16data[it.oIndex] = ox;
10998                                        }
10999                                } else {
11000                                        while (it.hasNext()) {
11001                                                final long iax = it.aLong;
11002                                                final long ibx = it.bLong;
11003                                                short ox;
11004                                                ox = (short) toLong(Math.pow(iax, ibx));
11005                                                oai16data[it.oIndex] = ox;
11006                                        }
11007                                }
11008                        } else if (as < bs) {
11009                                if (it.isOutputDouble()) {
11010                                        while (it.hasNext()) {
11011                                                final double iax = it.aDouble;
11012                                                double ibx = it.bDouble;
11013                                                short ox;
11014                                                ox = (short) toLong(Math.pow(iax, ibx));
11015                                                oai16data[it.oIndex] = ox;
11016                                                for (int j = 1; j < is; j++) {
11017                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11018                                                        ox = (short) toLong(Math.pow(iax, ibx));
11019                                                        oai16data[it.oIndex + j] = ox;
11020                                                }
11021                                        }
11022                                } else {
11023                                        while (it.hasNext()) {
11024                                                final long iax = it.aLong;
11025                                                long ibx = it.bLong;
11026                                                short ox;
11027                                                ox = (short) toLong(Math.pow(iax, ibx));
11028                                                oai16data[it.oIndex] = ox;
11029                                                for (int j = 1; j < is; j++) {
11030                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11031                                                        ox = (short) toLong(Math.pow(iax, ibx));
11032                                                        oai16data[it.oIndex + j] = ox;
11033                                                }
11034                                        }
11035                                }
11036                        } else if (as > bs) {
11037                                if (it.isOutputDouble()) {
11038                                        while (it.hasNext()) {
11039                                                double iax = it.aDouble;
11040                                                final double ibx = it.bDouble;
11041                                                short ox;
11042                                                ox = (short) toLong(Math.pow(iax, ibx));
11043                                                oai16data[it.oIndex] = ox;
11044                                                for (int j = 1; j < is; j++) {
11045                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11046                                                        ox = (short) toLong(Math.pow(iax, ibx));
11047                                                        oai16data[it.oIndex + j] = ox;
11048                                                }
11049                                        }
11050                                } else {
11051                                        while (it.hasNext()) {
11052                                                long iax = it.aLong;
11053                                                final long ibx = it.bLong;
11054                                                short ox;
11055                                                ox = (short) toLong(Math.pow(iax, ibx));
11056                                                oai16data[it.oIndex] = ox;
11057                                                for (int j = 1; j < is; j++) {
11058                                                        iax = da.getElementLongAbs(it.aIndex + j);
11059                                                        ox = (short) toLong(Math.pow(iax, ibx));
11060                                                        oai16data[it.oIndex + j] = ox;
11061                                                }
11062                                        }
11063                                }
11064                        } else if (as == 1) {
11065                                if (it.isOutputDouble()) {
11066                                        while (it.hasNext()) {
11067                                                final double iax = it.aDouble;
11068                                                final double ibx = it.bDouble;
11069                                                short ox;
11070                                                ox = (short) toLong(Math.pow(iax, ibx));
11071                                                for (int j = 0; j < is; j++) {
11072                                                        oai16data[it.oIndex + j] = ox;
11073                                                }
11074                                        }
11075                                } else {
11076                                        while (it.hasNext()) {
11077                                                final long iax = it.aLong;
11078                                                final long ibx = it.bLong;
11079                                                short ox;
11080                                                ox = (short) toLong(Math.pow(iax, ibx));
11081                                                for (int j = 0; j < is; j++) {
11082                                                        oai16data[it.oIndex + j] = ox;
11083                                                }
11084                                        }
11085                                }
11086                        } else {
11087                                if (it.isOutputDouble()) {
11088                                        while (it.hasNext()) {
11089                                                double iax = it.aDouble;
11090                                                double ibx = it.bDouble;
11091                                                short ox;
11092                                                ox = (short) toLong(Math.pow(iax, ibx));
11093                                                oai16data[it.oIndex] = ox;
11094                                                for (int j = 1; j < is; j++) {
11095                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11096                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11097                                                        ox = (short) toLong(Math.pow(iax, ibx));
11098                                                        oai16data[it.oIndex + j] = ox;
11099                                                }
11100                                        }
11101                                } else {
11102                                        while (it.hasNext()) {
11103                                                long iax = it.aLong;
11104                                                long ibx = it.bLong;
11105                                                short ox;
11106                                                ox = (short) toLong(Math.pow(iax, ibx));
11107                                                oai16data[it.oIndex] = ox;
11108                                                for (int j = 1; j < is; j++) {
11109                                                        iax = da.getElementLongAbs(it.aIndex + j);
11110                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11111                                                        ox = (short) toLong(Math.pow(iax, ibx));
11112                                                        oai16data[it.oIndex + j] = ox;
11113                                                }
11114                                        }
11115                                }
11116                        }
11117                        break;
11118                case Dataset.ARRAYINT64:
11119                        final long[] oai64data = ((CompoundLongDataset) result).getData();
11120                        if (is == 1) {
11121                                if (it.isOutputDouble()) {
11122                                        while (it.hasNext()) {
11123                                                final double iax = it.aDouble;
11124                                                final double ibx = it.bDouble;
11125                                                long ox;
11126                                                ox = toLong(Math.pow(iax, ibx));
11127                                                oai64data[it.oIndex] = ox;
11128                                        }
11129                                } else {
11130                                        while (it.hasNext()) {
11131                                                final long iax = it.aLong;
11132                                                final long ibx = it.bLong;
11133                                                long ox;
11134                                                ox = toLong(Math.pow(iax, ibx));
11135                                                oai64data[it.oIndex] = ox;
11136                                        }
11137                                }
11138                        } else if (as < bs) {
11139                                if (it.isOutputDouble()) {
11140                                        while (it.hasNext()) {
11141                                                final double iax = it.aDouble;
11142                                                double ibx = it.bDouble;
11143                                                long ox;
11144                                                ox = toLong(Math.pow(iax, ibx));
11145                                                oai64data[it.oIndex] = ox;
11146                                                for (int j = 1; j < is; j++) {
11147                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11148                                                        ox = toLong(Math.pow(iax, ibx));
11149                                                        oai64data[it.oIndex + j] = ox;
11150                                                }
11151                                        }
11152                                } else {
11153                                        while (it.hasNext()) {
11154                                                final long iax = it.aLong;
11155                                                long ibx = it.bLong;
11156                                                long ox;
11157                                                ox = toLong(Math.pow(iax, ibx));
11158                                                oai64data[it.oIndex] = ox;
11159                                                for (int j = 1; j < is; j++) {
11160                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11161                                                        ox = toLong(Math.pow(iax, ibx));
11162                                                        oai64data[it.oIndex + j] = ox;
11163                                                }
11164                                        }
11165                                }
11166                        } else if (as > bs) {
11167                                if (it.isOutputDouble()) {
11168                                        while (it.hasNext()) {
11169                                                double iax = it.aDouble;
11170                                                final double ibx = it.bDouble;
11171                                                long ox;
11172                                                ox = toLong(Math.pow(iax, ibx));
11173                                                oai64data[it.oIndex] = ox;
11174                                                for (int j = 1; j < is; j++) {
11175                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11176                                                        ox = toLong(Math.pow(iax, ibx));
11177                                                        oai64data[it.oIndex + j] = ox;
11178                                                }
11179                                        }
11180                                } else {
11181                                        while (it.hasNext()) {
11182                                                long iax = it.aLong;
11183                                                final long ibx = it.bLong;
11184                                                long ox;
11185                                                ox = toLong(Math.pow(iax, ibx));
11186                                                oai64data[it.oIndex] = ox;
11187                                                for (int j = 1; j < is; j++) {
11188                                                        iax = da.getElementLongAbs(it.aIndex + j);
11189                                                        ox = toLong(Math.pow(iax, ibx));
11190                                                        oai64data[it.oIndex + j] = ox;
11191                                                }
11192                                        }
11193                                }
11194                        } else if (as == 1) {
11195                                if (it.isOutputDouble()) {
11196                                        while (it.hasNext()) {
11197                                                final double iax = it.aDouble;
11198                                                final double ibx = it.bDouble;
11199                                                long ox;
11200                                                ox = toLong(Math.pow(iax, ibx));
11201                                                for (int j = 0; j < is; j++) {
11202                                                        oai64data[it.oIndex + j] = ox;
11203                                                }
11204                                        }
11205                                } else {
11206                                        while (it.hasNext()) {
11207                                                final long iax = it.aLong;
11208                                                final long ibx = it.bLong;
11209                                                long ox;
11210                                                ox = toLong(Math.pow(iax, ibx));
11211                                                for (int j = 0; j < is; j++) {
11212                                                        oai64data[it.oIndex + j] = ox;
11213                                                }
11214                                        }
11215                                }
11216                        } else {
11217                                if (it.isOutputDouble()) {
11218                                        while (it.hasNext()) {
11219                                                double iax = it.aDouble;
11220                                                double ibx = it.bDouble;
11221                                                long ox;
11222                                                ox = toLong(Math.pow(iax, ibx));
11223                                                oai64data[it.oIndex] = ox;
11224                                                for (int j = 1; j < is; j++) {
11225                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11226                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11227                                                        ox = toLong(Math.pow(iax, ibx));
11228                                                        oai64data[it.oIndex + j] = ox;
11229                                                }
11230                                        }
11231                                } else {
11232                                        while (it.hasNext()) {
11233                                                long iax = it.aLong;
11234                                                long ibx = it.bLong;
11235                                                long ox;
11236                                                ox = toLong(Math.pow(iax, ibx));
11237                                                oai64data[it.oIndex] = ox;
11238                                                for (int j = 1; j < is; j++) {
11239                                                        iax = da.getElementLongAbs(it.aIndex + j);
11240                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11241                                                        ox = toLong(Math.pow(iax, ibx));
11242                                                        oai64data[it.oIndex + j] = ox;
11243                                                }
11244                                        }
11245                                }
11246                        }
11247                        break;
11248                case Dataset.ARRAYINT32:
11249                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
11250                        if (is == 1) {
11251                                if (it.isOutputDouble()) {
11252                                        while (it.hasNext()) {
11253                                                final double iax = it.aDouble;
11254                                                final double ibx = it.bDouble;
11255                                                int ox;
11256                                                ox = (int) toLong(Math.pow(iax, ibx));
11257                                                oai32data[it.oIndex] = ox;
11258                                        }
11259                                } else {
11260                                        while (it.hasNext()) {
11261                                                final long iax = it.aLong;
11262                                                final long ibx = it.bLong;
11263                                                int ox;
11264                                                ox = (int) toLong(Math.pow(iax, ibx));
11265                                                oai32data[it.oIndex] = ox;
11266                                        }
11267                                }
11268                        } else if (as < bs) {
11269                                if (it.isOutputDouble()) {
11270                                        while (it.hasNext()) {
11271                                                final double iax = it.aDouble;
11272                                                double ibx = it.bDouble;
11273                                                int ox;
11274                                                ox = (int) toLong(Math.pow(iax, ibx));
11275                                                oai32data[it.oIndex] = ox;
11276                                                for (int j = 1; j < is; j++) {
11277                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11278                                                        ox = (int) toLong(Math.pow(iax, ibx));
11279                                                        oai32data[it.oIndex + j] = ox;
11280                                                }
11281                                        }
11282                                } else {
11283                                        while (it.hasNext()) {
11284                                                final long iax = it.aLong;
11285                                                long ibx = it.bLong;
11286                                                int ox;
11287                                                ox = (int) toLong(Math.pow(iax, ibx));
11288                                                oai32data[it.oIndex] = ox;
11289                                                for (int j = 1; j < is; j++) {
11290                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11291                                                        ox = (int) toLong(Math.pow(iax, ibx));
11292                                                        oai32data[it.oIndex + j] = ox;
11293                                                }
11294                                        }
11295                                }
11296                        } else if (as > bs) {
11297                                if (it.isOutputDouble()) {
11298                                        while (it.hasNext()) {
11299                                                double iax = it.aDouble;
11300                                                final double ibx = it.bDouble;
11301                                                int ox;
11302                                                ox = (int) toLong(Math.pow(iax, ibx));
11303                                                oai32data[it.oIndex] = ox;
11304                                                for (int j = 1; j < is; j++) {
11305                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11306                                                        ox = (int) toLong(Math.pow(iax, ibx));
11307                                                        oai32data[it.oIndex + j] = ox;
11308                                                }
11309                                        }
11310                                } else {
11311                                        while (it.hasNext()) {
11312                                                long iax = it.aLong;
11313                                                final long ibx = it.bLong;
11314                                                int ox;
11315                                                ox = (int) toLong(Math.pow(iax, ibx));
11316                                                oai32data[it.oIndex] = ox;
11317                                                for (int j = 1; j < is; j++) {
11318                                                        iax = da.getElementLongAbs(it.aIndex + j);
11319                                                        ox = (int) toLong(Math.pow(iax, ibx));
11320                                                        oai32data[it.oIndex + j] = ox;
11321                                                }
11322                                        }
11323                                }
11324                        } else if (as == 1) {
11325                                if (it.isOutputDouble()) {
11326                                        while (it.hasNext()) {
11327                                                final double iax = it.aDouble;
11328                                                final double ibx = it.bDouble;
11329                                                int ox;
11330                                                ox = (int) toLong(Math.pow(iax, ibx));
11331                                                for (int j = 0; j < is; j++) {
11332                                                        oai32data[it.oIndex + j] = ox;
11333                                                }
11334                                        }
11335                                } else {
11336                                        while (it.hasNext()) {
11337                                                final long iax = it.aLong;
11338                                                final long ibx = it.bLong;
11339                                                int ox;
11340                                                ox = (int) toLong(Math.pow(iax, ibx));
11341                                                for (int j = 0; j < is; j++) {
11342                                                        oai32data[it.oIndex + j] = ox;
11343                                                }
11344                                        }
11345                                }
11346                        } else {
11347                                if (it.isOutputDouble()) {
11348                                        while (it.hasNext()) {
11349                                                double iax = it.aDouble;
11350                                                double ibx = it.bDouble;
11351                                                int ox;
11352                                                ox = (int) toLong(Math.pow(iax, ibx));
11353                                                oai32data[it.oIndex] = ox;
11354                                                for (int j = 1; j < is; j++) {
11355                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11356                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11357                                                        ox = (int) toLong(Math.pow(iax, ibx));
11358                                                        oai32data[it.oIndex + j] = ox;
11359                                                }
11360                                        }
11361                                } else {
11362                                        while (it.hasNext()) {
11363                                                long iax = it.aLong;
11364                                                long ibx = it.bLong;
11365                                                int ox;
11366                                                ox = (int) toLong(Math.pow(iax, ibx));
11367                                                oai32data[it.oIndex] = ox;
11368                                                for (int j = 1; j < is; j++) {
11369                                                        iax = da.getElementLongAbs(it.aIndex + j);
11370                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11371                                                        ox = (int) toLong(Math.pow(iax, ibx));
11372                                                        oai32data[it.oIndex + j] = ox;
11373                                                }
11374                                        }
11375                                }
11376                        }
11377                        break;
11378                case Dataset.FLOAT32:
11379                        final float[] of32data = ((FloatDataset) result).getData();
11380                        if (it.isOutputDouble()) {
11381                                while (it.hasNext()) {
11382                                        final double iax = it.aDouble;
11383                                        final double ibx = it.bDouble;
11384                                        float ox;
11385                                        ox = (float) (Math.pow(iax, ibx));
11386                                        of32data[it.oIndex] = ox;
11387                                }
11388                        } else {
11389                                while (it.hasNext()) {
11390                                        final long iax = it.aLong;
11391                                        final long ibx = it.bLong;
11392                                        float ox;
11393                                        ox = (float) (Math.pow(iax, ibx));
11394                                        of32data[it.oIndex] = ox;
11395                                }
11396                        }
11397                        break;
11398                case Dataset.FLOAT64:
11399                        final double[] of64data = ((DoubleDataset) result).getData();
11400                        if (it.isOutputDouble()) {
11401                                while (it.hasNext()) {
11402                                        final double iax = it.aDouble;
11403                                        final double ibx = it.bDouble;
11404                                        double ox;
11405                                        ox = (Math.pow(iax, ibx));
11406                                        of64data[it.oIndex] = ox;
11407                                }
11408                        } else {
11409                                while (it.hasNext()) {
11410                                        final long iax = it.aLong;
11411                                        final long ibx = it.bLong;
11412                                        double ox;
11413                                        ox = (Math.pow(iax, ibx));
11414                                        of64data[it.oIndex] = ox;
11415                                }
11416                        }
11417                        break;
11418                case Dataset.ARRAYFLOAT32:
11419                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
11420                        if (is == 1) {
11421                                if (it.isOutputDouble()) {
11422                                        while (it.hasNext()) {
11423                                                final double iax = it.aDouble;
11424                                                final double ibx = it.bDouble;
11425                                                float ox;
11426                                                ox = (float) (Math.pow(iax, ibx));
11427                                                oaf32data[it.oIndex] = ox;
11428                                        }
11429                                } else {
11430                                        while (it.hasNext()) {
11431                                                final long iax = it.aLong;
11432                                                final long ibx = it.bLong;
11433                                                float ox;
11434                                                ox = (float) (Math.pow(iax, ibx));
11435                                                oaf32data[it.oIndex] = ox;
11436                                        }
11437                                }
11438                        } else if (as < bs) {
11439                                if (it.isOutputDouble()) {
11440                                        while (it.hasNext()) {
11441                                                final double iax = it.aDouble;
11442                                                double ibx = it.bDouble;
11443                                                float ox;
11444                                                ox = (float) (Math.pow(iax, ibx));
11445                                                oaf32data[it.oIndex] = ox;
11446                                                for (int j = 1; j < is; j++) {
11447                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11448                                                        ox = (float) (Math.pow(iax, ibx));
11449                                                        oaf32data[it.oIndex + j] = ox;
11450                                                }
11451                                        }
11452                                } else {
11453                                        while (it.hasNext()) {
11454                                                final long iax = it.aLong;
11455                                                long ibx = it.bLong;
11456                                                float ox;
11457                                                ox = (float) (Math.pow(iax, ibx));
11458                                                oaf32data[it.oIndex] = ox;
11459                                                for (int j = 1; j < is; j++) {
11460                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11461                                                        ox = (float) (Math.pow(iax, ibx));
11462                                                        oaf32data[it.oIndex + j] = ox;
11463                                                }
11464                                        }
11465                                }
11466                        } else if (as > bs) {
11467                                if (it.isOutputDouble()) {
11468                                        while (it.hasNext()) {
11469                                                double iax = it.aDouble;
11470                                                final double ibx = it.bDouble;
11471                                                float ox;
11472                                                ox = (float) (Math.pow(iax, ibx));
11473                                                oaf32data[it.oIndex] = ox;
11474                                                for (int j = 1; j < is; j++) {
11475                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11476                                                        ox = (float) (Math.pow(iax, ibx));
11477                                                        oaf32data[it.oIndex + j] = ox;
11478                                                }
11479                                        }
11480                                } else {
11481                                        while (it.hasNext()) {
11482                                                long iax = it.aLong;
11483                                                final long ibx = it.bLong;
11484                                                float ox;
11485                                                ox = (float) (Math.pow(iax, ibx));
11486                                                oaf32data[it.oIndex] = ox;
11487                                                for (int j = 1; j < is; j++) {
11488                                                        iax = da.getElementLongAbs(it.aIndex + j);
11489                                                        ox = (float) (Math.pow(iax, ibx));
11490                                                        oaf32data[it.oIndex + j] = ox;
11491                                                }
11492                                        }
11493                                }
11494                        } else if (as == 1) {
11495                                if (it.isOutputDouble()) {
11496                                        while (it.hasNext()) {
11497                                                final double iax = it.aDouble;
11498                                                final double ibx = it.bDouble;
11499                                                float ox;
11500                                                ox = (float) (Math.pow(iax, ibx));
11501                                                for (int j = 0; j < is; j++) {
11502                                                        oaf32data[it.oIndex + j] = ox;
11503                                                }
11504                                        }
11505                                } else {
11506                                        while (it.hasNext()) {
11507                                                final long iax = it.aLong;
11508                                                final long ibx = it.bLong;
11509                                                float ox;
11510                                                ox = (float) (Math.pow(iax, ibx));
11511                                                for (int j = 0; j < is; j++) {
11512                                                        oaf32data[it.oIndex + j] = ox;
11513                                                }
11514                                        }
11515                                }
11516                        } else {
11517                                if (it.isOutputDouble()) {
11518                                        while (it.hasNext()) {
11519                                                double iax = it.aDouble;
11520                                                double ibx = it.bDouble;
11521                                                float ox;
11522                                                ox = (float) (Math.pow(iax, ibx));
11523                                                oaf32data[it.oIndex] = ox;
11524                                                for (int j = 1; j < is; j++) {
11525                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11526                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11527                                                        ox = (float) (Math.pow(iax, ibx));
11528                                                        oaf32data[it.oIndex + j] = ox;
11529                                                }
11530                                        }
11531                                } else {
11532                                        while (it.hasNext()) {
11533                                                long iax = it.aLong;
11534                                                long ibx = it.bLong;
11535                                                float ox;
11536                                                ox = (float) (Math.pow(iax, ibx));
11537                                                oaf32data[it.oIndex] = ox;
11538                                                for (int j = 1; j < is; j++) {
11539                                                        iax = da.getElementLongAbs(it.aIndex + j);
11540                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11541                                                        ox = (float) (Math.pow(iax, ibx));
11542                                                        oaf32data[it.oIndex + j] = ox;
11543                                                }
11544                                        }
11545                                }
11546                        }
11547                        break;
11548                case Dataset.ARRAYFLOAT64:
11549                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
11550                        if (is == 1) {
11551                                if (it.isOutputDouble()) {
11552                                        while (it.hasNext()) {
11553                                                final double iax = it.aDouble;
11554                                                final double ibx = it.bDouble;
11555                                                double ox;
11556                                                ox = (Math.pow(iax, ibx));
11557                                                oaf64data[it.oIndex] = ox;
11558                                        }
11559                                } else {
11560                                        while (it.hasNext()) {
11561                                                final long iax = it.aLong;
11562                                                final long ibx = it.bLong;
11563                                                double ox;
11564                                                ox = (Math.pow(iax, ibx));
11565                                                oaf64data[it.oIndex] = ox;
11566                                        }
11567                                }
11568                        } else if (as < bs) {
11569                                if (it.isOutputDouble()) {
11570                                        while (it.hasNext()) {
11571                                                final double iax = it.aDouble;
11572                                                double ibx = it.bDouble;
11573                                                double ox;
11574                                                ox = (Math.pow(iax, ibx));
11575                                                oaf64data[it.oIndex] = ox;
11576                                                for (int j = 1; j < is; j++) {
11577                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11578                                                        ox = (Math.pow(iax, ibx));
11579                                                        oaf64data[it.oIndex + j] = ox;
11580                                                }
11581                                        }
11582                                } else {
11583                                        while (it.hasNext()) {
11584                                                final long iax = it.aLong;
11585                                                long ibx = it.bLong;
11586                                                double ox;
11587                                                ox = (Math.pow(iax, ibx));
11588                                                oaf64data[it.oIndex] = ox;
11589                                                for (int j = 1; j < is; j++) {
11590                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11591                                                        ox = (Math.pow(iax, ibx));
11592                                                        oaf64data[it.oIndex + j] = ox;
11593                                                }
11594                                        }
11595                                }
11596                        } else if (as > bs) {
11597                                if (it.isOutputDouble()) {
11598                                        while (it.hasNext()) {
11599                                                double iax = it.aDouble;
11600                                                final double ibx = it.bDouble;
11601                                                double ox;
11602                                                ox = (Math.pow(iax, ibx));
11603                                                oaf64data[it.oIndex] = ox;
11604                                                for (int j = 1; j < is; j++) {
11605                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11606                                                        ox = (Math.pow(iax, ibx));
11607                                                        oaf64data[it.oIndex + j] = ox;
11608                                                }
11609                                        }
11610                                } else {
11611                                        while (it.hasNext()) {
11612                                                long iax = it.aLong;
11613                                                final long ibx = it.bLong;
11614                                                double ox;
11615                                                ox = (Math.pow(iax, ibx));
11616                                                oaf64data[it.oIndex] = ox;
11617                                                for (int j = 1; j < is; j++) {
11618                                                        iax = da.getElementLongAbs(it.aIndex + j);
11619                                                        ox = (Math.pow(iax, ibx));
11620                                                        oaf64data[it.oIndex + j] = ox;
11621                                                }
11622                                        }
11623                                }
11624                        } else if (as == 1) {
11625                                if (it.isOutputDouble()) {
11626                                        while (it.hasNext()) {
11627                                                final double iax = it.aDouble;
11628                                                final double ibx = it.bDouble;
11629                                                double ox;
11630                                                ox = (Math.pow(iax, ibx));
11631                                                for (int j = 0; j < is; j++) {
11632                                                        oaf64data[it.oIndex + j] = ox;
11633                                                }
11634                                        }
11635                                } else {
11636                                        while (it.hasNext()) {
11637                                                final long iax = it.aLong;
11638                                                final long ibx = it.bLong;
11639                                                double ox;
11640                                                ox = (Math.pow(iax, ibx));
11641                                                for (int j = 0; j < is; j++) {
11642                                                        oaf64data[it.oIndex + j] = ox;
11643                                                }
11644                                        }
11645                                }
11646                        } else {
11647                                if (it.isOutputDouble()) {
11648                                        while (it.hasNext()) {
11649                                                double iax = it.aDouble;
11650                                                double ibx = it.bDouble;
11651                                                double ox;
11652                                                ox = (Math.pow(iax, ibx));
11653                                                oaf64data[it.oIndex] = ox;
11654                                                for (int j = 1; j < is; j++) {
11655                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11656                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11657                                                        ox = (Math.pow(iax, ibx));
11658                                                        oaf64data[it.oIndex + j] = ox;
11659                                                }
11660                                        }
11661                                } else {
11662                                        while (it.hasNext()) {
11663                                                long iax = it.aLong;
11664                                                long ibx = it.bLong;
11665                                                double ox;
11666                                                ox = (Math.pow(iax, ibx));
11667                                                oaf64data[it.oIndex] = ox;
11668                                                for (int j = 1; j < is; j++) {
11669                                                        iax = da.getElementLongAbs(it.aIndex + j);
11670                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11671                                                        ox = (Math.pow(iax, ibx));
11672                                                        oaf64data[it.oIndex + j] = ox;
11673                                                }
11674                                        }
11675                                }
11676                        }
11677                        break;
11678                case Dataset.COMPLEX64:
11679                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
11680                        if (!da.isComplex()) {
11681                                if (it.isOutputDouble()) {
11682                                        final double iay = 0;
11683                                        if (db.isComplex()) {
11684                                                while (it.hasNext()) {
11685                                                        final double iax = it.aDouble;
11686                                                        final double ibx = it.bDouble;
11687                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
11688                                                        Complex tz;
11689                                                        float ox;
11690                                                        float oy;
11691                                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11692                                                        ox = (float) (tz.getReal());
11693                                                        oy = (float) (tz.getImaginary());
11694                                                        oc64data[it.oIndex] = ox;
11695                                                        oc64data[it.oIndex + 1] = oy;
11696                                                }
11697                                        } else {
11698                                                while (it.hasNext()) {
11699                                                        final double iax = it.aDouble;
11700                                                        final double ibx = it.bDouble;
11701                                                        final double iby = 0;
11702                                                        Complex tz;
11703                                                        float ox;
11704                                                        float oy;
11705                                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11706                                                        ox = (float) (tz.getReal());
11707                                                        oy = (float) (tz.getImaginary());
11708                                                        oc64data[it.oIndex] = ox;
11709                                                        oc64data[it.oIndex + 1] = oy;
11710                                                }
11711                                        }
11712                                } else {
11713                                        final long iay = 0;
11714                                        while (it.hasNext()) {
11715                                                final long iax = it.aLong;
11716                                                final long ibx = it.bLong;
11717                                                final long iby = 0;
11718                                                Complex tz;
11719                                                float ox;
11720                                                float oy;
11721                                                tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11722                                                ox = (float) (tz.getReal());
11723                                                oy = (float) (tz.getImaginary());
11724                                                oc64data[it.oIndex] = ox;
11725                                                oc64data[it.oIndex + 1] = oy;
11726                                        }
11727                                }
11728                        } else if (!db.isComplex()) {
11729                                final double iby = 0;
11730                                while (it.hasNext()) {
11731                                        final double iax = it.aDouble;
11732                                        final double ibx = it.bDouble;
11733                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
11734                                        Complex tz;
11735                                        float ox;
11736                                        float oy;
11737                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11738                                        ox = (float) (tz.getReal());
11739                                        oy = (float) (tz.getImaginary());
11740                                        oc64data[it.oIndex] = ox;
11741                                        oc64data[it.oIndex + 1] = oy;
11742                                }
11743                        } else {
11744                                while (it.hasNext()) {
11745                                        final double iax = it.aDouble;
11746                                        final double ibx = it.bDouble;
11747                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
11748                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
11749                                        Complex tz;
11750                                        float ox;
11751                                        float oy;
11752                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11753                                        ox = (float) (tz.getReal());
11754                                        oy = (float) (tz.getImaginary());
11755                                        oc64data[it.oIndex] = ox;
11756                                        oc64data[it.oIndex + 1] = oy;
11757                                }
11758                        }
11759                        break;
11760                case Dataset.COMPLEX128:
11761                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
11762                        if (!da.isComplex()) {
11763                                if (it.isOutputDouble()) {
11764                                        final double iay = 0;
11765                                        if (db.isComplex()) {
11766                                                while (it.hasNext()) {
11767                                                        final double iax = it.aDouble;
11768                                                        final double ibx = it.bDouble;
11769                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
11770                                                        Complex tz;
11771                                                        double ox;
11772                                                        double oy;
11773                                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11774                                                        ox = (tz.getReal());
11775                                                        oy = (tz.getImaginary());
11776                                                        oc128data[it.oIndex] = ox;
11777                                                        oc128data[it.oIndex + 1] = oy;
11778                                                }
11779                                        } else {
11780                                                while (it.hasNext()) {
11781                                                        final double iax = it.aDouble;
11782                                                        final double ibx = it.bDouble;
11783                                                        final double iby = 0;
11784                                                        Complex tz;
11785                                                        double ox;
11786                                                        double oy;
11787                                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11788                                                        ox = (tz.getReal());
11789                                                        oy = (tz.getImaginary());
11790                                                        oc128data[it.oIndex] = ox;
11791                                                        oc128data[it.oIndex + 1] = oy;
11792                                                }
11793                                        }
11794                                } else {
11795                                        final long iay = 0;
11796                                        while (it.hasNext()) {
11797                                                final long iax = it.aLong;
11798                                                final long ibx = it.bLong;
11799                                                final long iby = 0;
11800                                                Complex tz;
11801                                                double ox;
11802                                                double oy;
11803                                                tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11804                                                ox = (tz.getReal());
11805                                                oy = (tz.getImaginary());
11806                                                oc128data[it.oIndex] = ox;
11807                                                oc128data[it.oIndex + 1] = oy;
11808                                        }
11809                                }
11810                        } else if (!db.isComplex()) {
11811                                final double iby = 0;
11812                                while (it.hasNext()) {
11813                                        final double iax = it.aDouble;
11814                                        final double ibx = it.bDouble;
11815                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
11816                                        Complex tz;
11817                                        double ox;
11818                                        double oy;
11819                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11820                                        ox = (tz.getReal());
11821                                        oy = (tz.getImaginary());
11822                                        oc128data[it.oIndex] = ox;
11823                                        oc128data[it.oIndex + 1] = oy;
11824                                }
11825                        } else {
11826                                while (it.hasNext()) {
11827                                        final double iax = it.aDouble;
11828                                        final double ibx = it.bDouble;
11829                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
11830                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
11831                                        Complex tz;
11832                                        double ox;
11833                                        double oy;
11834                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11835                                        ox = (tz.getReal());
11836                                        oy = (tz.getImaginary());
11837                                        oc128data[it.oIndex] = ox;
11838                                        oc128data[it.oIndex + 1] = oy;
11839                                }
11840                        }
11841                        break;
11842                default:
11843                        throw new IllegalArgumentException("power supports integer, compound integer, real, compound real, complex datasets only");
11844                }
11845
11846                addBinaryOperatorName(da, db, result, "**");
11847                return result;
11848        }
11849
11850        /**
11851         * remainder operator
11852         * @param a
11853         * @param b
11854         * @return {@code a % b}, remainder of division of a by b
11855         */
11856        public static Dataset remainder(final Object a, final Object b) {
11857                return remainder(a, b, null);
11858        }
11859
11860        /**
11861         * remainder operator
11862         * @param a
11863         * @param b
11864         * @param o output can be null - in which case, a new dataset is created
11865         * @return {@code a % b}, remainder of division of a by b
11866         */
11867        public static Dataset remainder(final Object a, final Object b, final Dataset o) {
11868                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
11869                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
11870                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
11871                final Dataset result = it.getOutput();
11872                if (!result.isComplex()) {
11873                        boolean change = false;
11874                        if (da.isComplex()) {
11875                                da = da.getRealView();
11876                                change = true;
11877                        }
11878                        if (db.isComplex()) {
11879                                db = db.getRealView();
11880                                change = true;
11881                        }
11882                        if (change) {
11883                                it = BroadcastIterator.createIterator(da, db, result, true);
11884                        }
11885                }
11886                final int is = result.getElementsPerItem();
11887                final int as = da.getElementsPerItem();
11888                final int bs = db.getElementsPerItem();
11889                final int dt = result.getDType();
11890
11891                switch(dt) {
11892                case Dataset.INT8:
11893                        final byte[] oi8data = ((ByteDataset) result).getData();
11894                        if (it.isOutputDouble()) {
11895                                while (it.hasNext()) {
11896                                        final double iax = it.aDouble;
11897                                        final double ibx = it.bDouble;
11898                                        byte ox;
11899                                        ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
11900                                        oi8data[it.oIndex] = ox;
11901                                }
11902                        } else {
11903                                while (it.hasNext()) {
11904                                        final long iax = it.aLong;
11905                                        final long ibx = it.bLong;
11906                                        byte ox;
11907                                        ox = (byte) (ibx == 0 ? 0 : iax % ibx);
11908                                        oi8data[it.oIndex] = ox;
11909                                }
11910                        }
11911                        break;
11912                case Dataset.INT16:
11913                        final short[] oi16data = ((ShortDataset) result).getData();
11914                        if (it.isOutputDouble()) {
11915                                while (it.hasNext()) {
11916                                        final double iax = it.aDouble;
11917                                        final double ibx = it.bDouble;
11918                                        short ox;
11919                                        ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
11920                                        oi16data[it.oIndex] = ox;
11921                                }
11922                        } else {
11923                                while (it.hasNext()) {
11924                                        final long iax = it.aLong;
11925                                        final long ibx = it.bLong;
11926                                        short ox;
11927                                        ox = (short) (ibx == 0 ? 0 : iax % ibx);
11928                                        oi16data[it.oIndex] = ox;
11929                                }
11930                        }
11931                        break;
11932                case Dataset.INT64:
11933                        final long[] oi64data = ((LongDataset) result).getData();
11934                        if (it.isOutputDouble()) {
11935                                while (it.hasNext()) {
11936                                        final double iax = it.aDouble;
11937                                        final double ibx = it.bDouble;
11938                                        long ox;
11939                                        ox = toLong(ibx == 0 ? 0 : iax % ibx);
11940                                        oi64data[it.oIndex] = ox;
11941                                }
11942                        } else {
11943                                while (it.hasNext()) {
11944                                        final long iax = it.aLong;
11945                                        final long ibx = it.bLong;
11946                                        long ox;
11947                                        ox = (ibx == 0 ? 0 : iax % ibx);
11948                                        oi64data[it.oIndex] = ox;
11949                                }
11950                        }
11951                        break;
11952                case Dataset.INT32:
11953                        final int[] oi32data = ((IntegerDataset) result).getData();
11954                        if (it.isOutputDouble()) {
11955                                while (it.hasNext()) {
11956                                        final double iax = it.aDouble;
11957                                        final double ibx = it.bDouble;
11958                                        int ox;
11959                                        ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
11960                                        oi32data[it.oIndex] = ox;
11961                                }
11962                        } else {
11963                                while (it.hasNext()) {
11964                                        final long iax = it.aLong;
11965                                        final long ibx = it.bLong;
11966                                        int ox;
11967                                        ox = (int) (ibx == 0 ? 0 : iax % ibx);
11968                                        oi32data[it.oIndex] = ox;
11969                                }
11970                        }
11971                        break;
11972                case Dataset.ARRAYINT8:
11973                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
11974                        if (is == 1) {
11975                                if (it.isOutputDouble()) {
11976                                        while (it.hasNext()) {
11977                                                final double iax = it.aDouble;
11978                                                final double ibx = it.bDouble;
11979                                                byte ox;
11980                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
11981                                                oai8data[it.oIndex] = ox;
11982                                        }
11983                                } else {
11984                                        while (it.hasNext()) {
11985                                                final long iax = it.aLong;
11986                                                final long ibx = it.bLong;
11987                                                byte ox;
11988                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
11989                                                oai8data[it.oIndex] = ox;
11990                                        }
11991                                }
11992                        } else if (as < bs) {
11993                                if (it.isOutputDouble()) {
11994                                        while (it.hasNext()) {
11995                                                final double iax = it.aDouble;
11996                                                double ibx = it.bDouble;
11997                                                byte ox;
11998                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
11999                                                oai8data[it.oIndex] = ox;
12000                                                for (int j = 1; j < is; j++) {
12001                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12002                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
12003                                                        oai8data[it.oIndex + j] = ox;
12004                                                }
12005                                        }
12006                                } else {
12007                                        while (it.hasNext()) {
12008                                                final long iax = it.aLong;
12009                                                long ibx = it.bLong;
12010                                                byte ox;
12011                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
12012                                                oai8data[it.oIndex] = ox;
12013                                                for (int j = 1; j < is; j++) {
12014                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12015                                                        ox = (byte) (ibx == 0 ? 0 : iax % ibx);
12016                                                        oai8data[it.oIndex + j] = ox;
12017                                                }
12018                                        }
12019                                }
12020                        } else if (as > bs) {
12021                                if (it.isOutputDouble()) {
12022                                        while (it.hasNext()) {
12023                                                double iax = it.aDouble;
12024                                                final double ibx = it.bDouble;
12025                                                byte ox;
12026                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
12027                                                oai8data[it.oIndex] = ox;
12028                                                for (int j = 1; j < is; j++) {
12029                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12030                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
12031                                                        oai8data[it.oIndex + j] = ox;
12032                                                }
12033                                        }
12034                                } else {
12035                                        while (it.hasNext()) {
12036                                                long iax = it.aLong;
12037                                                final long ibx = it.bLong;
12038                                                byte ox;
12039                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
12040                                                oai8data[it.oIndex] = ox;
12041                                                for (int j = 1; j < is; j++) {
12042                                                        iax = da.getElementLongAbs(it.aIndex + j);
12043                                                        ox = (byte) (ibx == 0 ? 0 : iax % ibx);
12044                                                        oai8data[it.oIndex + j] = ox;
12045                                                }
12046                                        }
12047                                }
12048                        } else if (as == 1) {
12049                                if (it.isOutputDouble()) {
12050                                        while (it.hasNext()) {
12051                                                final double iax = it.aDouble;
12052                                                final double ibx = it.bDouble;
12053                                                byte ox;
12054                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
12055                                                for (int j = 0; j < is; j++) {
12056                                                        oai8data[it.oIndex + j] = ox;
12057                                                }
12058                                        }
12059                                } else {
12060                                        while (it.hasNext()) {
12061                                                final long iax = it.aLong;
12062                                                final long ibx = it.bLong;
12063                                                byte ox;
12064                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
12065                                                for (int j = 0; j < is; j++) {
12066                                                        oai8data[it.oIndex + j] = ox;
12067                                                }
12068                                        }
12069                                }
12070                        } else {
12071                                if (it.isOutputDouble()) {
12072                                        while (it.hasNext()) {
12073                                                double iax = it.aDouble;
12074                                                double ibx = it.bDouble;
12075                                                byte ox;
12076                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
12077                                                oai8data[it.oIndex] = ox;
12078                                                for (int j = 1; j < is; j++) {
12079                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12080                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12081                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
12082                                                        oai8data[it.oIndex + j] = ox;
12083                                                }
12084                                        }
12085                                } else {
12086                                        while (it.hasNext()) {
12087                                                long iax = it.aLong;
12088                                                long ibx = it.bLong;
12089                                                byte ox;
12090                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
12091                                                oai8data[it.oIndex] = ox;
12092                                                for (int j = 1; j < is; j++) {
12093                                                        iax = da.getElementLongAbs(it.aIndex + j);
12094                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12095                                                        ox = (byte) (ibx == 0 ? 0 : iax % ibx);
12096                                                        oai8data[it.oIndex + j] = ox;
12097                                                }
12098                                        }
12099                                }
12100                        }
12101                        break;
12102                case Dataset.ARRAYINT16:
12103                        final short[] oai16data = ((CompoundShortDataset) result).getData();
12104                        if (is == 1) {
12105                                if (it.isOutputDouble()) {
12106                                        while (it.hasNext()) {
12107                                                final double iax = it.aDouble;
12108                                                final double ibx = it.bDouble;
12109                                                short ox;
12110                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
12111                                                oai16data[it.oIndex] = ox;
12112                                        }
12113                                } else {
12114                                        while (it.hasNext()) {
12115                                                final long iax = it.aLong;
12116                                                final long ibx = it.bLong;
12117                                                short ox;
12118                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
12119                                                oai16data[it.oIndex] = ox;
12120                                        }
12121                                }
12122                        } else if (as < bs) {
12123                                if (it.isOutputDouble()) {
12124                                        while (it.hasNext()) {
12125                                                final double iax = it.aDouble;
12126                                                double ibx = it.bDouble;
12127                                                short ox;
12128                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
12129                                                oai16data[it.oIndex] = ox;
12130                                                for (int j = 1; j < is; j++) {
12131                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12132                                                        ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
12133                                                        oai16data[it.oIndex + j] = ox;
12134                                                }
12135                                        }
12136                                } else {
12137                                        while (it.hasNext()) {
12138                                                final long iax = it.aLong;
12139                                                long ibx = it.bLong;
12140                                                short ox;
12141                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
12142                                                oai16data[it.oIndex] = ox;
12143                                                for (int j = 1; j < is; j++) {
12144                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12145                                                        ox = (short) (ibx == 0 ? 0 : iax % ibx);
12146                                                        oai16data[it.oIndex + j] = ox;
12147                                                }
12148                                        }
12149                                }
12150                        } else if (as > bs) {
12151                                if (it.isOutputDouble()) {
12152                                        while (it.hasNext()) {
12153                                                double iax = it.aDouble;
12154                                                final double ibx = it.bDouble;
12155                                                short ox;
12156                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
12157                                                oai16data[it.oIndex] = ox;
12158                                                for (int j = 1; j < is; j++) {
12159                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12160                                                        ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
12161                                                        oai16data[it.oIndex + j] = ox;
12162                                                }
12163                                        }
12164                                } else {
12165                                        while (it.hasNext()) {
12166                                                long iax = it.aLong;
12167                                                final long ibx = it.bLong;
12168                                                short ox;
12169                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
12170                                                oai16data[it.oIndex] = ox;
12171                                                for (int j = 1; j < is; j++) {
12172                                                        iax = da.getElementLongAbs(it.aIndex + j);
12173                                                        ox = (short) (ibx == 0 ? 0 : iax % ibx);
12174                                                        oai16data[it.oIndex + j] = ox;
12175                                                }
12176                                        }
12177                                }
12178                        } else if (as == 1) {
12179                                if (it.isOutputDouble()) {
12180                                        while (it.hasNext()) {
12181                                                final double iax = it.aDouble;
12182                                                final double ibx = it.bDouble;
12183                                                short ox;
12184                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
12185                                                for (int j = 0; j < is; j++) {
12186                                                        oai16data[it.oIndex + j] = ox;
12187                                                }
12188                                        }
12189                                } else {
12190                                        while (it.hasNext()) {
12191                                                final long iax = it.aLong;
12192                                                final long ibx = it.bLong;
12193                                                short ox;
12194                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
12195                                                for (int j = 0; j < is; j++) {
12196                                                        oai16data[it.oIndex + j] = ox;
12197                                                }
12198                                        }
12199                                }
12200                        } else {
12201                                if (it.isOutputDouble()) {
12202                                        while (it.hasNext()) {
12203                                                double iax = it.aDouble;
12204                                                double ibx = it.bDouble;
12205                                                short ox;
12206                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
12207                                                oai16data[it.oIndex] = ox;
12208                                                for (int j = 1; j < is; j++) {
12209                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12210                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12211                                                        ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
12212                                                        oai16data[it.oIndex + j] = ox;
12213                                                }
12214                                        }
12215                                } else {
12216                                        while (it.hasNext()) {
12217                                                long iax = it.aLong;
12218                                                long ibx = it.bLong;
12219                                                short ox;
12220                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
12221                                                oai16data[it.oIndex] = ox;
12222                                                for (int j = 1; j < is; j++) {
12223                                                        iax = da.getElementLongAbs(it.aIndex + j);
12224                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12225                                                        ox = (short) (ibx == 0 ? 0 : iax % ibx);
12226                                                        oai16data[it.oIndex + j] = ox;
12227                                                }
12228                                        }
12229                                }
12230                        }
12231                        break;
12232                case Dataset.ARRAYINT64:
12233                        final long[] oai64data = ((CompoundLongDataset) result).getData();
12234                        if (is == 1) {
12235                                if (it.isOutputDouble()) {
12236                                        while (it.hasNext()) {
12237                                                final double iax = it.aDouble;
12238                                                final double ibx = it.bDouble;
12239                                                long ox;
12240                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
12241                                                oai64data[it.oIndex] = ox;
12242                                        }
12243                                } else {
12244                                        while (it.hasNext()) {
12245                                                final long iax = it.aLong;
12246                                                final long ibx = it.bLong;
12247                                                long ox;
12248                                                ox = (ibx == 0 ? 0 : iax % ibx);
12249                                                oai64data[it.oIndex] = ox;
12250                                        }
12251                                }
12252                        } else if (as < bs) {
12253                                if (it.isOutputDouble()) {
12254                                        while (it.hasNext()) {
12255                                                final double iax = it.aDouble;
12256                                                double ibx = it.bDouble;
12257                                                long ox;
12258                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
12259                                                oai64data[it.oIndex] = ox;
12260                                                for (int j = 1; j < is; j++) {
12261                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12262                                                        ox = toLong(ibx == 0 ? 0 : iax % ibx);
12263                                                        oai64data[it.oIndex + j] = ox;
12264                                                }
12265                                        }
12266                                } else {
12267                                        while (it.hasNext()) {
12268                                                final long iax = it.aLong;
12269                                                long ibx = it.bLong;
12270                                                long ox;
12271                                                ox = (ibx == 0 ? 0 : iax % ibx);
12272                                                oai64data[it.oIndex] = ox;
12273                                                for (int j = 1; j < is; j++) {
12274                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12275                                                        ox = (ibx == 0 ? 0 : iax % ibx);
12276                                                        oai64data[it.oIndex + j] = ox;
12277                                                }
12278                                        }
12279                                }
12280                        } else if (as > bs) {
12281                                if (it.isOutputDouble()) {
12282                                        while (it.hasNext()) {
12283                                                double iax = it.aDouble;
12284                                                final double ibx = it.bDouble;
12285                                                long ox;
12286                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
12287                                                oai64data[it.oIndex] = ox;
12288                                                for (int j = 1; j < is; j++) {
12289                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12290                                                        ox = toLong(ibx == 0 ? 0 : iax % ibx);
12291                                                        oai64data[it.oIndex + j] = ox;
12292                                                }
12293                                        }
12294                                } else {
12295                                        while (it.hasNext()) {
12296                                                long iax = it.aLong;
12297                                                final long ibx = it.bLong;
12298                                                long ox;
12299                                                ox = (ibx == 0 ? 0 : iax % ibx);
12300                                                oai64data[it.oIndex] = ox;
12301                                                for (int j = 1; j < is; j++) {
12302                                                        iax = da.getElementLongAbs(it.aIndex + j);
12303                                                        ox = (ibx == 0 ? 0 : iax % ibx);
12304                                                        oai64data[it.oIndex + j] = ox;
12305                                                }
12306                                        }
12307                                }
12308                        } else if (as == 1) {
12309                                if (it.isOutputDouble()) {
12310                                        while (it.hasNext()) {
12311                                                final double iax = it.aDouble;
12312                                                final double ibx = it.bDouble;
12313                                                long ox;
12314                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
12315                                                for (int j = 0; j < is; j++) {
12316                                                        oai64data[it.oIndex + j] = ox;
12317                                                }
12318                                        }
12319                                } else {
12320                                        while (it.hasNext()) {
12321                                                final long iax = it.aLong;
12322                                                final long ibx = it.bLong;
12323                                                long ox;
12324                                                ox = (ibx == 0 ? 0 : iax % ibx);
12325                                                for (int j = 0; j < is; j++) {
12326                                                        oai64data[it.oIndex + j] = ox;
12327                                                }
12328                                        }
12329                                }
12330                        } else {
12331                                if (it.isOutputDouble()) {
12332                                        while (it.hasNext()) {
12333                                                double iax = it.aDouble;
12334                                                double ibx = it.bDouble;
12335                                                long ox;
12336                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
12337                                                oai64data[it.oIndex] = ox;
12338                                                for (int j = 1; j < is; j++) {
12339                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12340                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12341                                                        ox = toLong(ibx == 0 ? 0 : iax % ibx);
12342                                                        oai64data[it.oIndex + j] = ox;
12343                                                }
12344                                        }
12345                                } else {
12346                                        while (it.hasNext()) {
12347                                                long iax = it.aLong;
12348                                                long ibx = it.bLong;
12349                                                long ox;
12350                                                ox = (ibx == 0 ? 0 : iax % ibx);
12351                                                oai64data[it.oIndex] = ox;
12352                                                for (int j = 1; j < is; j++) {
12353                                                        iax = da.getElementLongAbs(it.aIndex + j);
12354                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12355                                                        ox = (ibx == 0 ? 0 : iax % ibx);
12356                                                        oai64data[it.oIndex + j] = ox;
12357                                                }
12358                                        }
12359                                }
12360                        }
12361                        break;
12362                case Dataset.ARRAYINT32:
12363                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
12364                        if (is == 1) {
12365                                if (it.isOutputDouble()) {
12366                                        while (it.hasNext()) {
12367                                                final double iax = it.aDouble;
12368                                                final double ibx = it.bDouble;
12369                                                int ox;
12370                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12371                                                oai32data[it.oIndex] = ox;
12372                                        }
12373                                } else {
12374                                        while (it.hasNext()) {
12375                                                final long iax = it.aLong;
12376                                                final long ibx = it.bLong;
12377                                                int ox;
12378                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
12379                                                oai32data[it.oIndex] = ox;
12380                                        }
12381                                }
12382                        } else if (as < bs) {
12383                                if (it.isOutputDouble()) {
12384                                        while (it.hasNext()) {
12385                                                final double iax = it.aDouble;
12386                                                double ibx = it.bDouble;
12387                                                int ox;
12388                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12389                                                oai32data[it.oIndex] = ox;
12390                                                for (int j = 1; j < is; j++) {
12391                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12392                                                        ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12393                                                        oai32data[it.oIndex + j] = ox;
12394                                                }
12395                                        }
12396                                } else {
12397                                        while (it.hasNext()) {
12398                                                final long iax = it.aLong;
12399                                                long ibx = it.bLong;
12400                                                int ox;
12401                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
12402                                                oai32data[it.oIndex] = ox;
12403                                                for (int j = 1; j < is; j++) {
12404                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12405                                                        ox = (int) (ibx == 0 ? 0 : iax % ibx);
12406                                                        oai32data[it.oIndex + j] = ox;
12407                                                }
12408                                        }
12409                                }
12410                        } else if (as > bs) {
12411                                if (it.isOutputDouble()) {
12412                                        while (it.hasNext()) {
12413                                                double iax = it.aDouble;
12414                                                final double ibx = it.bDouble;
12415                                                int ox;
12416                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12417                                                oai32data[it.oIndex] = ox;
12418                                                for (int j = 1; j < is; j++) {
12419                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12420                                                        ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12421                                                        oai32data[it.oIndex + j] = ox;
12422                                                }
12423                                        }
12424                                } else {
12425                                        while (it.hasNext()) {
12426                                                long iax = it.aLong;
12427                                                final long ibx = it.bLong;
12428                                                int ox;
12429                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
12430                                                oai32data[it.oIndex] = ox;
12431                                                for (int j = 1; j < is; j++) {
12432                                                        iax = da.getElementLongAbs(it.aIndex + j);
12433                                                        ox = (int) (ibx == 0 ? 0 : iax % ibx);
12434                                                        oai32data[it.oIndex + j] = ox;
12435                                                }
12436                                        }
12437                                }
12438                        } else if (as == 1) {
12439                                if (it.isOutputDouble()) {
12440                                        while (it.hasNext()) {
12441                                                final double iax = it.aDouble;
12442                                                final double ibx = it.bDouble;
12443                                                int ox;
12444                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12445                                                for (int j = 0; j < is; j++) {
12446                                                        oai32data[it.oIndex + j] = ox;
12447                                                }
12448                                        }
12449                                } else {
12450                                        while (it.hasNext()) {
12451                                                final long iax = it.aLong;
12452                                                final long ibx = it.bLong;
12453                                                int ox;
12454                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
12455                                                for (int j = 0; j < is; j++) {
12456                                                        oai32data[it.oIndex + j] = ox;
12457                                                }
12458                                        }
12459                                }
12460                        } else {
12461                                if (it.isOutputDouble()) {
12462                                        while (it.hasNext()) {
12463                                                double iax = it.aDouble;
12464                                                double ibx = it.bDouble;
12465                                                int ox;
12466                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12467                                                oai32data[it.oIndex] = ox;
12468                                                for (int j = 1; j < is; j++) {
12469                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12470                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12471                                                        ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12472                                                        oai32data[it.oIndex + j] = ox;
12473                                                }
12474                                        }
12475                                } else {
12476                                        while (it.hasNext()) {
12477                                                long iax = it.aLong;
12478                                                long ibx = it.bLong;
12479                                                int ox;
12480                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
12481                                                oai32data[it.oIndex] = ox;
12482                                                for (int j = 1; j < is; j++) {
12483                                                        iax = da.getElementLongAbs(it.aIndex + j);
12484                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12485                                                        ox = (int) (ibx == 0 ? 0 : iax % ibx);
12486                                                        oai32data[it.oIndex + j] = ox;
12487                                                }
12488                                        }
12489                                }
12490                        }
12491                        break;
12492                case Dataset.FLOAT32:
12493                        final float[] of32data = ((FloatDataset) result).getData();
12494                        if (it.isOutputDouble()) {
12495                                while (it.hasNext()) {
12496                                        final double iax = it.aDouble;
12497                                        final double ibx = it.bDouble;
12498                                        float ox;
12499                                        ox = (float) (iax % ibx);
12500                                        of32data[it.oIndex] = ox;
12501                                }
12502                        } else {
12503                                while (it.hasNext()) {
12504                                        final long iax = it.aLong;
12505                                        final long ibx = it.bLong;
12506                                        float ox;
12507                                        ox = (iax % ibx);
12508                                        of32data[it.oIndex] = ox;
12509                                }
12510                        }
12511                        break;
12512                case Dataset.FLOAT64:
12513                        final double[] of64data = ((DoubleDataset) result).getData();
12514                        if (it.isOutputDouble()) {
12515                                while (it.hasNext()) {
12516                                        final double iax = it.aDouble;
12517                                        final double ibx = it.bDouble;
12518                                        double ox;
12519                                        ox = (iax % ibx);
12520                                        of64data[it.oIndex] = ox;
12521                                }
12522                        } else {
12523                                while (it.hasNext()) {
12524                                        final long iax = it.aLong;
12525                                        final long ibx = it.bLong;
12526                                        double ox;
12527                                        ox = (iax % ibx);
12528                                        of64data[it.oIndex] = ox;
12529                                }
12530                        }
12531                        break;
12532                case Dataset.ARRAYFLOAT32:
12533                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
12534                        if (is == 1) {
12535                                if (it.isOutputDouble()) {
12536                                        while (it.hasNext()) {
12537                                                final double iax = it.aDouble;
12538                                                final double ibx = it.bDouble;
12539                                                float ox;
12540                                                ox = (float) (iax % ibx);
12541                                                oaf32data[it.oIndex] = ox;
12542                                        }
12543                                } else {
12544                                        while (it.hasNext()) {
12545                                                final long iax = it.aLong;
12546                                                final long ibx = it.bLong;
12547                                                float ox;
12548                                                ox = (iax % ibx);
12549                                                oaf32data[it.oIndex] = ox;
12550                                        }
12551                                }
12552                        } else if (as < bs) {
12553                                if (it.isOutputDouble()) {
12554                                        while (it.hasNext()) {
12555                                                final double iax = it.aDouble;
12556                                                double ibx = it.bDouble;
12557                                                float ox;
12558                                                ox = (float) (iax % ibx);
12559                                                oaf32data[it.oIndex] = ox;
12560                                                for (int j = 1; j < is; j++) {
12561                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12562                                                        ox = (float) (iax % ibx);
12563                                                        oaf32data[it.oIndex + j] = ox;
12564                                                }
12565                                        }
12566                                } else {
12567                                        while (it.hasNext()) {
12568                                                final long iax = it.aLong;
12569                                                long ibx = it.bLong;
12570                                                float ox;
12571                                                ox = (iax % ibx);
12572                                                oaf32data[it.oIndex] = ox;
12573                                                for (int j = 1; j < is; j++) {
12574                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12575                                                        ox = (iax % ibx);
12576                                                        oaf32data[it.oIndex + j] = ox;
12577                                                }
12578                                        }
12579                                }
12580                        } else if (as > bs) {
12581                                if (it.isOutputDouble()) {
12582                                        while (it.hasNext()) {
12583                                                double iax = it.aDouble;
12584                                                final double ibx = it.bDouble;
12585                                                float ox;
12586                                                ox = (float) (iax % ibx);
12587                                                oaf32data[it.oIndex] = ox;
12588                                                for (int j = 1; j < is; j++) {
12589                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12590                                                        ox = (float) (iax % ibx);
12591                                                        oaf32data[it.oIndex + j] = ox;
12592                                                }
12593                                        }
12594                                } else {
12595                                        while (it.hasNext()) {
12596                                                long iax = it.aLong;
12597                                                final long ibx = it.bLong;
12598                                                float ox;
12599                                                ox = (iax % ibx);
12600                                                oaf32data[it.oIndex] = ox;
12601                                                for (int j = 1; j < is; j++) {
12602                                                        iax = da.getElementLongAbs(it.aIndex + j);
12603                                                        ox = (iax % ibx);
12604                                                        oaf32data[it.oIndex + j] = ox;
12605                                                }
12606                                        }
12607                                }
12608                        } else if (as == 1) {
12609                                if (it.isOutputDouble()) {
12610                                        while (it.hasNext()) {
12611                                                final double iax = it.aDouble;
12612                                                final double ibx = it.bDouble;
12613                                                float ox;
12614                                                ox = (float) (iax % ibx);
12615                                                for (int j = 0; j < is; j++) {
12616                                                        oaf32data[it.oIndex + j] = ox;
12617                                                }
12618                                        }
12619                                } else {
12620                                        while (it.hasNext()) {
12621                                                final long iax = it.aLong;
12622                                                final long ibx = it.bLong;
12623                                                float ox;
12624                                                ox = (iax % ibx);
12625                                                for (int j = 0; j < is; j++) {
12626                                                        oaf32data[it.oIndex + j] = ox;
12627                                                }
12628                                        }
12629                                }
12630                        } else {
12631                                if (it.isOutputDouble()) {
12632                                        while (it.hasNext()) {
12633                                                double iax = it.aDouble;
12634                                                double ibx = it.bDouble;
12635                                                float ox;
12636                                                ox = (float) (iax % ibx);
12637                                                oaf32data[it.oIndex] = ox;
12638                                                for (int j = 1; j < is; j++) {
12639                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12640                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12641                                                        ox = (float) (iax % ibx);
12642                                                        oaf32data[it.oIndex + j] = ox;
12643                                                }
12644                                        }
12645                                } else {
12646                                        while (it.hasNext()) {
12647                                                long iax = it.aLong;
12648                                                long ibx = it.bLong;
12649                                                float ox;
12650                                                ox = (iax % ibx);
12651                                                oaf32data[it.oIndex] = ox;
12652                                                for (int j = 1; j < is; j++) {
12653                                                        iax = da.getElementLongAbs(it.aIndex + j);
12654                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12655                                                        ox = (iax % ibx);
12656                                                        oaf32data[it.oIndex + j] = ox;
12657                                                }
12658                                        }
12659                                }
12660                        }
12661                        break;
12662                case Dataset.ARRAYFLOAT64:
12663                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
12664                        if (is == 1) {
12665                                if (it.isOutputDouble()) {
12666                                        while (it.hasNext()) {
12667                                                final double iax = it.aDouble;
12668                                                final double ibx = it.bDouble;
12669                                                double ox;
12670                                                ox = (iax % ibx);
12671                                                oaf64data[it.oIndex] = ox;
12672                                        }
12673                                } else {
12674                                        while (it.hasNext()) {
12675                                                final long iax = it.aLong;
12676                                                final long ibx = it.bLong;
12677                                                double ox;
12678                                                ox = (iax % ibx);
12679                                                oaf64data[it.oIndex] = ox;
12680                                        }
12681                                }
12682                        } else if (as < bs) {
12683                                if (it.isOutputDouble()) {
12684                                        while (it.hasNext()) {
12685                                                final double iax = it.aDouble;
12686                                                double ibx = it.bDouble;
12687                                                double ox;
12688                                                ox = (iax % ibx);
12689                                                oaf64data[it.oIndex] = ox;
12690                                                for (int j = 1; j < is; j++) {
12691                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12692                                                        ox = (iax % ibx);
12693                                                        oaf64data[it.oIndex + j] = ox;
12694                                                }
12695                                        }
12696                                } else {
12697                                        while (it.hasNext()) {
12698                                                final long iax = it.aLong;
12699                                                long ibx = it.bLong;
12700                                                double ox;
12701                                                ox = (iax % ibx);
12702                                                oaf64data[it.oIndex] = ox;
12703                                                for (int j = 1; j < is; j++) {
12704                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12705                                                        ox = (iax % ibx);
12706                                                        oaf64data[it.oIndex + j] = ox;
12707                                                }
12708                                        }
12709                                }
12710                        } else if (as > bs) {
12711                                if (it.isOutputDouble()) {
12712                                        while (it.hasNext()) {
12713                                                double iax = it.aDouble;
12714                                                final double ibx = it.bDouble;
12715                                                double ox;
12716                                                ox = (iax % ibx);
12717                                                oaf64data[it.oIndex] = ox;
12718                                                for (int j = 1; j < is; j++) {
12719                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12720                                                        ox = (iax % ibx);
12721                                                        oaf64data[it.oIndex + j] = ox;
12722                                                }
12723                                        }
12724                                } else {
12725                                        while (it.hasNext()) {
12726                                                long iax = it.aLong;
12727                                                final long ibx = it.bLong;
12728                                                double ox;
12729                                                ox = (iax % ibx);
12730                                                oaf64data[it.oIndex] = ox;
12731                                                for (int j = 1; j < is; j++) {
12732                                                        iax = da.getElementLongAbs(it.aIndex + j);
12733                                                        ox = (iax % ibx);
12734                                                        oaf64data[it.oIndex + j] = ox;
12735                                                }
12736                                        }
12737                                }
12738                        } else if (as == 1) {
12739                                if (it.isOutputDouble()) {
12740                                        while (it.hasNext()) {
12741                                                final double iax = it.aDouble;
12742                                                final double ibx = it.bDouble;
12743                                                double ox;
12744                                                ox = (iax % ibx);
12745                                                for (int j = 0; j < is; j++) {
12746                                                        oaf64data[it.oIndex + j] = ox;
12747                                                }
12748                                        }
12749                                } else {
12750                                        while (it.hasNext()) {
12751                                                final long iax = it.aLong;
12752                                                final long ibx = it.bLong;
12753                                                double ox;
12754                                                ox = (iax % ibx);
12755                                                for (int j = 0; j < is; j++) {
12756                                                        oaf64data[it.oIndex + j] = ox;
12757                                                }
12758                                        }
12759                                }
12760                        } else {
12761                                if (it.isOutputDouble()) {
12762                                        while (it.hasNext()) {
12763                                                double iax = it.aDouble;
12764                                                double ibx = it.bDouble;
12765                                                double ox;
12766                                                ox = (iax % ibx);
12767                                                oaf64data[it.oIndex] = ox;
12768                                                for (int j = 1; j < is; j++) {
12769                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12770                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12771                                                        ox = (iax % ibx);
12772                                                        oaf64data[it.oIndex + j] = ox;
12773                                                }
12774                                        }
12775                                } else {
12776                                        while (it.hasNext()) {
12777                                                long iax = it.aLong;
12778                                                long ibx = it.bLong;
12779                                                double ox;
12780                                                ox = (iax % ibx);
12781                                                oaf64data[it.oIndex] = ox;
12782                                                for (int j = 1; j < is; j++) {
12783                                                        iax = da.getElementLongAbs(it.aIndex + j);
12784                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12785                                                        ox = (iax % ibx);
12786                                                        oaf64data[it.oIndex + j] = ox;
12787                                                }
12788                                        }
12789                                }
12790                        }
12791                        break;
12792                default:
12793                        throw new IllegalArgumentException("remainder supports integer, compound integer, real, compound real datasets only");
12794                }
12795
12796                addBinaryOperatorName(da, db, result, "%");
12797                return result;
12798        }
12799
12800        /**
12801         * maximum operator
12802         * @param a
12803         * @param b
12804         * @return return maximum of a and b
12805         */
12806        public static Dataset maximum(final Object a, final Object b) {
12807                return maximum(a, b, null);
12808        }
12809
12810        /**
12811         * maximum operator
12812         * @param a
12813         * @param b
12814         * @param o output can be null - in which case, a new dataset is created
12815         * @return return maximum of a and b
12816         */
12817        public static Dataset maximum(final Object a, final Object b, final Dataset o) {
12818                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
12819                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
12820                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
12821                final Dataset result = it.getOutput();
12822                if (!result.isComplex()) {
12823                        boolean change = false;
12824                        if (da.isComplex()) {
12825                                da = da.getRealView();
12826                                change = true;
12827                        }
12828                        if (db.isComplex()) {
12829                                db = db.getRealView();
12830                                change = true;
12831                        }
12832                        if (change) {
12833                                it = BroadcastIterator.createIterator(da, db, result, true);
12834                        }
12835                }
12836                final int is = result.getElementsPerItem();
12837                final int as = da.getElementsPerItem();
12838                final int bs = db.getElementsPerItem();
12839                final int dt = result.getDType();
12840
12841                switch(dt) {
12842                case Dataset.INT8:
12843                        final byte[] oi8data = ((ByteDataset) result).getData();
12844                        if (it.isOutputDouble()) {
12845                                while (it.hasNext()) {
12846                                        final double iax = it.aDouble;
12847                                        final double ibx = it.bDouble;
12848                                        byte ox;
12849                                        ox = (byte) toLong(Math.max(iax, ibx));
12850                                        oi8data[it.oIndex] = ox;
12851                                }
12852                        } else {
12853                                while (it.hasNext()) {
12854                                        final long iax = it.aLong;
12855                                        final long ibx = it.bLong;
12856                                        byte ox;
12857                                        ox = (byte) toLong(Math.max(iax, ibx));
12858                                        oi8data[it.oIndex] = ox;
12859                                }
12860                        }
12861                        break;
12862                case Dataset.INT16:
12863                        final short[] oi16data = ((ShortDataset) result).getData();
12864                        if (it.isOutputDouble()) {
12865                                while (it.hasNext()) {
12866                                        final double iax = it.aDouble;
12867                                        final double ibx = it.bDouble;
12868                                        short ox;
12869                                        ox = (short) toLong(Math.max(iax, ibx));
12870                                        oi16data[it.oIndex] = ox;
12871                                }
12872                        } else {
12873                                while (it.hasNext()) {
12874                                        final long iax = it.aLong;
12875                                        final long ibx = it.bLong;
12876                                        short ox;
12877                                        ox = (short) toLong(Math.max(iax, ibx));
12878                                        oi16data[it.oIndex] = ox;
12879                                }
12880                        }
12881                        break;
12882                case Dataset.INT64:
12883                        final long[] oi64data = ((LongDataset) result).getData();
12884                        if (it.isOutputDouble()) {
12885                                while (it.hasNext()) {
12886                                        final double iax = it.aDouble;
12887                                        final double ibx = it.bDouble;
12888                                        long ox;
12889                                        ox = toLong(Math.max(iax, ibx));
12890                                        oi64data[it.oIndex] = ox;
12891                                }
12892                        } else {
12893                                while (it.hasNext()) {
12894                                        final long iax = it.aLong;
12895                                        final long ibx = it.bLong;
12896                                        long ox;
12897                                        ox = toLong(Math.max(iax, ibx));
12898                                        oi64data[it.oIndex] = ox;
12899                                }
12900                        }
12901                        break;
12902                case Dataset.INT32:
12903                        final int[] oi32data = ((IntegerDataset) result).getData();
12904                        if (it.isOutputDouble()) {
12905                                while (it.hasNext()) {
12906                                        final double iax = it.aDouble;
12907                                        final double ibx = it.bDouble;
12908                                        int ox;
12909                                        ox = (int) toLong(Math.max(iax, ibx));
12910                                        oi32data[it.oIndex] = ox;
12911                                }
12912                        } else {
12913                                while (it.hasNext()) {
12914                                        final long iax = it.aLong;
12915                                        final long ibx = it.bLong;
12916                                        int ox;
12917                                        ox = (int) toLong(Math.max(iax, ibx));
12918                                        oi32data[it.oIndex] = ox;
12919                                }
12920                        }
12921                        break;
12922                case Dataset.ARRAYINT8:
12923                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
12924                        if (is == 1) {
12925                                if (it.isOutputDouble()) {
12926                                        while (it.hasNext()) {
12927                                                final double iax = it.aDouble;
12928                                                final double ibx = it.bDouble;
12929                                                byte ox;
12930                                                ox = (byte) toLong(Math.max(iax, ibx));
12931                                                oai8data[it.oIndex] = ox;
12932                                        }
12933                                } else {
12934                                        while (it.hasNext()) {
12935                                                final long iax = it.aLong;
12936                                                final long ibx = it.bLong;
12937                                                byte ox;
12938                                                ox = (byte) toLong(Math.max(iax, ibx));
12939                                                oai8data[it.oIndex] = ox;
12940                                        }
12941                                }
12942                        } else if (as < bs) {
12943                                if (it.isOutputDouble()) {
12944                                        while (it.hasNext()) {
12945                                                final double iax = it.aDouble;
12946                                                double ibx = it.bDouble;
12947                                                byte ox;
12948                                                ox = (byte) toLong(Math.max(iax, ibx));
12949                                                oai8data[it.oIndex] = ox;
12950                                                for (int j = 1; j < is; j++) {
12951                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12952                                                        ox = (byte) toLong(Math.max(iax, ibx));
12953                                                        oai8data[it.oIndex + j] = ox;
12954                                                }
12955                                        }
12956                                } else {
12957                                        while (it.hasNext()) {
12958                                                final long iax = it.aLong;
12959                                                long ibx = it.bLong;
12960                                                byte ox;
12961                                                ox = (byte) toLong(Math.max(iax, ibx));
12962                                                oai8data[it.oIndex] = ox;
12963                                                for (int j = 1; j < is; j++) {
12964                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12965                                                        ox = (byte) toLong(Math.max(iax, ibx));
12966                                                        oai8data[it.oIndex + j] = ox;
12967                                                }
12968                                        }
12969                                }
12970                        } else if (as > bs) {
12971                                if (it.isOutputDouble()) {
12972                                        while (it.hasNext()) {
12973                                                double iax = it.aDouble;
12974                                                final double ibx = it.bDouble;
12975                                                byte ox;
12976                                                ox = (byte) toLong(Math.max(iax, ibx));
12977                                                oai8data[it.oIndex] = ox;
12978                                                for (int j = 1; j < is; j++) {
12979                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12980                                                        ox = (byte) toLong(Math.max(iax, ibx));
12981                                                        oai8data[it.oIndex + j] = ox;
12982                                                }
12983                                        }
12984                                } else {
12985                                        while (it.hasNext()) {
12986                                                long iax = it.aLong;
12987                                                final long ibx = it.bLong;
12988                                                byte ox;
12989                                                ox = (byte) toLong(Math.max(iax, ibx));
12990                                                oai8data[it.oIndex] = ox;
12991                                                for (int j = 1; j < is; j++) {
12992                                                        iax = da.getElementLongAbs(it.aIndex + j);
12993                                                        ox = (byte) toLong(Math.max(iax, ibx));
12994                                                        oai8data[it.oIndex + j] = ox;
12995                                                }
12996                                        }
12997                                }
12998                        } else if (as == 1) {
12999                                if (it.isOutputDouble()) {
13000                                        while (it.hasNext()) {
13001                                                final double iax = it.aDouble;
13002                                                final double ibx = it.bDouble;
13003                                                byte ox;
13004                                                ox = (byte) toLong(Math.max(iax, ibx));
13005                                                for (int j = 0; j < is; j++) {
13006                                                        oai8data[it.oIndex + j] = ox;
13007                                                }
13008                                        }
13009                                } else {
13010                                        while (it.hasNext()) {
13011                                                final long iax = it.aLong;
13012                                                final long ibx = it.bLong;
13013                                                byte ox;
13014                                                ox = (byte) toLong(Math.max(iax, ibx));
13015                                                for (int j = 0; j < is; j++) {
13016                                                        oai8data[it.oIndex + j] = ox;
13017                                                }
13018                                        }
13019                                }
13020                        } else {
13021                                if (it.isOutputDouble()) {
13022                                        while (it.hasNext()) {
13023                                                double iax = it.aDouble;
13024                                                double ibx = it.bDouble;
13025                                                byte ox;
13026                                                ox = (byte) toLong(Math.max(iax, ibx));
13027                                                oai8data[it.oIndex] = ox;
13028                                                for (int j = 1; j < is; j++) {
13029                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13030                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13031                                                        ox = (byte) toLong(Math.max(iax, ibx));
13032                                                        oai8data[it.oIndex + j] = ox;
13033                                                }
13034                                        }
13035                                } else {
13036                                        while (it.hasNext()) {
13037                                                long iax = it.aLong;
13038                                                long ibx = it.bLong;
13039                                                byte ox;
13040                                                ox = (byte) toLong(Math.max(iax, ibx));
13041                                                oai8data[it.oIndex] = ox;
13042                                                for (int j = 1; j < is; j++) {
13043                                                        iax = da.getElementLongAbs(it.aIndex + j);
13044                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13045                                                        ox = (byte) toLong(Math.max(iax, ibx));
13046                                                        oai8data[it.oIndex + j] = ox;
13047                                                }
13048                                        }
13049                                }
13050                        }
13051                        break;
13052                case Dataset.ARRAYINT16:
13053                        final short[] oai16data = ((CompoundShortDataset) result).getData();
13054                        if (is == 1) {
13055                                if (it.isOutputDouble()) {
13056                                        while (it.hasNext()) {
13057                                                final double iax = it.aDouble;
13058                                                final double ibx = it.bDouble;
13059                                                short ox;
13060                                                ox = (short) toLong(Math.max(iax, ibx));
13061                                                oai16data[it.oIndex] = ox;
13062                                        }
13063                                } else {
13064                                        while (it.hasNext()) {
13065                                                final long iax = it.aLong;
13066                                                final long ibx = it.bLong;
13067                                                short ox;
13068                                                ox = (short) toLong(Math.max(iax, ibx));
13069                                                oai16data[it.oIndex] = ox;
13070                                        }
13071                                }
13072                        } else if (as < bs) {
13073                                if (it.isOutputDouble()) {
13074                                        while (it.hasNext()) {
13075                                                final double iax = it.aDouble;
13076                                                double ibx = it.bDouble;
13077                                                short ox;
13078                                                ox = (short) toLong(Math.max(iax, ibx));
13079                                                oai16data[it.oIndex] = ox;
13080                                                for (int j = 1; j < is; j++) {
13081                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13082                                                        ox = (short) toLong(Math.max(iax, ibx));
13083                                                        oai16data[it.oIndex + j] = ox;
13084                                                }
13085                                        }
13086                                } else {
13087                                        while (it.hasNext()) {
13088                                                final long iax = it.aLong;
13089                                                long ibx = it.bLong;
13090                                                short ox;
13091                                                ox = (short) toLong(Math.max(iax, ibx));
13092                                                oai16data[it.oIndex] = ox;
13093                                                for (int j = 1; j < is; j++) {
13094                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13095                                                        ox = (short) toLong(Math.max(iax, ibx));
13096                                                        oai16data[it.oIndex + j] = ox;
13097                                                }
13098                                        }
13099                                }
13100                        } else if (as > bs) {
13101                                if (it.isOutputDouble()) {
13102                                        while (it.hasNext()) {
13103                                                double iax = it.aDouble;
13104                                                final double ibx = it.bDouble;
13105                                                short ox;
13106                                                ox = (short) toLong(Math.max(iax, ibx));
13107                                                oai16data[it.oIndex] = ox;
13108                                                for (int j = 1; j < is; j++) {
13109                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13110                                                        ox = (short) toLong(Math.max(iax, ibx));
13111                                                        oai16data[it.oIndex + j] = ox;
13112                                                }
13113                                        }
13114                                } else {
13115                                        while (it.hasNext()) {
13116                                                long iax = it.aLong;
13117                                                final long ibx = it.bLong;
13118                                                short ox;
13119                                                ox = (short) toLong(Math.max(iax, ibx));
13120                                                oai16data[it.oIndex] = ox;
13121                                                for (int j = 1; j < is; j++) {
13122                                                        iax = da.getElementLongAbs(it.aIndex + j);
13123                                                        ox = (short) toLong(Math.max(iax, ibx));
13124                                                        oai16data[it.oIndex + j] = ox;
13125                                                }
13126                                        }
13127                                }
13128                        } else if (as == 1) {
13129                                if (it.isOutputDouble()) {
13130                                        while (it.hasNext()) {
13131                                                final double iax = it.aDouble;
13132                                                final double ibx = it.bDouble;
13133                                                short ox;
13134                                                ox = (short) toLong(Math.max(iax, ibx));
13135                                                for (int j = 0; j < is; j++) {
13136                                                        oai16data[it.oIndex + j] = ox;
13137                                                }
13138                                        }
13139                                } else {
13140                                        while (it.hasNext()) {
13141                                                final long iax = it.aLong;
13142                                                final long ibx = it.bLong;
13143                                                short ox;
13144                                                ox = (short) toLong(Math.max(iax, ibx));
13145                                                for (int j = 0; j < is; j++) {
13146                                                        oai16data[it.oIndex + j] = ox;
13147                                                }
13148                                        }
13149                                }
13150                        } else {
13151                                if (it.isOutputDouble()) {
13152                                        while (it.hasNext()) {
13153                                                double iax = it.aDouble;
13154                                                double ibx = it.bDouble;
13155                                                short ox;
13156                                                ox = (short) toLong(Math.max(iax, ibx));
13157                                                oai16data[it.oIndex] = ox;
13158                                                for (int j = 1; j < is; j++) {
13159                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13160                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13161                                                        ox = (short) toLong(Math.max(iax, ibx));
13162                                                        oai16data[it.oIndex + j] = ox;
13163                                                }
13164                                        }
13165                                } else {
13166                                        while (it.hasNext()) {
13167                                                long iax = it.aLong;
13168                                                long ibx = it.bLong;
13169                                                short ox;
13170                                                ox = (short) toLong(Math.max(iax, ibx));
13171                                                oai16data[it.oIndex] = ox;
13172                                                for (int j = 1; j < is; j++) {
13173                                                        iax = da.getElementLongAbs(it.aIndex + j);
13174                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13175                                                        ox = (short) toLong(Math.max(iax, ibx));
13176                                                        oai16data[it.oIndex + j] = ox;
13177                                                }
13178                                        }
13179                                }
13180                        }
13181                        break;
13182                case Dataset.ARRAYINT64:
13183                        final long[] oai64data = ((CompoundLongDataset) result).getData();
13184                        if (is == 1) {
13185                                if (it.isOutputDouble()) {
13186                                        while (it.hasNext()) {
13187                                                final double iax = it.aDouble;
13188                                                final double ibx = it.bDouble;
13189                                                long ox;
13190                                                ox = toLong(Math.max(iax, ibx));
13191                                                oai64data[it.oIndex] = ox;
13192                                        }
13193                                } else {
13194                                        while (it.hasNext()) {
13195                                                final long iax = it.aLong;
13196                                                final long ibx = it.bLong;
13197                                                long ox;
13198                                                ox = toLong(Math.max(iax, ibx));
13199                                                oai64data[it.oIndex] = ox;
13200                                        }
13201                                }
13202                        } else if (as < bs) {
13203                                if (it.isOutputDouble()) {
13204                                        while (it.hasNext()) {
13205                                                final double iax = it.aDouble;
13206                                                double ibx = it.bDouble;
13207                                                long ox;
13208                                                ox = toLong(Math.max(iax, ibx));
13209                                                oai64data[it.oIndex] = ox;
13210                                                for (int j = 1; j < is; j++) {
13211                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13212                                                        ox = toLong(Math.max(iax, ibx));
13213                                                        oai64data[it.oIndex + j] = ox;
13214                                                }
13215                                        }
13216                                } else {
13217                                        while (it.hasNext()) {
13218                                                final long iax = it.aLong;
13219                                                long ibx = it.bLong;
13220                                                long ox;
13221                                                ox = toLong(Math.max(iax, ibx));
13222                                                oai64data[it.oIndex] = ox;
13223                                                for (int j = 1; j < is; j++) {
13224                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13225                                                        ox = toLong(Math.max(iax, ibx));
13226                                                        oai64data[it.oIndex + j] = ox;
13227                                                }
13228                                        }
13229                                }
13230                        } else if (as > bs) {
13231                                if (it.isOutputDouble()) {
13232                                        while (it.hasNext()) {
13233                                                double iax = it.aDouble;
13234                                                final double ibx = it.bDouble;
13235                                                long ox;
13236                                                ox = toLong(Math.max(iax, ibx));
13237                                                oai64data[it.oIndex] = ox;
13238                                                for (int j = 1; j < is; j++) {
13239                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13240                                                        ox = toLong(Math.max(iax, ibx));
13241                                                        oai64data[it.oIndex + j] = ox;
13242                                                }
13243                                        }
13244                                } else {
13245                                        while (it.hasNext()) {
13246                                                long iax = it.aLong;
13247                                                final long ibx = it.bLong;
13248                                                long ox;
13249                                                ox = toLong(Math.max(iax, ibx));
13250                                                oai64data[it.oIndex] = ox;
13251                                                for (int j = 1; j < is; j++) {
13252                                                        iax = da.getElementLongAbs(it.aIndex + j);
13253                                                        ox = toLong(Math.max(iax, ibx));
13254                                                        oai64data[it.oIndex + j] = ox;
13255                                                }
13256                                        }
13257                                }
13258                        } else if (as == 1) {
13259                                if (it.isOutputDouble()) {
13260                                        while (it.hasNext()) {
13261                                                final double iax = it.aDouble;
13262                                                final double ibx = it.bDouble;
13263                                                long ox;
13264                                                ox = toLong(Math.max(iax, ibx));
13265                                                for (int j = 0; j < is; j++) {
13266                                                        oai64data[it.oIndex + j] = ox;
13267                                                }
13268                                        }
13269                                } else {
13270                                        while (it.hasNext()) {
13271                                                final long iax = it.aLong;
13272                                                final long ibx = it.bLong;
13273                                                long ox;
13274                                                ox = toLong(Math.max(iax, ibx));
13275                                                for (int j = 0; j < is; j++) {
13276                                                        oai64data[it.oIndex + j] = ox;
13277                                                }
13278                                        }
13279                                }
13280                        } else {
13281                                if (it.isOutputDouble()) {
13282                                        while (it.hasNext()) {
13283                                                double iax = it.aDouble;
13284                                                double ibx = it.bDouble;
13285                                                long ox;
13286                                                ox = toLong(Math.max(iax, ibx));
13287                                                oai64data[it.oIndex] = ox;
13288                                                for (int j = 1; j < is; j++) {
13289                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13290                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13291                                                        ox = toLong(Math.max(iax, ibx));
13292                                                        oai64data[it.oIndex + j] = ox;
13293                                                }
13294                                        }
13295                                } else {
13296                                        while (it.hasNext()) {
13297                                                long iax = it.aLong;
13298                                                long ibx = it.bLong;
13299                                                long ox;
13300                                                ox = toLong(Math.max(iax, ibx));
13301                                                oai64data[it.oIndex] = ox;
13302                                                for (int j = 1; j < is; j++) {
13303                                                        iax = da.getElementLongAbs(it.aIndex + j);
13304                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13305                                                        ox = toLong(Math.max(iax, ibx));
13306                                                        oai64data[it.oIndex + j] = ox;
13307                                                }
13308                                        }
13309                                }
13310                        }
13311                        break;
13312                case Dataset.ARRAYINT32:
13313                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
13314                        if (is == 1) {
13315                                if (it.isOutputDouble()) {
13316                                        while (it.hasNext()) {
13317                                                final double iax = it.aDouble;
13318                                                final double ibx = it.bDouble;
13319                                                int ox;
13320                                                ox = (int) toLong(Math.max(iax, ibx));
13321                                                oai32data[it.oIndex] = ox;
13322                                        }
13323                                } else {
13324                                        while (it.hasNext()) {
13325                                                final long iax = it.aLong;
13326                                                final long ibx = it.bLong;
13327                                                int ox;
13328                                                ox = (int) toLong(Math.max(iax, ibx));
13329                                                oai32data[it.oIndex] = ox;
13330                                        }
13331                                }
13332                        } else if (as < bs) {
13333                                if (it.isOutputDouble()) {
13334                                        while (it.hasNext()) {
13335                                                final double iax = it.aDouble;
13336                                                double ibx = it.bDouble;
13337                                                int ox;
13338                                                ox = (int) toLong(Math.max(iax, ibx));
13339                                                oai32data[it.oIndex] = ox;
13340                                                for (int j = 1; j < is; j++) {
13341                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13342                                                        ox = (int) toLong(Math.max(iax, ibx));
13343                                                        oai32data[it.oIndex + j] = ox;
13344                                                }
13345                                        }
13346                                } else {
13347                                        while (it.hasNext()) {
13348                                                final long iax = it.aLong;
13349                                                long ibx = it.bLong;
13350                                                int ox;
13351                                                ox = (int) toLong(Math.max(iax, ibx));
13352                                                oai32data[it.oIndex] = ox;
13353                                                for (int j = 1; j < is; j++) {
13354                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13355                                                        ox = (int) toLong(Math.max(iax, ibx));
13356                                                        oai32data[it.oIndex + j] = ox;
13357                                                }
13358                                        }
13359                                }
13360                        } else if (as > bs) {
13361                                if (it.isOutputDouble()) {
13362                                        while (it.hasNext()) {
13363                                                double iax = it.aDouble;
13364                                                final double ibx = it.bDouble;
13365                                                int ox;
13366                                                ox = (int) toLong(Math.max(iax, ibx));
13367                                                oai32data[it.oIndex] = ox;
13368                                                for (int j = 1; j < is; j++) {
13369                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13370                                                        ox = (int) toLong(Math.max(iax, ibx));
13371                                                        oai32data[it.oIndex + j] = ox;
13372                                                }
13373                                        }
13374                                } else {
13375                                        while (it.hasNext()) {
13376                                                long iax = it.aLong;
13377                                                final long ibx = it.bLong;
13378                                                int ox;
13379                                                ox = (int) toLong(Math.max(iax, ibx));
13380                                                oai32data[it.oIndex] = ox;
13381                                                for (int j = 1; j < is; j++) {
13382                                                        iax = da.getElementLongAbs(it.aIndex + j);
13383                                                        ox = (int) toLong(Math.max(iax, ibx));
13384                                                        oai32data[it.oIndex + j] = ox;
13385                                                }
13386                                        }
13387                                }
13388                        } else if (as == 1) {
13389                                if (it.isOutputDouble()) {
13390                                        while (it.hasNext()) {
13391                                                final double iax = it.aDouble;
13392                                                final double ibx = it.bDouble;
13393                                                int ox;
13394                                                ox = (int) toLong(Math.max(iax, ibx));
13395                                                for (int j = 0; j < is; j++) {
13396                                                        oai32data[it.oIndex + j] = ox;
13397                                                }
13398                                        }
13399                                } else {
13400                                        while (it.hasNext()) {
13401                                                final long iax = it.aLong;
13402                                                final long ibx = it.bLong;
13403                                                int ox;
13404                                                ox = (int) toLong(Math.max(iax, ibx));
13405                                                for (int j = 0; j < is; j++) {
13406                                                        oai32data[it.oIndex + j] = ox;
13407                                                }
13408                                        }
13409                                }
13410                        } else {
13411                                if (it.isOutputDouble()) {
13412                                        while (it.hasNext()) {
13413                                                double iax = it.aDouble;
13414                                                double ibx = it.bDouble;
13415                                                int ox;
13416                                                ox = (int) toLong(Math.max(iax, ibx));
13417                                                oai32data[it.oIndex] = ox;
13418                                                for (int j = 1; j < is; j++) {
13419                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13420                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13421                                                        ox = (int) toLong(Math.max(iax, ibx));
13422                                                        oai32data[it.oIndex + j] = ox;
13423                                                }
13424                                        }
13425                                } else {
13426                                        while (it.hasNext()) {
13427                                                long iax = it.aLong;
13428                                                long ibx = it.bLong;
13429                                                int ox;
13430                                                ox = (int) toLong(Math.max(iax, ibx));
13431                                                oai32data[it.oIndex] = ox;
13432                                                for (int j = 1; j < is; j++) {
13433                                                        iax = da.getElementLongAbs(it.aIndex + j);
13434                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13435                                                        ox = (int) toLong(Math.max(iax, ibx));
13436                                                        oai32data[it.oIndex + j] = ox;
13437                                                }
13438                                        }
13439                                }
13440                        }
13441                        break;
13442                case Dataset.FLOAT32:
13443                        final float[] of32data = ((FloatDataset) result).getData();
13444                        if (it.isOutputDouble()) {
13445                                while (it.hasNext()) {
13446                                        final double iax = it.aDouble;
13447                                        final double ibx = it.bDouble;
13448                                        float ox;
13449                                        ox = (float) (Math.max(iax, ibx));
13450                                        of32data[it.oIndex] = ox;
13451                                }
13452                        } else {
13453                                while (it.hasNext()) {
13454                                        final long iax = it.aLong;
13455                                        final long ibx = it.bLong;
13456                                        float ox;
13457                                        ox = (float) (Math.max(iax, ibx));
13458                                        of32data[it.oIndex] = ox;
13459                                }
13460                        }
13461                        break;
13462                case Dataset.FLOAT64:
13463                        final double[] of64data = ((DoubleDataset) result).getData();
13464                        if (it.isOutputDouble()) {
13465                                while (it.hasNext()) {
13466                                        final double iax = it.aDouble;
13467                                        final double ibx = it.bDouble;
13468                                        double ox;
13469                                        ox = (Math.max(iax, ibx));
13470                                        of64data[it.oIndex] = ox;
13471                                }
13472                        } else {
13473                                while (it.hasNext()) {
13474                                        final long iax = it.aLong;
13475                                        final long ibx = it.bLong;
13476                                        double ox;
13477                                        ox = (Math.max(iax, ibx));
13478                                        of64data[it.oIndex] = ox;
13479                                }
13480                        }
13481                        break;
13482                case Dataset.ARRAYFLOAT32:
13483                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
13484                        if (is == 1) {
13485                                if (it.isOutputDouble()) {
13486                                        while (it.hasNext()) {
13487                                                final double iax = it.aDouble;
13488                                                final double ibx = it.bDouble;
13489                                                float ox;
13490                                                ox = (float) (Math.max(iax, ibx));
13491                                                oaf32data[it.oIndex] = ox;
13492                                        }
13493                                } else {
13494                                        while (it.hasNext()) {
13495                                                final long iax = it.aLong;
13496                                                final long ibx = it.bLong;
13497                                                float ox;
13498                                                ox = (float) (Math.max(iax, ibx));
13499                                                oaf32data[it.oIndex] = ox;
13500                                        }
13501                                }
13502                        } else if (as < bs) {
13503                                if (it.isOutputDouble()) {
13504                                        while (it.hasNext()) {
13505                                                final double iax = it.aDouble;
13506                                                double ibx = it.bDouble;
13507                                                float ox;
13508                                                ox = (float) (Math.max(iax, ibx));
13509                                                oaf32data[it.oIndex] = ox;
13510                                                for (int j = 1; j < is; j++) {
13511                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13512                                                        ox = (float) (Math.max(iax, ibx));
13513                                                        oaf32data[it.oIndex + j] = ox;
13514                                                }
13515                                        }
13516                                } else {
13517                                        while (it.hasNext()) {
13518                                                final long iax = it.aLong;
13519                                                long ibx = it.bLong;
13520                                                float ox;
13521                                                ox = (float) (Math.max(iax, ibx));
13522                                                oaf32data[it.oIndex] = ox;
13523                                                for (int j = 1; j < is; j++) {
13524                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13525                                                        ox = (float) (Math.max(iax, ibx));
13526                                                        oaf32data[it.oIndex + j] = ox;
13527                                                }
13528                                        }
13529                                }
13530                        } else if (as > bs) {
13531                                if (it.isOutputDouble()) {
13532                                        while (it.hasNext()) {
13533                                                double iax = it.aDouble;
13534                                                final double ibx = it.bDouble;
13535                                                float ox;
13536                                                ox = (float) (Math.max(iax, ibx));
13537                                                oaf32data[it.oIndex] = ox;
13538                                                for (int j = 1; j < is; j++) {
13539                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13540                                                        ox = (float) (Math.max(iax, ibx));
13541                                                        oaf32data[it.oIndex + j] = ox;
13542                                                }
13543                                        }
13544                                } else {
13545                                        while (it.hasNext()) {
13546                                                long iax = it.aLong;
13547                                                final long ibx = it.bLong;
13548                                                float ox;
13549                                                ox = (float) (Math.max(iax, ibx));
13550                                                oaf32data[it.oIndex] = ox;
13551                                                for (int j = 1; j < is; j++) {
13552                                                        iax = da.getElementLongAbs(it.aIndex + j);
13553                                                        ox = (float) (Math.max(iax, ibx));
13554                                                        oaf32data[it.oIndex + j] = ox;
13555                                                }
13556                                        }
13557                                }
13558                        } else if (as == 1) {
13559                                if (it.isOutputDouble()) {
13560                                        while (it.hasNext()) {
13561                                                final double iax = it.aDouble;
13562                                                final double ibx = it.bDouble;
13563                                                float ox;
13564                                                ox = (float) (Math.max(iax, ibx));
13565                                                for (int j = 0; j < is; j++) {
13566                                                        oaf32data[it.oIndex + j] = ox;
13567                                                }
13568                                        }
13569                                } else {
13570                                        while (it.hasNext()) {
13571                                                final long iax = it.aLong;
13572                                                final long ibx = it.bLong;
13573                                                float ox;
13574                                                ox = (float) (Math.max(iax, ibx));
13575                                                for (int j = 0; j < is; j++) {
13576                                                        oaf32data[it.oIndex + j] = ox;
13577                                                }
13578                                        }
13579                                }
13580                        } else {
13581                                if (it.isOutputDouble()) {
13582                                        while (it.hasNext()) {
13583                                                double iax = it.aDouble;
13584                                                double ibx = it.bDouble;
13585                                                float ox;
13586                                                ox = (float) (Math.max(iax, ibx));
13587                                                oaf32data[it.oIndex] = ox;
13588                                                for (int j = 1; j < is; j++) {
13589                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13590                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13591                                                        ox = (float) (Math.max(iax, ibx));
13592                                                        oaf32data[it.oIndex + j] = ox;
13593                                                }
13594                                        }
13595                                } else {
13596                                        while (it.hasNext()) {
13597                                                long iax = it.aLong;
13598                                                long ibx = it.bLong;
13599                                                float ox;
13600                                                ox = (float) (Math.max(iax, ibx));
13601                                                oaf32data[it.oIndex] = ox;
13602                                                for (int j = 1; j < is; j++) {
13603                                                        iax = da.getElementLongAbs(it.aIndex + j);
13604                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13605                                                        ox = (float) (Math.max(iax, ibx));
13606                                                        oaf32data[it.oIndex + j] = ox;
13607                                                }
13608                                        }
13609                                }
13610                        }
13611                        break;
13612                case Dataset.ARRAYFLOAT64:
13613                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
13614                        if (is == 1) {
13615                                if (it.isOutputDouble()) {
13616                                        while (it.hasNext()) {
13617                                                final double iax = it.aDouble;
13618                                                final double ibx = it.bDouble;
13619                                                double ox;
13620                                                ox = (Math.max(iax, ibx));
13621                                                oaf64data[it.oIndex] = ox;
13622                                        }
13623                                } else {
13624                                        while (it.hasNext()) {
13625                                                final long iax = it.aLong;
13626                                                final long ibx = it.bLong;
13627                                                double ox;
13628                                                ox = (Math.max(iax, ibx));
13629                                                oaf64data[it.oIndex] = ox;
13630                                        }
13631                                }
13632                        } else if (as < bs) {
13633                                if (it.isOutputDouble()) {
13634                                        while (it.hasNext()) {
13635                                                final double iax = it.aDouble;
13636                                                double ibx = it.bDouble;
13637                                                double ox;
13638                                                ox = (Math.max(iax, ibx));
13639                                                oaf64data[it.oIndex] = ox;
13640                                                for (int j = 1; j < is; j++) {
13641                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13642                                                        ox = (Math.max(iax, ibx));
13643                                                        oaf64data[it.oIndex + j] = ox;
13644                                                }
13645                                        }
13646                                } else {
13647                                        while (it.hasNext()) {
13648                                                final long iax = it.aLong;
13649                                                long ibx = it.bLong;
13650                                                double ox;
13651                                                ox = (Math.max(iax, ibx));
13652                                                oaf64data[it.oIndex] = ox;
13653                                                for (int j = 1; j < is; j++) {
13654                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13655                                                        ox = (Math.max(iax, ibx));
13656                                                        oaf64data[it.oIndex + j] = ox;
13657                                                }
13658                                        }
13659                                }
13660                        } else if (as > bs) {
13661                                if (it.isOutputDouble()) {
13662                                        while (it.hasNext()) {
13663                                                double iax = it.aDouble;
13664                                                final double ibx = it.bDouble;
13665                                                double ox;
13666                                                ox = (Math.max(iax, ibx));
13667                                                oaf64data[it.oIndex] = ox;
13668                                                for (int j = 1; j < is; j++) {
13669                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13670                                                        ox = (Math.max(iax, ibx));
13671                                                        oaf64data[it.oIndex + j] = ox;
13672                                                }
13673                                        }
13674                                } else {
13675                                        while (it.hasNext()) {
13676                                                long iax = it.aLong;
13677                                                final long ibx = it.bLong;
13678                                                double ox;
13679                                                ox = (Math.max(iax, ibx));
13680                                                oaf64data[it.oIndex] = ox;
13681                                                for (int j = 1; j < is; j++) {
13682                                                        iax = da.getElementLongAbs(it.aIndex + j);
13683                                                        ox = (Math.max(iax, ibx));
13684                                                        oaf64data[it.oIndex + j] = ox;
13685                                                }
13686                                        }
13687                                }
13688                        } else if (as == 1) {
13689                                if (it.isOutputDouble()) {
13690                                        while (it.hasNext()) {
13691                                                final double iax = it.aDouble;
13692                                                final double ibx = it.bDouble;
13693                                                double ox;
13694                                                ox = (Math.max(iax, ibx));
13695                                                for (int j = 0; j < is; j++) {
13696                                                        oaf64data[it.oIndex + j] = ox;
13697                                                }
13698                                        }
13699                                } else {
13700                                        while (it.hasNext()) {
13701                                                final long iax = it.aLong;
13702                                                final long ibx = it.bLong;
13703                                                double ox;
13704                                                ox = (Math.max(iax, ibx));
13705                                                for (int j = 0; j < is; j++) {
13706                                                        oaf64data[it.oIndex + j] = ox;
13707                                                }
13708                                        }
13709                                }
13710                        } else {
13711                                if (it.isOutputDouble()) {
13712                                        while (it.hasNext()) {
13713                                                double iax = it.aDouble;
13714                                                double ibx = it.bDouble;
13715                                                double ox;
13716                                                ox = (Math.max(iax, ibx));
13717                                                oaf64data[it.oIndex] = ox;
13718                                                for (int j = 1; j < is; j++) {
13719                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13720                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13721                                                        ox = (Math.max(iax, ibx));
13722                                                        oaf64data[it.oIndex + j] = ox;
13723                                                }
13724                                        }
13725                                } else {
13726                                        while (it.hasNext()) {
13727                                                long iax = it.aLong;
13728                                                long ibx = it.bLong;
13729                                                double ox;
13730                                                ox = (Math.max(iax, ibx));
13731                                                oaf64data[it.oIndex] = ox;
13732                                                for (int j = 1; j < is; j++) {
13733                                                        iax = da.getElementLongAbs(it.aIndex + j);
13734                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13735                                                        ox = (Math.max(iax, ibx));
13736                                                        oaf64data[it.oIndex + j] = ox;
13737                                                }
13738                                        }
13739                                }
13740                        }
13741                        break;
13742                case Dataset.COMPLEX64:
13743                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
13744                        if (!da.isComplex()) {
13745                                if (it.isOutputDouble()) {
13746                                        final double iay = 0;
13747                                        if (db.isComplex()) {
13748                                                while (it.hasNext()) {
13749                                                        final double iax = it.aDouble;
13750                                                        final double ibx = it.bDouble;
13751                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
13752                                                        float ox;
13753                                                        float oy;
13754                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13755                                                                ox = (float) (iax);
13756                                                                oy = (float) (iay);
13757                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13758                                                                ox = (float) (ibx);
13759                                                                oy = (float) (iby);
13760                                                        } else {
13761                                                                ox = (float) (Math.max(iax, ibx));
13762                                                                oy = (float) (Math.max(iay, iby));
13763                                                        }
13764                                                        oc64data[it.oIndex] = ox;
13765                                                        oc64data[it.oIndex + 1] = oy;
13766                                                }
13767                                        } else {
13768                                                while (it.hasNext()) {
13769                                                        final double iax = it.aDouble;
13770                                                        final double ibx = it.bDouble;
13771                                                        final double iby = 0;
13772                                                        float ox;
13773                                                        float oy;
13774                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13775                                                                ox = (float) (iax);
13776                                                                oy = (float) (iay);
13777                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13778                                                                ox = (float) (ibx);
13779                                                                oy = (float) (iby);
13780                                                        } else {
13781                                                                ox = (float) (Math.max(iax, ibx));
13782                                                                oy = (float) (Math.max(iay, iby));
13783                                                        }
13784                                                        oc64data[it.oIndex] = ox;
13785                                                        oc64data[it.oIndex + 1] = oy;
13786                                                }
13787                                        }
13788                                } else {
13789                                        final long iay = 0;
13790                                        while (it.hasNext()) {
13791                                                final long iax = it.aLong;
13792                                                final long ibx = it.bLong;
13793                                                final long iby = 0;
13794                                                float ox;
13795                                                float oy;
13796                                                if (Double.isNaN(iax) || Double.isNaN(iay)) {
13797                                                        ox = (float) (iax);
13798                                                        oy = (float) (iay);
13799                                                } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13800                                                        ox = (float) (ibx);
13801                                                        oy = (float) (iby);
13802                                                } else {
13803                                                        ox = (float) (Math.max(iax, ibx));
13804                                                        oy = (float) (Math.max(iay, iby));
13805                                                }
13806                                                oc64data[it.oIndex] = ox;
13807                                                oc64data[it.oIndex + 1] = oy;
13808                                        }
13809                                }
13810                        } else if (!db.isComplex()) {
13811                                final double iby = 0;
13812                                while (it.hasNext()) {
13813                                        final double iax = it.aDouble;
13814                                        final double ibx = it.bDouble;
13815                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
13816                                        float ox;
13817                                        float oy;
13818                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13819                                                ox = (float) (iax);
13820                                                oy = (float) (iay);
13821                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13822                                                ox = (float) (ibx);
13823                                                oy = (float) (iby);
13824                                        } else {
13825                                                ox = (float) (Math.max(iax, ibx));
13826                                                oy = (float) (Math.max(iay, iby));
13827                                        }
13828                                        oc64data[it.oIndex] = ox;
13829                                        oc64data[it.oIndex + 1] = oy;
13830                                }
13831                        } else {
13832                                while (it.hasNext()) {
13833                                        final double iax = it.aDouble;
13834                                        final double ibx = it.bDouble;
13835                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
13836                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
13837                                        float ox;
13838                                        float oy;
13839                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13840                                                ox = (float) (iax);
13841                                                oy = (float) (iay);
13842                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13843                                                ox = (float) (ibx);
13844                                                oy = (float) (iby);
13845                                        } else {
13846                                                ox = (float) (Math.max(iax, ibx));
13847                                                oy = (float) (Math.max(iay, iby));
13848                                        }
13849                                        oc64data[it.oIndex] = ox;
13850                                        oc64data[it.oIndex + 1] = oy;
13851                                }
13852                        }
13853                        break;
13854                case Dataset.COMPLEX128:
13855                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
13856                        if (!da.isComplex()) {
13857                                if (it.isOutputDouble()) {
13858                                        final double iay = 0;
13859                                        if (db.isComplex()) {
13860                                                while (it.hasNext()) {
13861                                                        final double iax = it.aDouble;
13862                                                        final double ibx = it.bDouble;
13863                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
13864                                                        double ox;
13865                                                        double oy;
13866                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13867                                                                ox = (iax);
13868                                                                oy = (iay);
13869                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13870                                                                ox = (ibx);
13871                                                                oy = (iby);
13872                                                        } else {
13873                                                                ox = (Math.max(iax, ibx));
13874                                                                oy = (Math.max(iay, iby));
13875                                                        }
13876                                                        oc128data[it.oIndex] = ox;
13877                                                        oc128data[it.oIndex + 1] = oy;
13878                                                }
13879                                        } else {
13880                                                while (it.hasNext()) {
13881                                                        final double iax = it.aDouble;
13882                                                        final double ibx = it.bDouble;
13883                                                        final double iby = 0;
13884                                                        double ox;
13885                                                        double oy;
13886                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13887                                                                ox = (iax);
13888                                                                oy = (iay);
13889                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13890                                                                ox = (ibx);
13891                                                                oy = (iby);
13892                                                        } else {
13893                                                                ox = (Math.max(iax, ibx));
13894                                                                oy = (Math.max(iay, iby));
13895                                                        }
13896                                                        oc128data[it.oIndex] = ox;
13897                                                        oc128data[it.oIndex + 1] = oy;
13898                                                }
13899                                        }
13900                                } else {
13901                                        final long iay = 0;
13902                                        while (it.hasNext()) {
13903                                                final long iax = it.aLong;
13904                                                final long ibx = it.bLong;
13905                                                final long iby = 0;
13906                                                double ox;
13907                                                double oy;
13908                                                if (Double.isNaN(iax) || Double.isNaN(iay)) {
13909                                                        ox = (iax);
13910                                                        oy = (iay);
13911                                                } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13912                                                        ox = (ibx);
13913                                                        oy = (iby);
13914                                                } else {
13915                                                        ox = (double) (Math.max(iax, ibx));
13916                                                        oy = (double) (Math.max(iay, iby));
13917                                                }
13918                                                oc128data[it.oIndex] = ox;
13919                                                oc128data[it.oIndex + 1] = oy;
13920                                        }
13921                                }
13922                        } else if (!db.isComplex()) {
13923                                final double iby = 0;
13924                                while (it.hasNext()) {
13925                                        final double iax = it.aDouble;
13926                                        final double ibx = it.bDouble;
13927                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
13928                                        double ox;
13929                                        double oy;
13930                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13931                                                ox = (iax);
13932                                                oy = (iay);
13933                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13934                                                ox = (ibx);
13935                                                oy = (iby);
13936                                        } else {
13937                                                ox = (Math.max(iax, ibx));
13938                                                oy = (Math.max(iay, iby));
13939                                        }
13940                                        oc128data[it.oIndex] = ox;
13941                                        oc128data[it.oIndex + 1] = oy;
13942                                }
13943                        } else {
13944                                while (it.hasNext()) {
13945                                        final double iax = it.aDouble;
13946                                        final double ibx = it.bDouble;
13947                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
13948                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
13949                                        double ox;
13950                                        double oy;
13951                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13952                                                ox = (iax);
13953                                                oy = (iay);
13954                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13955                                                ox = (ibx);
13956                                                oy = (iby);
13957                                        } else {
13958                                                ox = (Math.max(iax, ibx));
13959                                                oy = (Math.max(iay, iby));
13960                                        }
13961                                        oc128data[it.oIndex] = ox;
13962                                        oc128data[it.oIndex + 1] = oy;
13963                                }
13964                        }
13965                        break;
13966                default:
13967                        throw new IllegalArgumentException("maximum supports integer, compound integer, real, compound real, complex datasets only");
13968                }
13969
13970                addBinaryOperatorName(da, db, result, "maximum");
13971                return result;
13972        }
13973
13974        /**
13975         * minimum operator
13976         * @param a
13977         * @param b
13978         * @return return minimum of a and b
13979         */
13980        public static Dataset minimum(final Object a, final Object b) {
13981                return minimum(a, b, null);
13982        }
13983
13984        /**
13985         * minimum operator
13986         * @param a
13987         * @param b
13988         * @param o output can be null - in which case, a new dataset is created
13989         * @return return minimum of a and b
13990         */
13991        public static Dataset minimum(final Object a, final Object b, final Dataset o) {
13992                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
13993                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
13994                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
13995                final Dataset result = it.getOutput();
13996                if (!result.isComplex()) {
13997                        boolean change = false;
13998                        if (da.isComplex()) {
13999                                da = da.getRealView();
14000                                change = true;
14001                        }
14002                        if (db.isComplex()) {
14003                                db = db.getRealView();
14004                                change = true;
14005                        }
14006                        if (change) {
14007                                it = BroadcastIterator.createIterator(da, db, result, true);
14008                        }
14009                }
14010                final int is = result.getElementsPerItem();
14011                final int as = da.getElementsPerItem();
14012                final int bs = db.getElementsPerItem();
14013                final int dt = result.getDType();
14014
14015                switch(dt) {
14016                case Dataset.INT8:
14017                        final byte[] oi8data = ((ByteDataset) result).getData();
14018                        if (it.isOutputDouble()) {
14019                                while (it.hasNext()) {
14020                                        final double iax = it.aDouble;
14021                                        final double ibx = it.bDouble;
14022                                        byte ox;
14023                                        ox = (byte) toLong(Math.min(iax, ibx));
14024                                        oi8data[it.oIndex] = ox;
14025                                }
14026                        } else {
14027                                while (it.hasNext()) {
14028                                        final long iax = it.aLong;
14029                                        final long ibx = it.bLong;
14030                                        byte ox;
14031                                        ox = (byte) toLong(Math.min(iax, ibx));
14032                                        oi8data[it.oIndex] = ox;
14033                                }
14034                        }
14035                        break;
14036                case Dataset.INT16:
14037                        final short[] oi16data = ((ShortDataset) result).getData();
14038                        if (it.isOutputDouble()) {
14039                                while (it.hasNext()) {
14040                                        final double iax = it.aDouble;
14041                                        final double ibx = it.bDouble;
14042                                        short ox;
14043                                        ox = (short) toLong(Math.min(iax, ibx));
14044                                        oi16data[it.oIndex] = ox;
14045                                }
14046                        } else {
14047                                while (it.hasNext()) {
14048                                        final long iax = it.aLong;
14049                                        final long ibx = it.bLong;
14050                                        short ox;
14051                                        ox = (short) toLong(Math.min(iax, ibx));
14052                                        oi16data[it.oIndex] = ox;
14053                                }
14054                        }
14055                        break;
14056                case Dataset.INT64:
14057                        final long[] oi64data = ((LongDataset) result).getData();
14058                        if (it.isOutputDouble()) {
14059                                while (it.hasNext()) {
14060                                        final double iax = it.aDouble;
14061                                        final double ibx = it.bDouble;
14062                                        long ox;
14063                                        ox = toLong(Math.min(iax, ibx));
14064                                        oi64data[it.oIndex] = ox;
14065                                }
14066                        } else {
14067                                while (it.hasNext()) {
14068                                        final long iax = it.aLong;
14069                                        final long ibx = it.bLong;
14070                                        long ox;
14071                                        ox = toLong(Math.min(iax, ibx));
14072                                        oi64data[it.oIndex] = ox;
14073                                }
14074                        }
14075                        break;
14076                case Dataset.INT32:
14077                        final int[] oi32data = ((IntegerDataset) result).getData();
14078                        if (it.isOutputDouble()) {
14079                                while (it.hasNext()) {
14080                                        final double iax = it.aDouble;
14081                                        final double ibx = it.bDouble;
14082                                        int ox;
14083                                        ox = (int) toLong(Math.min(iax, ibx));
14084                                        oi32data[it.oIndex] = ox;
14085                                }
14086                        } else {
14087                                while (it.hasNext()) {
14088                                        final long iax = it.aLong;
14089                                        final long ibx = it.bLong;
14090                                        int ox;
14091                                        ox = (int) toLong(Math.min(iax, ibx));
14092                                        oi32data[it.oIndex] = ox;
14093                                }
14094                        }
14095                        break;
14096                case Dataset.ARRAYINT8:
14097                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
14098                        if (is == 1) {
14099                                if (it.isOutputDouble()) {
14100                                        while (it.hasNext()) {
14101                                                final double iax = it.aDouble;
14102                                                final double ibx = it.bDouble;
14103                                                byte ox;
14104                                                ox = (byte) toLong(Math.min(iax, ibx));
14105                                                oai8data[it.oIndex] = ox;
14106                                        }
14107                                } else {
14108                                        while (it.hasNext()) {
14109                                                final long iax = it.aLong;
14110                                                final long ibx = it.bLong;
14111                                                byte ox;
14112                                                ox = (byte) toLong(Math.min(iax, ibx));
14113                                                oai8data[it.oIndex] = ox;
14114                                        }
14115                                }
14116                        } else if (as < bs) {
14117                                if (it.isOutputDouble()) {
14118                                        while (it.hasNext()) {
14119                                                final double iax = it.aDouble;
14120                                                double ibx = it.bDouble;
14121                                                byte ox;
14122                                                ox = (byte) toLong(Math.min(iax, ibx));
14123                                                oai8data[it.oIndex] = ox;
14124                                                for (int j = 1; j < is; j++) {
14125                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14126                                                        ox = (byte) toLong(Math.min(iax, ibx));
14127                                                        oai8data[it.oIndex + j] = ox;
14128                                                }
14129                                        }
14130                                } else {
14131                                        while (it.hasNext()) {
14132                                                final long iax = it.aLong;
14133                                                long ibx = it.bLong;
14134                                                byte ox;
14135                                                ox = (byte) toLong(Math.min(iax, ibx));
14136                                                oai8data[it.oIndex] = ox;
14137                                                for (int j = 1; j < is; j++) {
14138                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14139                                                        ox = (byte) toLong(Math.min(iax, ibx));
14140                                                        oai8data[it.oIndex + j] = ox;
14141                                                }
14142                                        }
14143                                }
14144                        } else if (as > bs) {
14145                                if (it.isOutputDouble()) {
14146                                        while (it.hasNext()) {
14147                                                double iax = it.aDouble;
14148                                                final double ibx = it.bDouble;
14149                                                byte ox;
14150                                                ox = (byte) toLong(Math.min(iax, ibx));
14151                                                oai8data[it.oIndex] = ox;
14152                                                for (int j = 1; j < is; j++) {
14153                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14154                                                        ox = (byte) toLong(Math.min(iax, ibx));
14155                                                        oai8data[it.oIndex + j] = ox;
14156                                                }
14157                                        }
14158                                } else {
14159                                        while (it.hasNext()) {
14160                                                long iax = it.aLong;
14161                                                final long ibx = it.bLong;
14162                                                byte ox;
14163                                                ox = (byte) toLong(Math.min(iax, ibx));
14164                                                oai8data[it.oIndex] = ox;
14165                                                for (int j = 1; j < is; j++) {
14166                                                        iax = da.getElementLongAbs(it.aIndex + j);
14167                                                        ox = (byte) toLong(Math.min(iax, ibx));
14168                                                        oai8data[it.oIndex + j] = ox;
14169                                                }
14170                                        }
14171                                }
14172                        } else if (as == 1) {
14173                                if (it.isOutputDouble()) {
14174                                        while (it.hasNext()) {
14175                                                final double iax = it.aDouble;
14176                                                final double ibx = it.bDouble;
14177                                                byte ox;
14178                                                ox = (byte) toLong(Math.min(iax, ibx));
14179                                                for (int j = 0; j < is; j++) {
14180                                                        oai8data[it.oIndex + j] = ox;
14181                                                }
14182                                        }
14183                                } else {
14184                                        while (it.hasNext()) {
14185                                                final long iax = it.aLong;
14186                                                final long ibx = it.bLong;
14187                                                byte ox;
14188                                                ox = (byte) toLong(Math.min(iax, ibx));
14189                                                for (int j = 0; j < is; j++) {
14190                                                        oai8data[it.oIndex + j] = ox;
14191                                                }
14192                                        }
14193                                }
14194                        } else {
14195                                if (it.isOutputDouble()) {
14196                                        while (it.hasNext()) {
14197                                                double iax = it.aDouble;
14198                                                double ibx = it.bDouble;
14199                                                byte ox;
14200                                                ox = (byte) toLong(Math.min(iax, ibx));
14201                                                oai8data[it.oIndex] = ox;
14202                                                for (int j = 1; j < is; j++) {
14203                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14204                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14205                                                        ox = (byte) toLong(Math.min(iax, ibx));
14206                                                        oai8data[it.oIndex + j] = ox;
14207                                                }
14208                                        }
14209                                } else {
14210                                        while (it.hasNext()) {
14211                                                long iax = it.aLong;
14212                                                long ibx = it.bLong;
14213                                                byte ox;
14214                                                ox = (byte) toLong(Math.min(iax, ibx));
14215                                                oai8data[it.oIndex] = ox;
14216                                                for (int j = 1; j < is; j++) {
14217                                                        iax = da.getElementLongAbs(it.aIndex + j);
14218                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14219                                                        ox = (byte) toLong(Math.min(iax, ibx));
14220                                                        oai8data[it.oIndex + j] = ox;
14221                                                }
14222                                        }
14223                                }
14224                        }
14225                        break;
14226                case Dataset.ARRAYINT16:
14227                        final short[] oai16data = ((CompoundShortDataset) result).getData();
14228                        if (is == 1) {
14229                                if (it.isOutputDouble()) {
14230                                        while (it.hasNext()) {
14231                                                final double iax = it.aDouble;
14232                                                final double ibx = it.bDouble;
14233                                                short ox;
14234                                                ox = (short) toLong(Math.min(iax, ibx));
14235                                                oai16data[it.oIndex] = ox;
14236                                        }
14237                                } else {
14238                                        while (it.hasNext()) {
14239                                                final long iax = it.aLong;
14240                                                final long ibx = it.bLong;
14241                                                short ox;
14242                                                ox = (short) toLong(Math.min(iax, ibx));
14243                                                oai16data[it.oIndex] = ox;
14244                                        }
14245                                }
14246                        } else if (as < bs) {
14247                                if (it.isOutputDouble()) {
14248                                        while (it.hasNext()) {
14249                                                final double iax = it.aDouble;
14250                                                double ibx = it.bDouble;
14251                                                short ox;
14252                                                ox = (short) toLong(Math.min(iax, ibx));
14253                                                oai16data[it.oIndex] = ox;
14254                                                for (int j = 1; j < is; j++) {
14255                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14256                                                        ox = (short) toLong(Math.min(iax, ibx));
14257                                                        oai16data[it.oIndex + j] = ox;
14258                                                }
14259                                        }
14260                                } else {
14261                                        while (it.hasNext()) {
14262                                                final long iax = it.aLong;
14263                                                long ibx = it.bLong;
14264                                                short ox;
14265                                                ox = (short) toLong(Math.min(iax, ibx));
14266                                                oai16data[it.oIndex] = ox;
14267                                                for (int j = 1; j < is; j++) {
14268                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14269                                                        ox = (short) toLong(Math.min(iax, ibx));
14270                                                        oai16data[it.oIndex + j] = ox;
14271                                                }
14272                                        }
14273                                }
14274                        } else if (as > bs) {
14275                                if (it.isOutputDouble()) {
14276                                        while (it.hasNext()) {
14277                                                double iax = it.aDouble;
14278                                                final double ibx = it.bDouble;
14279                                                short ox;
14280                                                ox = (short) toLong(Math.min(iax, ibx));
14281                                                oai16data[it.oIndex] = ox;
14282                                                for (int j = 1; j < is; j++) {
14283                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14284                                                        ox = (short) toLong(Math.min(iax, ibx));
14285                                                        oai16data[it.oIndex + j] = ox;
14286                                                }
14287                                        }
14288                                } else {
14289                                        while (it.hasNext()) {
14290                                                long iax = it.aLong;
14291                                                final long ibx = it.bLong;
14292                                                short ox;
14293                                                ox = (short) toLong(Math.min(iax, ibx));
14294                                                oai16data[it.oIndex] = ox;
14295                                                for (int j = 1; j < is; j++) {
14296                                                        iax = da.getElementLongAbs(it.aIndex + j);
14297                                                        ox = (short) toLong(Math.min(iax, ibx));
14298                                                        oai16data[it.oIndex + j] = ox;
14299                                                }
14300                                        }
14301                                }
14302                        } else if (as == 1) {
14303                                if (it.isOutputDouble()) {
14304                                        while (it.hasNext()) {
14305                                                final double iax = it.aDouble;
14306                                                final double ibx = it.bDouble;
14307                                                short ox;
14308                                                ox = (short) toLong(Math.min(iax, ibx));
14309                                                for (int j = 0; j < is; j++) {
14310                                                        oai16data[it.oIndex + j] = ox;
14311                                                }
14312                                        }
14313                                } else {
14314                                        while (it.hasNext()) {
14315                                                final long iax = it.aLong;
14316                                                final long ibx = it.bLong;
14317                                                short ox;
14318                                                ox = (short) toLong(Math.min(iax, ibx));
14319                                                for (int j = 0; j < is; j++) {
14320                                                        oai16data[it.oIndex + j] = ox;
14321                                                }
14322                                        }
14323                                }
14324                        } else {
14325                                if (it.isOutputDouble()) {
14326                                        while (it.hasNext()) {
14327                                                double iax = it.aDouble;
14328                                                double ibx = it.bDouble;
14329                                                short ox;
14330                                                ox = (short) toLong(Math.min(iax, ibx));
14331                                                oai16data[it.oIndex] = ox;
14332                                                for (int j = 1; j < is; j++) {
14333                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14334                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14335                                                        ox = (short) toLong(Math.min(iax, ibx));
14336                                                        oai16data[it.oIndex + j] = ox;
14337                                                }
14338                                        }
14339                                } else {
14340                                        while (it.hasNext()) {
14341                                                long iax = it.aLong;
14342                                                long ibx = it.bLong;
14343                                                short ox;
14344                                                ox = (short) toLong(Math.min(iax, ibx));
14345                                                oai16data[it.oIndex] = ox;
14346                                                for (int j = 1; j < is; j++) {
14347                                                        iax = da.getElementLongAbs(it.aIndex + j);
14348                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14349                                                        ox = (short) toLong(Math.min(iax, ibx));
14350                                                        oai16data[it.oIndex + j] = ox;
14351                                                }
14352                                        }
14353                                }
14354                        }
14355                        break;
14356                case Dataset.ARRAYINT64:
14357                        final long[] oai64data = ((CompoundLongDataset) result).getData();
14358                        if (is == 1) {
14359                                if (it.isOutputDouble()) {
14360                                        while (it.hasNext()) {
14361                                                final double iax = it.aDouble;
14362                                                final double ibx = it.bDouble;
14363                                                long ox;
14364                                                ox = toLong(Math.min(iax, ibx));
14365                                                oai64data[it.oIndex] = ox;
14366                                        }
14367                                } else {
14368                                        while (it.hasNext()) {
14369                                                final long iax = it.aLong;
14370                                                final long ibx = it.bLong;
14371                                                long ox;
14372                                                ox = toLong(Math.min(iax, ibx));
14373                                                oai64data[it.oIndex] = ox;
14374                                        }
14375                                }
14376                        } else if (as < bs) {
14377                                if (it.isOutputDouble()) {
14378                                        while (it.hasNext()) {
14379                                                final double iax = it.aDouble;
14380                                                double ibx = it.bDouble;
14381                                                long ox;
14382                                                ox = toLong(Math.min(iax, ibx));
14383                                                oai64data[it.oIndex] = ox;
14384                                                for (int j = 1; j < is; j++) {
14385                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14386                                                        ox = toLong(Math.min(iax, ibx));
14387                                                        oai64data[it.oIndex + j] = ox;
14388                                                }
14389                                        }
14390                                } else {
14391                                        while (it.hasNext()) {
14392                                                final long iax = it.aLong;
14393                                                long ibx = it.bLong;
14394                                                long ox;
14395                                                ox = toLong(Math.min(iax, ibx));
14396                                                oai64data[it.oIndex] = ox;
14397                                                for (int j = 1; j < is; j++) {
14398                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14399                                                        ox = toLong(Math.min(iax, ibx));
14400                                                        oai64data[it.oIndex + j] = ox;
14401                                                }
14402                                        }
14403                                }
14404                        } else if (as > bs) {
14405                                if (it.isOutputDouble()) {
14406                                        while (it.hasNext()) {
14407                                                double iax = it.aDouble;
14408                                                final double ibx = it.bDouble;
14409                                                long ox;
14410                                                ox = toLong(Math.min(iax, ibx));
14411                                                oai64data[it.oIndex] = ox;
14412                                                for (int j = 1; j < is; j++) {
14413                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14414                                                        ox = toLong(Math.min(iax, ibx));
14415                                                        oai64data[it.oIndex + j] = ox;
14416                                                }
14417                                        }
14418                                } else {
14419                                        while (it.hasNext()) {
14420                                                long iax = it.aLong;
14421                                                final long ibx = it.bLong;
14422                                                long ox;
14423                                                ox = toLong(Math.min(iax, ibx));
14424                                                oai64data[it.oIndex] = ox;
14425                                                for (int j = 1; j < is; j++) {
14426                                                        iax = da.getElementLongAbs(it.aIndex + j);
14427                                                        ox = toLong(Math.min(iax, ibx));
14428                                                        oai64data[it.oIndex + j] = ox;
14429                                                }
14430                                        }
14431                                }
14432                        } else if (as == 1) {
14433                                if (it.isOutputDouble()) {
14434                                        while (it.hasNext()) {
14435                                                final double iax = it.aDouble;
14436                                                final double ibx = it.bDouble;
14437                                                long ox;
14438                                                ox = toLong(Math.min(iax, ibx));
14439                                                for (int j = 0; j < is; j++) {
14440                                                        oai64data[it.oIndex + j] = ox;
14441                                                }
14442                                        }
14443                                } else {
14444                                        while (it.hasNext()) {
14445                                                final long iax = it.aLong;
14446                                                final long ibx = it.bLong;
14447                                                long ox;
14448                                                ox = toLong(Math.min(iax, ibx));
14449                                                for (int j = 0; j < is; j++) {
14450                                                        oai64data[it.oIndex + j] = ox;
14451                                                }
14452                                        }
14453                                }
14454                        } else {
14455                                if (it.isOutputDouble()) {
14456                                        while (it.hasNext()) {
14457                                                double iax = it.aDouble;
14458                                                double ibx = it.bDouble;
14459                                                long ox;
14460                                                ox = toLong(Math.min(iax, ibx));
14461                                                oai64data[it.oIndex] = ox;
14462                                                for (int j = 1; j < is; j++) {
14463                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14464                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14465                                                        ox = toLong(Math.min(iax, ibx));
14466                                                        oai64data[it.oIndex + j] = ox;
14467                                                }
14468                                        }
14469                                } else {
14470                                        while (it.hasNext()) {
14471                                                long iax = it.aLong;
14472                                                long ibx = it.bLong;
14473                                                long ox;
14474                                                ox = toLong(Math.min(iax, ibx));
14475                                                oai64data[it.oIndex] = ox;
14476                                                for (int j = 1; j < is; j++) {
14477                                                        iax = da.getElementLongAbs(it.aIndex + j);
14478                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14479                                                        ox = toLong(Math.min(iax, ibx));
14480                                                        oai64data[it.oIndex + j] = ox;
14481                                                }
14482                                        }
14483                                }
14484                        }
14485                        break;
14486                case Dataset.ARRAYINT32:
14487                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
14488                        if (is == 1) {
14489                                if (it.isOutputDouble()) {
14490                                        while (it.hasNext()) {
14491                                                final double iax = it.aDouble;
14492                                                final double ibx = it.bDouble;
14493                                                int ox;
14494                                                ox = (int) toLong(Math.min(iax, ibx));
14495                                                oai32data[it.oIndex] = ox;
14496                                        }
14497                                } else {
14498                                        while (it.hasNext()) {
14499                                                final long iax = it.aLong;
14500                                                final long ibx = it.bLong;
14501                                                int ox;
14502                                                ox = (int) toLong(Math.min(iax, ibx));
14503                                                oai32data[it.oIndex] = ox;
14504                                        }
14505                                }
14506                        } else if (as < bs) {
14507                                if (it.isOutputDouble()) {
14508                                        while (it.hasNext()) {
14509                                                final double iax = it.aDouble;
14510                                                double ibx = it.bDouble;
14511                                                int ox;
14512                                                ox = (int) toLong(Math.min(iax, ibx));
14513                                                oai32data[it.oIndex] = ox;
14514                                                for (int j = 1; j < is; j++) {
14515                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14516                                                        ox = (int) toLong(Math.min(iax, ibx));
14517                                                        oai32data[it.oIndex + j] = ox;
14518                                                }
14519                                        }
14520                                } else {
14521                                        while (it.hasNext()) {
14522                                                final long iax = it.aLong;
14523                                                long ibx = it.bLong;
14524                                                int ox;
14525                                                ox = (int) toLong(Math.min(iax, ibx));
14526                                                oai32data[it.oIndex] = ox;
14527                                                for (int j = 1; j < is; j++) {
14528                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14529                                                        ox = (int) toLong(Math.min(iax, ibx));
14530                                                        oai32data[it.oIndex + j] = ox;
14531                                                }
14532                                        }
14533                                }
14534                        } else if (as > bs) {
14535                                if (it.isOutputDouble()) {
14536                                        while (it.hasNext()) {
14537                                                double iax = it.aDouble;
14538                                                final double ibx = it.bDouble;
14539                                                int ox;
14540                                                ox = (int) toLong(Math.min(iax, ibx));
14541                                                oai32data[it.oIndex] = ox;
14542                                                for (int j = 1; j < is; j++) {
14543                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14544                                                        ox = (int) toLong(Math.min(iax, ibx));
14545                                                        oai32data[it.oIndex + j] = ox;
14546                                                }
14547                                        }
14548                                } else {
14549                                        while (it.hasNext()) {
14550                                                long iax = it.aLong;
14551                                                final long ibx = it.bLong;
14552                                                int ox;
14553                                                ox = (int) toLong(Math.min(iax, ibx));
14554                                                oai32data[it.oIndex] = ox;
14555                                                for (int j = 1; j < is; j++) {
14556                                                        iax = da.getElementLongAbs(it.aIndex + j);
14557                                                        ox = (int) toLong(Math.min(iax, ibx));
14558                                                        oai32data[it.oIndex + j] = ox;
14559                                                }
14560                                        }
14561                                }
14562                        } else if (as == 1) {
14563                                if (it.isOutputDouble()) {
14564                                        while (it.hasNext()) {
14565                                                final double iax = it.aDouble;
14566                                                final double ibx = it.bDouble;
14567                                                int ox;
14568                                                ox = (int) toLong(Math.min(iax, ibx));
14569                                                for (int j = 0; j < is; j++) {
14570                                                        oai32data[it.oIndex + j] = ox;
14571                                                }
14572                                        }
14573                                } else {
14574                                        while (it.hasNext()) {
14575                                                final long iax = it.aLong;
14576                                                final long ibx = it.bLong;
14577                                                int ox;
14578                                                ox = (int) toLong(Math.min(iax, ibx));
14579                                                for (int j = 0; j < is; j++) {
14580                                                        oai32data[it.oIndex + j] = ox;
14581                                                }
14582                                        }
14583                                }
14584                        } else {
14585                                if (it.isOutputDouble()) {
14586                                        while (it.hasNext()) {
14587                                                double iax = it.aDouble;
14588                                                double ibx = it.bDouble;
14589                                                int ox;
14590                                                ox = (int) toLong(Math.min(iax, ibx));
14591                                                oai32data[it.oIndex] = ox;
14592                                                for (int j = 1; j < is; j++) {
14593                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14594                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14595                                                        ox = (int) toLong(Math.min(iax, ibx));
14596                                                        oai32data[it.oIndex + j] = ox;
14597                                                }
14598                                        }
14599                                } else {
14600                                        while (it.hasNext()) {
14601                                                long iax = it.aLong;
14602                                                long ibx = it.bLong;
14603                                                int ox;
14604                                                ox = (int) toLong(Math.min(iax, ibx));
14605                                                oai32data[it.oIndex] = ox;
14606                                                for (int j = 1; j < is; j++) {
14607                                                        iax = da.getElementLongAbs(it.aIndex + j);
14608                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14609                                                        ox = (int) toLong(Math.min(iax, ibx));
14610                                                        oai32data[it.oIndex + j] = ox;
14611                                                }
14612                                        }
14613                                }
14614                        }
14615                        break;
14616                case Dataset.FLOAT32:
14617                        final float[] of32data = ((FloatDataset) result).getData();
14618                        if (it.isOutputDouble()) {
14619                                while (it.hasNext()) {
14620                                        final double iax = it.aDouble;
14621                                        final double ibx = it.bDouble;
14622                                        float ox;
14623                                        ox = (float) (Math.min(iax, ibx));
14624                                        of32data[it.oIndex] = ox;
14625                                }
14626                        } else {
14627                                while (it.hasNext()) {
14628                                        final long iax = it.aLong;
14629                                        final long ibx = it.bLong;
14630                                        float ox;
14631                                        ox = (float) (Math.min(iax, ibx));
14632                                        of32data[it.oIndex] = ox;
14633                                }
14634                        }
14635                        break;
14636                case Dataset.FLOAT64:
14637                        final double[] of64data = ((DoubleDataset) result).getData();
14638                        if (it.isOutputDouble()) {
14639                                while (it.hasNext()) {
14640                                        final double iax = it.aDouble;
14641                                        final double ibx = it.bDouble;
14642                                        double ox;
14643                                        ox = (Math.min(iax, ibx));
14644                                        of64data[it.oIndex] = ox;
14645                                }
14646                        } else {
14647                                while (it.hasNext()) {
14648                                        final long iax = it.aLong;
14649                                        final long ibx = it.bLong;
14650                                        double ox;
14651                                        ox = (Math.min(iax, ibx));
14652                                        of64data[it.oIndex] = ox;
14653                                }
14654                        }
14655                        break;
14656                case Dataset.ARRAYFLOAT32:
14657                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
14658                        if (is == 1) {
14659                                if (it.isOutputDouble()) {
14660                                        while (it.hasNext()) {
14661                                                final double iax = it.aDouble;
14662                                                final double ibx = it.bDouble;
14663                                                float ox;
14664                                                ox = (float) (Math.min(iax, ibx));
14665                                                oaf32data[it.oIndex] = ox;
14666                                        }
14667                                } else {
14668                                        while (it.hasNext()) {
14669                                                final long iax = it.aLong;
14670                                                final long ibx = it.bLong;
14671                                                float ox;
14672                                                ox = (float) (Math.min(iax, ibx));
14673                                                oaf32data[it.oIndex] = ox;
14674                                        }
14675                                }
14676                        } else if (as < bs) {
14677                                if (it.isOutputDouble()) {
14678                                        while (it.hasNext()) {
14679                                                final double iax = it.aDouble;
14680                                                double ibx = it.bDouble;
14681                                                float ox;
14682                                                ox = (float) (Math.min(iax, ibx));
14683                                                oaf32data[it.oIndex] = ox;
14684                                                for (int j = 1; j < is; j++) {
14685                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14686                                                        ox = (float) (Math.min(iax, ibx));
14687                                                        oaf32data[it.oIndex + j] = ox;
14688                                                }
14689                                        }
14690                                } else {
14691                                        while (it.hasNext()) {
14692                                                final long iax = it.aLong;
14693                                                long ibx = it.bLong;
14694                                                float ox;
14695                                                ox = (float) (Math.min(iax, ibx));
14696                                                oaf32data[it.oIndex] = ox;
14697                                                for (int j = 1; j < is; j++) {
14698                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14699                                                        ox = (float) (Math.min(iax, ibx));
14700                                                        oaf32data[it.oIndex + j] = ox;
14701                                                }
14702                                        }
14703                                }
14704                        } else if (as > bs) {
14705                                if (it.isOutputDouble()) {
14706                                        while (it.hasNext()) {
14707                                                double iax = it.aDouble;
14708                                                final double ibx = it.bDouble;
14709                                                float ox;
14710                                                ox = (float) (Math.min(iax, ibx));
14711                                                oaf32data[it.oIndex] = ox;
14712                                                for (int j = 1; j < is; j++) {
14713                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14714                                                        ox = (float) (Math.min(iax, ibx));
14715                                                        oaf32data[it.oIndex + j] = ox;
14716                                                }
14717                                        }
14718                                } else {
14719                                        while (it.hasNext()) {
14720                                                long iax = it.aLong;
14721                                                final long ibx = it.bLong;
14722                                                float ox;
14723                                                ox = (float) (Math.min(iax, ibx));
14724                                                oaf32data[it.oIndex] = ox;
14725                                                for (int j = 1; j < is; j++) {
14726                                                        iax = da.getElementLongAbs(it.aIndex + j);
14727                                                        ox = (float) (Math.min(iax, ibx));
14728                                                        oaf32data[it.oIndex + j] = ox;
14729                                                }
14730                                        }
14731                                }
14732                        } else if (as == 1) {
14733                                if (it.isOutputDouble()) {
14734                                        while (it.hasNext()) {
14735                                                final double iax = it.aDouble;
14736                                                final double ibx = it.bDouble;
14737                                                float ox;
14738                                                ox = (float) (Math.min(iax, ibx));
14739                                                for (int j = 0; j < is; j++) {
14740                                                        oaf32data[it.oIndex + j] = ox;
14741                                                }
14742                                        }
14743                                } else {
14744                                        while (it.hasNext()) {
14745                                                final long iax = it.aLong;
14746                                                final long ibx = it.bLong;
14747                                                float ox;
14748                                                ox = (float) (Math.min(iax, ibx));
14749                                                for (int j = 0; j < is; j++) {
14750                                                        oaf32data[it.oIndex + j] = ox;
14751                                                }
14752                                        }
14753                                }
14754                        } else {
14755                                if (it.isOutputDouble()) {
14756                                        while (it.hasNext()) {
14757                                                double iax = it.aDouble;
14758                                                double ibx = it.bDouble;
14759                                                float ox;
14760                                                ox = (float) (Math.min(iax, ibx));
14761                                                oaf32data[it.oIndex] = ox;
14762                                                for (int j = 1; j < is; j++) {
14763                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14764                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14765                                                        ox = (float) (Math.min(iax, ibx));
14766                                                        oaf32data[it.oIndex + j] = ox;
14767                                                }
14768                                        }
14769                                } else {
14770                                        while (it.hasNext()) {
14771                                                long iax = it.aLong;
14772                                                long ibx = it.bLong;
14773                                                float ox;
14774                                                ox = (float) (Math.min(iax, ibx));
14775                                                oaf32data[it.oIndex] = ox;
14776                                                for (int j = 1; j < is; j++) {
14777                                                        iax = da.getElementLongAbs(it.aIndex + j);
14778                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14779                                                        ox = (float) (Math.min(iax, ibx));
14780                                                        oaf32data[it.oIndex + j] = ox;
14781                                                }
14782                                        }
14783                                }
14784                        }
14785                        break;
14786                case Dataset.ARRAYFLOAT64:
14787                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
14788                        if (is == 1) {
14789                                if (it.isOutputDouble()) {
14790                                        while (it.hasNext()) {
14791                                                final double iax = it.aDouble;
14792                                                final double ibx = it.bDouble;
14793                                                double ox;
14794                                                ox = (Math.min(iax, ibx));
14795                                                oaf64data[it.oIndex] = ox;
14796                                        }
14797                                } else {
14798                                        while (it.hasNext()) {
14799                                                final long iax = it.aLong;
14800                                                final long ibx = it.bLong;
14801                                                double ox;
14802                                                ox = (Math.min(iax, ibx));
14803                                                oaf64data[it.oIndex] = ox;
14804                                        }
14805                                }
14806                        } else if (as < bs) {
14807                                if (it.isOutputDouble()) {
14808                                        while (it.hasNext()) {
14809                                                final double iax = it.aDouble;
14810                                                double ibx = it.bDouble;
14811                                                double ox;
14812                                                ox = (Math.min(iax, ibx));
14813                                                oaf64data[it.oIndex] = ox;
14814                                                for (int j = 1; j < is; j++) {
14815                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14816                                                        ox = (Math.min(iax, ibx));
14817                                                        oaf64data[it.oIndex + j] = ox;
14818                                                }
14819                                        }
14820                                } else {
14821                                        while (it.hasNext()) {
14822                                                final long iax = it.aLong;
14823                                                long ibx = it.bLong;
14824                                                double ox;
14825                                                ox = (Math.min(iax, ibx));
14826                                                oaf64data[it.oIndex] = ox;
14827                                                for (int j = 1; j < is; j++) {
14828                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14829                                                        ox = (Math.min(iax, ibx));
14830                                                        oaf64data[it.oIndex + j] = ox;
14831                                                }
14832                                        }
14833                                }
14834                        } else if (as > bs) {
14835                                if (it.isOutputDouble()) {
14836                                        while (it.hasNext()) {
14837                                                double iax = it.aDouble;
14838                                                final double ibx = it.bDouble;
14839                                                double ox;
14840                                                ox = (Math.min(iax, ibx));
14841                                                oaf64data[it.oIndex] = ox;
14842                                                for (int j = 1; j < is; j++) {
14843                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14844                                                        ox = (Math.min(iax, ibx));
14845                                                        oaf64data[it.oIndex + j] = ox;
14846                                                }
14847                                        }
14848                                } else {
14849                                        while (it.hasNext()) {
14850                                                long iax = it.aLong;
14851                                                final long ibx = it.bLong;
14852                                                double ox;
14853                                                ox = (Math.min(iax, ibx));
14854                                                oaf64data[it.oIndex] = ox;
14855                                                for (int j = 1; j < is; j++) {
14856                                                        iax = da.getElementLongAbs(it.aIndex + j);
14857                                                        ox = (Math.min(iax, ibx));
14858                                                        oaf64data[it.oIndex + j] = ox;
14859                                                }
14860                                        }
14861                                }
14862                        } else if (as == 1) {
14863                                if (it.isOutputDouble()) {
14864                                        while (it.hasNext()) {
14865                                                final double iax = it.aDouble;
14866                                                final double ibx = it.bDouble;
14867                                                double ox;
14868                                                ox = (Math.min(iax, ibx));
14869                                                for (int j = 0; j < is; j++) {
14870                                                        oaf64data[it.oIndex + j] = ox;
14871                                                }
14872                                        }
14873                                } else {
14874                                        while (it.hasNext()) {
14875                                                final long iax = it.aLong;
14876                                                final long ibx = it.bLong;
14877                                                double ox;
14878                                                ox = (Math.min(iax, ibx));
14879                                                for (int j = 0; j < is; j++) {
14880                                                        oaf64data[it.oIndex + j] = ox;
14881                                                }
14882                                        }
14883                                }
14884                        } else {
14885                                if (it.isOutputDouble()) {
14886                                        while (it.hasNext()) {
14887                                                double iax = it.aDouble;
14888                                                double ibx = it.bDouble;
14889                                                double ox;
14890                                                ox = (Math.min(iax, ibx));
14891                                                oaf64data[it.oIndex] = ox;
14892                                                for (int j = 1; j < is; j++) {
14893                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14894                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14895                                                        ox = (Math.min(iax, ibx));
14896                                                        oaf64data[it.oIndex + j] = ox;
14897                                                }
14898                                        }
14899                                } else {
14900                                        while (it.hasNext()) {
14901                                                long iax = it.aLong;
14902                                                long ibx = it.bLong;
14903                                                double ox;
14904                                                ox = (Math.min(iax, ibx));
14905                                                oaf64data[it.oIndex] = ox;
14906                                                for (int j = 1; j < is; j++) {
14907                                                        iax = da.getElementLongAbs(it.aIndex + j);
14908                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14909                                                        ox = (Math.min(iax, ibx));
14910                                                        oaf64data[it.oIndex + j] = ox;
14911                                                }
14912                                        }
14913                                }
14914                        }
14915                        break;
14916                case Dataset.COMPLEX64:
14917                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
14918                        if (!da.isComplex()) {
14919                                if (it.isOutputDouble()) {
14920                                        final double iay = 0;
14921                                        if (db.isComplex()) {
14922                                                while (it.hasNext()) {
14923                                                        final double iax = it.aDouble;
14924                                                        final double ibx = it.bDouble;
14925                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
14926                                                        float ox;
14927                                                        float oy;
14928                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
14929                                                                ox = (float) (iax);
14930                                                                oy = (float) (iay);
14931                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
14932                                                                ox = (float) (ibx);
14933                                                                oy = (float) (iby);
14934                                                        } else {
14935                                                                ox = (float) (Math.min(iax, ibx));
14936                                                                oy = (float) (Math.min(iay, iby));
14937                                                        }
14938                                                        oc64data[it.oIndex] = ox;
14939                                                        oc64data[it.oIndex + 1] = oy;
14940                                                }
14941                                        } else {
14942                                                while (it.hasNext()) {
14943                                                        final double iax = it.aDouble;
14944                                                        final double ibx = it.bDouble;
14945                                                        final double iby = 0;
14946                                                        float ox;
14947                                                        float oy;
14948                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
14949                                                                ox = (float) (iax);
14950                                                                oy = (float) (iay);
14951                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
14952                                                                ox = (float) (ibx);
14953                                                                oy = (float) (iby);
14954                                                        } else {
14955                                                                ox = (float) (Math.min(iax, ibx));
14956                                                                oy = (float) (Math.min(iay, iby));
14957                                                        }
14958                                                        oc64data[it.oIndex] = ox;
14959                                                        oc64data[it.oIndex + 1] = oy;
14960                                                }
14961                                        }
14962                                } else {
14963                                        final long iay = 0;
14964                                        while (it.hasNext()) {
14965                                                final long iax = it.aLong;
14966                                                final long ibx = it.bLong;
14967                                                final long iby = 0;
14968                                                float ox;
14969                                                float oy;
14970                                                if (Double.isNaN(iax) || Double.isNaN(iay)) {
14971                                                        ox = (float) (iax);
14972                                                        oy = (float) (iay);
14973                                                } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
14974                                                        ox = (float) (ibx);
14975                                                        oy = (float) (iby);
14976                                                } else {
14977                                                        ox = (float) (Math.min(iax, ibx));
14978                                                        oy = (float) (Math.min(iay, iby));
14979                                                }
14980                                                oc64data[it.oIndex] = ox;
14981                                                oc64data[it.oIndex + 1] = oy;
14982                                        }
14983                                }
14984                        } else if (!db.isComplex()) {
14985                                final double iby = 0;
14986                                while (it.hasNext()) {
14987                                        final double iax = it.aDouble;
14988                                        final double ibx = it.bDouble;
14989                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
14990                                        float ox;
14991                                        float oy;
14992                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
14993                                                ox = (float) (iax);
14994                                                oy = (float) (iay);
14995                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
14996                                                ox = (float) (ibx);
14997                                                oy = (float) (iby);
14998                                        } else {
14999                                                ox = (float) (Math.min(iax, ibx));
15000                                                oy = (float) (Math.min(iay, iby));
15001                                        }
15002                                        oc64data[it.oIndex] = ox;
15003                                        oc64data[it.oIndex + 1] = oy;
15004                                }
15005                        } else {
15006                                while (it.hasNext()) {
15007                                        final double iax = it.aDouble;
15008                                        final double ibx = it.bDouble;
15009                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
15010                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
15011                                        float ox;
15012                                        float oy;
15013                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
15014                                                ox = (float) (iax);
15015                                                oy = (float) (iay);
15016                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
15017                                                ox = (float) (ibx);
15018                                                oy = (float) (iby);
15019                                        } else {
15020                                                ox = (float) (Math.min(iax, ibx));
15021                                                oy = (float) (Math.min(iay, iby));
15022                                        }
15023                                        oc64data[it.oIndex] = ox;
15024                                        oc64data[it.oIndex + 1] = oy;
15025                                }
15026                        }
15027                        break;
15028                case Dataset.COMPLEX128:
15029                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
15030                        if (!da.isComplex()) {
15031                                if (it.isOutputDouble()) {
15032                                        final double iay = 0;
15033                                        if (db.isComplex()) {
15034                                                while (it.hasNext()) {
15035                                                        final double iax = it.aDouble;
15036                                                        final double ibx = it.bDouble;
15037                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
15038                                                        double ox;
15039                                                        double oy;
15040                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
15041                                                                ox = (iax);
15042                                                                oy = (iay);
15043                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
15044                                                                ox = (ibx);
15045                                                                oy = (iby);
15046                                                        } else {
15047                                                                ox = (Math.min(iax, ibx));
15048                                                                oy = (Math.min(iay, iby));
15049                                                        }
15050                                                        oc128data[it.oIndex] = ox;
15051                                                        oc128data[it.oIndex + 1] = oy;
15052                                                }
15053                                        } else {
15054                                                while (it.hasNext()) {
15055                                                        final double iax = it.aDouble;
15056                                                        final double ibx = it.bDouble;
15057                                                        final double iby = 0;
15058                                                        double ox;
15059                                                        double oy;
15060                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
15061                                                                ox = (iax);
15062                                                                oy = (iay);
15063                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
15064                                                                ox = (ibx);
15065                                                                oy = (iby);
15066                                                        } else {
15067                                                                ox = (Math.min(iax, ibx));
15068                                                                oy = (Math.min(iay, iby));
15069                                                        }
15070                                                        oc128data[it.oIndex] = ox;
15071                                                        oc128data[it.oIndex + 1] = oy;
15072                                                }
15073                                        }
15074                                } else {
15075                                        final long iay = 0;
15076                                        while (it.hasNext()) {
15077                                                final long iax = it.aLong;
15078                                                final long ibx = it.bLong;
15079                                                final long iby = 0;
15080                                                double ox;
15081                                                double oy;
15082                                                if (Double.isNaN(iax) || Double.isNaN(iay)) {
15083                                                        ox = (iax);
15084                                                        oy = (iay);
15085                                                } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
15086                                                        ox = (ibx);
15087                                                        oy = (iby);
15088                                                } else {
15089                                                        ox = (double) (Math.min(iax, ibx));
15090                                                        oy = (double) (Math.min(iay, iby));
15091                                                }
15092                                                oc128data[it.oIndex] = ox;
15093                                                oc128data[it.oIndex + 1] = oy;
15094                                        }
15095                                }
15096                        } else if (!db.isComplex()) {
15097                                final double iby = 0;
15098                                while (it.hasNext()) {
15099                                        final double iax = it.aDouble;
15100                                        final double ibx = it.bDouble;
15101                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
15102                                        double ox;
15103                                        double oy;
15104                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
15105                                                ox = (iax);
15106                                                oy = (iay);
15107                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
15108                                                ox = (ibx);
15109                                                oy = (iby);
15110                                        } else {
15111                                                ox = (Math.min(iax, ibx));
15112                                                oy = (Math.min(iay, iby));
15113                                        }
15114                                        oc128data[it.oIndex] = ox;
15115                                        oc128data[it.oIndex + 1] = oy;
15116                                }
15117                        } else {
15118                                while (it.hasNext()) {
15119                                        final double iax = it.aDouble;
15120                                        final double ibx = it.bDouble;
15121                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
15122                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
15123                                        double ox;
15124                                        double oy;
15125                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
15126                                                ox = (iax);
15127                                                oy = (iay);
15128                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
15129                                                ox = (ibx);
15130                                                oy = (iby);
15131                                        } else {
15132                                                ox = (Math.min(iax, ibx));
15133                                                oy = (Math.min(iay, iby));
15134                                        }
15135                                        oc128data[it.oIndex] = ox;
15136                                        oc128data[it.oIndex + 1] = oy;
15137                                }
15138                        }
15139                        break;
15140                default:
15141                        throw new IllegalArgumentException("minimum supports integer, compound integer, real, compound real, complex datasets only");
15142                }
15143
15144                addBinaryOperatorName(da, db, result, "minimum");
15145                return result;
15146        }
15147
15148        /**
15149         * bitwiseAnd operator
15150         * @param a
15151         * @param b
15152         * @return {@code a & b}, bitwise AND of a and b
15153         */
15154        public static Dataset bitwiseAnd(final Object a, final Object b) {
15155                return bitwiseAnd(a, b, null);
15156        }
15157
15158        /**
15159         * bitwiseAnd operator
15160         * @param a
15161         * @param b
15162         * @param o output can be null - in which case, a new dataset is created
15163         * @return {@code a & b}, bitwise AND of a and b
15164         */
15165        public static Dataset bitwiseAnd(final Object a, final Object b, final Dataset o) {
15166                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
15167                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
15168                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
15169                it.setOutputDouble(false);
15170                final Dataset result = it.getOutput();
15171                if (!result.isComplex()) {
15172                        boolean change = false;
15173                        if (da.isComplex()) {
15174                                da = da.getRealView();
15175                                change = true;
15176                        }
15177                        if (db.isComplex()) {
15178                                db = db.getRealView();
15179                                change = true;
15180                        }
15181                        if (change) {
15182                                it = BroadcastIterator.createIterator(da, db, result, true);
15183                                it.setOutputDouble(false);
15184                        }
15185                }
15186                final int is = result.getElementsPerItem();
15187                final int as = da.getElementsPerItem();
15188                final int bs = db.getElementsPerItem();
15189                final int dt = result.getDType();
15190
15191                switch(dt) {
15192                case Dataset.INT8:
15193                        final byte[] oi8data = ((ByteDataset) result).getData();
15194                        {
15195                                while (it.hasNext()) {
15196                                        final long iax = it.aLong;
15197                                        final long ibx = it.bLong;
15198                                        byte ox;
15199                                        ox = (byte) (iax & ibx);
15200                                        oi8data[it.oIndex] = ox;
15201                                }
15202                        }
15203                        break;
15204                case Dataset.INT16:
15205                        final short[] oi16data = ((ShortDataset) result).getData();
15206                        {
15207                                while (it.hasNext()) {
15208                                        final long iax = it.aLong;
15209                                        final long ibx = it.bLong;
15210                                        short ox;
15211                                        ox = (short) (iax & ibx);
15212                                        oi16data[it.oIndex] = ox;
15213                                }
15214                        }
15215                        break;
15216                case Dataset.INT64:
15217                        final long[] oi64data = ((LongDataset) result).getData();
15218                        {
15219                                while (it.hasNext()) {
15220                                        final long iax = it.aLong;
15221                                        final long ibx = it.bLong;
15222                                        long ox;
15223                                        ox = (iax & ibx);
15224                                        oi64data[it.oIndex] = ox;
15225                                }
15226                        }
15227                        break;
15228                case Dataset.INT32:
15229                        final int[] oi32data = ((IntegerDataset) result).getData();
15230                        {
15231                                while (it.hasNext()) {
15232                                        final long iax = it.aLong;
15233                                        final long ibx = it.bLong;
15234                                        int ox;
15235                                        ox = (int) (iax & ibx);
15236                                        oi32data[it.oIndex] = ox;
15237                                }
15238                        }
15239                        break;
15240                case Dataset.ARRAYINT8:
15241                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
15242                        if (is == 1) {
15243                                {
15244                                        while (it.hasNext()) {
15245                                                final long iax = it.aLong;
15246                                                final long ibx = it.bLong;
15247                                                byte ox;
15248                                                ox = (byte) (iax & ibx);
15249                                                oai8data[it.oIndex] = ox;
15250                                        }
15251                                }
15252                        } else if (as < bs) {
15253                                {
15254                                        while (it.hasNext()) {
15255                                                final long iax = it.aLong;
15256                                                long ibx = it.bLong;
15257                                                byte ox;
15258                                                ox = (byte) (iax & ibx);
15259                                                oai8data[it.oIndex] = ox;
15260                                                for (int j = 1; j < is; j++) {
15261                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15262                                                        ox = (byte) (iax & ibx);
15263                                                        oai8data[it.oIndex + j] = ox;
15264                                                }
15265                                        }
15266                                }
15267                        } else if (as > bs) {
15268                                {
15269                                        while (it.hasNext()) {
15270                                                long iax = it.aLong;
15271                                                final long ibx = it.bLong;
15272                                                byte ox;
15273                                                ox = (byte) (iax & ibx);
15274                                                oai8data[it.oIndex] = ox;
15275                                                for (int j = 1; j < is; j++) {
15276                                                        iax = da.getElementLongAbs(it.aIndex + j);
15277                                                        ox = (byte) (iax & ibx);
15278                                                        oai8data[it.oIndex + j] = ox;
15279                                                }
15280                                        }
15281                                }
15282                        } else if (as == 1) {
15283                                {
15284                                        while (it.hasNext()) {
15285                                                final long iax = it.aLong;
15286                                                final long ibx = it.bLong;
15287                                                byte ox;
15288                                                ox = (byte) (iax & ibx);
15289                                                for (int j = 0; j < is; j++) {
15290                                                        oai8data[it.oIndex + j] = ox;
15291                                                }
15292                                        }
15293                                }
15294                        } else {
15295                                {
15296                                        while (it.hasNext()) {
15297                                                long iax = it.aLong;
15298                                                long ibx = it.bLong;
15299                                                byte ox;
15300                                                ox = (byte) (iax & ibx);
15301                                                oai8data[it.oIndex] = ox;
15302                                                for (int j = 1; j < is; j++) {
15303                                                        iax = da.getElementLongAbs(it.aIndex + j);
15304                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15305                                                        ox = (byte) (iax & ibx);
15306                                                        oai8data[it.oIndex + j] = ox;
15307                                                }
15308                                        }
15309                                }
15310                        }
15311                        break;
15312                case Dataset.ARRAYINT16:
15313                        final short[] oai16data = ((CompoundShortDataset) result).getData();
15314                        if (is == 1) {
15315                                {
15316                                        while (it.hasNext()) {
15317                                                final long iax = it.aLong;
15318                                                final long ibx = it.bLong;
15319                                                short ox;
15320                                                ox = (short) (iax & ibx);
15321                                                oai16data[it.oIndex] = ox;
15322                                        }
15323                                }
15324                        } else if (as < bs) {
15325                                {
15326                                        while (it.hasNext()) {
15327                                                final long iax = it.aLong;
15328                                                long ibx = it.bLong;
15329                                                short ox;
15330                                                ox = (short) (iax & ibx);
15331                                                oai16data[it.oIndex] = ox;
15332                                                for (int j = 1; j < is; j++) {
15333                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15334                                                        ox = (short) (iax & ibx);
15335                                                        oai16data[it.oIndex + j] = ox;
15336                                                }
15337                                        }
15338                                }
15339                        } else if (as > bs) {
15340                                {
15341                                        while (it.hasNext()) {
15342                                                long iax = it.aLong;
15343                                                final long ibx = it.bLong;
15344                                                short ox;
15345                                                ox = (short) (iax & ibx);
15346                                                oai16data[it.oIndex] = ox;
15347                                                for (int j = 1; j < is; j++) {
15348                                                        iax = da.getElementLongAbs(it.aIndex + j);
15349                                                        ox = (short) (iax & ibx);
15350                                                        oai16data[it.oIndex + j] = ox;
15351                                                }
15352                                        }
15353                                }
15354                        } else if (as == 1) {
15355                                {
15356                                        while (it.hasNext()) {
15357                                                final long iax = it.aLong;
15358                                                final long ibx = it.bLong;
15359                                                short ox;
15360                                                ox = (short) (iax & ibx);
15361                                                for (int j = 0; j < is; j++) {
15362                                                        oai16data[it.oIndex + j] = ox;
15363                                                }
15364                                        }
15365                                }
15366                        } else {
15367                                {
15368                                        while (it.hasNext()) {
15369                                                long iax = it.aLong;
15370                                                long ibx = it.bLong;
15371                                                short ox;
15372                                                ox = (short) (iax & ibx);
15373                                                oai16data[it.oIndex] = ox;
15374                                                for (int j = 1; j < is; j++) {
15375                                                        iax = da.getElementLongAbs(it.aIndex + j);
15376                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15377                                                        ox = (short) (iax & ibx);
15378                                                        oai16data[it.oIndex + j] = ox;
15379                                                }
15380                                        }
15381                                }
15382                        }
15383                        break;
15384                case Dataset.ARRAYINT64:
15385                        final long[] oai64data = ((CompoundLongDataset) result).getData();
15386                        if (is == 1) {
15387                                {
15388                                        while (it.hasNext()) {
15389                                                final long iax = it.aLong;
15390                                                final long ibx = it.bLong;
15391                                                long ox;
15392                                                ox = (iax & ibx);
15393                                                oai64data[it.oIndex] = ox;
15394                                        }
15395                                }
15396                        } else if (as < bs) {
15397                                {
15398                                        while (it.hasNext()) {
15399                                                final long iax = it.aLong;
15400                                                long ibx = it.bLong;
15401                                                long ox;
15402                                                ox = (iax & ibx);
15403                                                oai64data[it.oIndex] = ox;
15404                                                for (int j = 1; j < is; j++) {
15405                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15406                                                        ox = (iax & ibx);
15407                                                        oai64data[it.oIndex + j] = ox;
15408                                                }
15409                                        }
15410                                }
15411                        } else if (as > bs) {
15412                                {
15413                                        while (it.hasNext()) {
15414                                                long iax = it.aLong;
15415                                                final long ibx = it.bLong;
15416                                                long ox;
15417                                                ox = (iax & ibx);
15418                                                oai64data[it.oIndex] = ox;
15419                                                for (int j = 1; j < is; j++) {
15420                                                        iax = da.getElementLongAbs(it.aIndex + j);
15421                                                        ox = (iax & ibx);
15422                                                        oai64data[it.oIndex + j] = ox;
15423                                                }
15424                                        }
15425                                }
15426                        } else if (as == 1) {
15427                                {
15428                                        while (it.hasNext()) {
15429                                                final long iax = it.aLong;
15430                                                final long ibx = it.bLong;
15431                                                long ox;
15432                                                ox = (iax & ibx);
15433                                                for (int j = 0; j < is; j++) {
15434                                                        oai64data[it.oIndex + j] = ox;
15435                                                }
15436                                        }
15437                                }
15438                        } else {
15439                                {
15440                                        while (it.hasNext()) {
15441                                                long iax = it.aLong;
15442                                                long ibx = it.bLong;
15443                                                long ox;
15444                                                ox = (iax & ibx);
15445                                                oai64data[it.oIndex] = ox;
15446                                                for (int j = 1; j < is; j++) {
15447                                                        iax = da.getElementLongAbs(it.aIndex + j);
15448                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15449                                                        ox = (iax & ibx);
15450                                                        oai64data[it.oIndex + j] = ox;
15451                                                }
15452                                        }
15453                                }
15454                        }
15455                        break;
15456                case Dataset.ARRAYINT32:
15457                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
15458                        if (is == 1) {
15459                                {
15460                                        while (it.hasNext()) {
15461                                                final long iax = it.aLong;
15462                                                final long ibx = it.bLong;
15463                                                int ox;
15464                                                ox = (int) (iax & ibx);
15465                                                oai32data[it.oIndex] = ox;
15466                                        }
15467                                }
15468                        } else if (as < bs) {
15469                                {
15470                                        while (it.hasNext()) {
15471                                                final long iax = it.aLong;
15472                                                long ibx = it.bLong;
15473                                                int ox;
15474                                                ox = (int) (iax & ibx);
15475                                                oai32data[it.oIndex] = ox;
15476                                                for (int j = 1; j < is; j++) {
15477                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15478                                                        ox = (int) (iax & ibx);
15479                                                        oai32data[it.oIndex + j] = ox;
15480                                                }
15481                                        }
15482                                }
15483                        } else if (as > bs) {
15484                                {
15485                                        while (it.hasNext()) {
15486                                                long iax = it.aLong;
15487                                                final long ibx = it.bLong;
15488                                                int ox;
15489                                                ox = (int) (iax & ibx);
15490                                                oai32data[it.oIndex] = ox;
15491                                                for (int j = 1; j < is; j++) {
15492                                                        iax = da.getElementLongAbs(it.aIndex + j);
15493                                                        ox = (int) (iax & ibx);
15494                                                        oai32data[it.oIndex + j] = ox;
15495                                                }
15496                                        }
15497                                }
15498                        } else if (as == 1) {
15499                                {
15500                                        while (it.hasNext()) {
15501                                                final long iax = it.aLong;
15502                                                final long ibx = it.bLong;
15503                                                int ox;
15504                                                ox = (int) (iax & ibx);
15505                                                for (int j = 0; j < is; j++) {
15506                                                        oai32data[it.oIndex + j] = ox;
15507                                                }
15508                                        }
15509                                }
15510                        } else {
15511                                {
15512                                        while (it.hasNext()) {
15513                                                long iax = it.aLong;
15514                                                long ibx = it.bLong;
15515                                                int ox;
15516                                                ox = (int) (iax & ibx);
15517                                                oai32data[it.oIndex] = ox;
15518                                                for (int j = 1; j < is; j++) {
15519                                                        iax = da.getElementLongAbs(it.aIndex + j);
15520                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15521                                                        ox = (int) (iax & ibx);
15522                                                        oai32data[it.oIndex + j] = ox;
15523                                                }
15524                                        }
15525                                }
15526                        }
15527                        break;
15528                default:
15529                        throw new IllegalArgumentException("bitwiseAnd supports integer, compound integer datasets only");
15530                }
15531
15532                addBinaryOperatorName(da, db, result, "&");
15533                return result;
15534        }
15535
15536        /**
15537         * bitwiseOr operator
15538         * @param a
15539         * @param b
15540         * @return {@code a | b}, bitwise inclusive OR of a and b
15541         */
15542        public static Dataset bitwiseOr(final Object a, final Object b) {
15543                return bitwiseOr(a, b, null);
15544        }
15545
15546        /**
15547         * bitwiseOr operator
15548         * @param a
15549         * @param b
15550         * @param o output can be null - in which case, a new dataset is created
15551         * @return {@code a | b}, bitwise inclusive OR of a and b
15552         */
15553        public static Dataset bitwiseOr(final Object a, final Object b, final Dataset o) {
15554                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
15555                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
15556                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
15557                it.setOutputDouble(false);
15558                final Dataset result = it.getOutput();
15559                if (!result.isComplex()) {
15560                        boolean change = false;
15561                        if (da.isComplex()) {
15562                                da = da.getRealView();
15563                                change = true;
15564                        }
15565                        if (db.isComplex()) {
15566                                db = db.getRealView();
15567                                change = true;
15568                        }
15569                        if (change) {
15570                                it = BroadcastIterator.createIterator(da, db, result, true);
15571                                it.setOutputDouble(false);
15572                        }
15573                }
15574                final int is = result.getElementsPerItem();
15575                final int as = da.getElementsPerItem();
15576                final int bs = db.getElementsPerItem();
15577                final int dt = result.getDType();
15578
15579                switch(dt) {
15580                case Dataset.INT8:
15581                        final byte[] oi8data = ((ByteDataset) result).getData();
15582                        {
15583                                while (it.hasNext()) {
15584                                        final long iax = it.aLong;
15585                                        final long ibx = it.bLong;
15586                                        byte ox;
15587                                        ox = (byte) (iax | ibx);
15588                                        oi8data[it.oIndex] = ox;
15589                                }
15590                        }
15591                        break;
15592                case Dataset.INT16:
15593                        final short[] oi16data = ((ShortDataset) result).getData();
15594                        {
15595                                while (it.hasNext()) {
15596                                        final long iax = it.aLong;
15597                                        final long ibx = it.bLong;
15598                                        short ox;
15599                                        ox = (short) (iax | ibx);
15600                                        oi16data[it.oIndex] = ox;
15601                                }
15602                        }
15603                        break;
15604                case Dataset.INT64:
15605                        final long[] oi64data = ((LongDataset) result).getData();
15606                        {
15607                                while (it.hasNext()) {
15608                                        final long iax = it.aLong;
15609                                        final long ibx = it.bLong;
15610                                        long ox;
15611                                        ox = (iax | ibx);
15612                                        oi64data[it.oIndex] = ox;
15613                                }
15614                        }
15615                        break;
15616                case Dataset.INT32:
15617                        final int[] oi32data = ((IntegerDataset) result).getData();
15618                        {
15619                                while (it.hasNext()) {
15620                                        final long iax = it.aLong;
15621                                        final long ibx = it.bLong;
15622                                        int ox;
15623                                        ox = (int) (iax | ibx);
15624                                        oi32data[it.oIndex] = ox;
15625                                }
15626                        }
15627                        break;
15628                case Dataset.ARRAYINT8:
15629                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
15630                        if (is == 1) {
15631                                {
15632                                        while (it.hasNext()) {
15633                                                final long iax = it.aLong;
15634                                                final long ibx = it.bLong;
15635                                                byte ox;
15636                                                ox = (byte) (iax | ibx);
15637                                                oai8data[it.oIndex] = ox;
15638                                        }
15639                                }
15640                        } else if (as < bs) {
15641                                {
15642                                        while (it.hasNext()) {
15643                                                final long iax = it.aLong;
15644                                                long ibx = it.bLong;
15645                                                byte ox;
15646                                                ox = (byte) (iax | ibx);
15647                                                oai8data[it.oIndex] = ox;
15648                                                for (int j = 1; j < is; j++) {
15649                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15650                                                        ox = (byte) (iax | ibx);
15651                                                        oai8data[it.oIndex + j] = ox;
15652                                                }
15653                                        }
15654                                }
15655                        } else if (as > bs) {
15656                                {
15657                                        while (it.hasNext()) {
15658                                                long iax = it.aLong;
15659                                                final long ibx = it.bLong;
15660                                                byte ox;
15661                                                ox = (byte) (iax | ibx);
15662                                                oai8data[it.oIndex] = ox;
15663                                                for (int j = 1; j < is; j++) {
15664                                                        iax = da.getElementLongAbs(it.aIndex + j);
15665                                                        ox = (byte) (iax | ibx);
15666                                                        oai8data[it.oIndex + j] = ox;
15667                                                }
15668                                        }
15669                                }
15670                        } else if (as == 1) {
15671                                {
15672                                        while (it.hasNext()) {
15673                                                final long iax = it.aLong;
15674                                                final long ibx = it.bLong;
15675                                                byte ox;
15676                                                ox = (byte) (iax | ibx);
15677                                                for (int j = 0; j < is; j++) {
15678                                                        oai8data[it.oIndex + j] = ox;
15679                                                }
15680                                        }
15681                                }
15682                        } else {
15683                                {
15684                                        while (it.hasNext()) {
15685                                                long iax = it.aLong;
15686                                                long ibx = it.bLong;
15687                                                byte ox;
15688                                                ox = (byte) (iax | ibx);
15689                                                oai8data[it.oIndex] = ox;
15690                                                for (int j = 1; j < is; j++) {
15691                                                        iax = da.getElementLongAbs(it.aIndex + j);
15692                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15693                                                        ox = (byte) (iax | ibx);
15694                                                        oai8data[it.oIndex + j] = ox;
15695                                                }
15696                                        }
15697                                }
15698                        }
15699                        break;
15700                case Dataset.ARRAYINT16:
15701                        final short[] oai16data = ((CompoundShortDataset) result).getData();
15702                        if (is == 1) {
15703                                {
15704                                        while (it.hasNext()) {
15705                                                final long iax = it.aLong;
15706                                                final long ibx = it.bLong;
15707                                                short ox;
15708                                                ox = (short) (iax | ibx);
15709                                                oai16data[it.oIndex] = ox;
15710                                        }
15711                                }
15712                        } else if (as < bs) {
15713                                {
15714                                        while (it.hasNext()) {
15715                                                final long iax = it.aLong;
15716                                                long ibx = it.bLong;
15717                                                short ox;
15718                                                ox = (short) (iax | ibx);
15719                                                oai16data[it.oIndex] = ox;
15720                                                for (int j = 1; j < is; j++) {
15721                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15722                                                        ox = (short) (iax | ibx);
15723                                                        oai16data[it.oIndex + j] = ox;
15724                                                }
15725                                        }
15726                                }
15727                        } else if (as > bs) {
15728                                {
15729                                        while (it.hasNext()) {
15730                                                long iax = it.aLong;
15731                                                final long ibx = it.bLong;
15732                                                short ox;
15733                                                ox = (short) (iax | ibx);
15734                                                oai16data[it.oIndex] = ox;
15735                                                for (int j = 1; j < is; j++) {
15736                                                        iax = da.getElementLongAbs(it.aIndex + j);
15737                                                        ox = (short) (iax | ibx);
15738                                                        oai16data[it.oIndex + j] = ox;
15739                                                }
15740                                        }
15741                                }
15742                        } else if (as == 1) {
15743                                {
15744                                        while (it.hasNext()) {
15745                                                final long iax = it.aLong;
15746                                                final long ibx = it.bLong;
15747                                                short ox;
15748                                                ox = (short) (iax | ibx);
15749                                                for (int j = 0; j < is; j++) {
15750                                                        oai16data[it.oIndex + j] = ox;
15751                                                }
15752                                        }
15753                                }
15754                        } else {
15755                                {
15756                                        while (it.hasNext()) {
15757                                                long iax = it.aLong;
15758                                                long ibx = it.bLong;
15759                                                short ox;
15760                                                ox = (short) (iax | ibx);
15761                                                oai16data[it.oIndex] = ox;
15762                                                for (int j = 1; j < is; j++) {
15763                                                        iax = da.getElementLongAbs(it.aIndex + j);
15764                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15765                                                        ox = (short) (iax | ibx);
15766                                                        oai16data[it.oIndex + j] = ox;
15767                                                }
15768                                        }
15769                                }
15770                        }
15771                        break;
15772                case Dataset.ARRAYINT64:
15773                        final long[] oai64data = ((CompoundLongDataset) result).getData();
15774                        if (is == 1) {
15775                                {
15776                                        while (it.hasNext()) {
15777                                                final long iax = it.aLong;
15778                                                final long ibx = it.bLong;
15779                                                long ox;
15780                                                ox = (iax | ibx);
15781                                                oai64data[it.oIndex] = ox;
15782                                        }
15783                                }
15784                        } else if (as < bs) {
15785                                {
15786                                        while (it.hasNext()) {
15787                                                final long iax = it.aLong;
15788                                                long ibx = it.bLong;
15789                                                long ox;
15790                                                ox = (iax | ibx);
15791                                                oai64data[it.oIndex] = ox;
15792                                                for (int j = 1; j < is; j++) {
15793                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15794                                                        ox = (iax | ibx);
15795                                                        oai64data[it.oIndex + j] = ox;
15796                                                }
15797                                        }
15798                                }
15799                        } else if (as > bs) {
15800                                {
15801                                        while (it.hasNext()) {
15802                                                long iax = it.aLong;
15803                                                final long ibx = it.bLong;
15804                                                long ox;
15805                                                ox = (iax | ibx);
15806                                                oai64data[it.oIndex] = ox;
15807                                                for (int j = 1; j < is; j++) {
15808                                                        iax = da.getElementLongAbs(it.aIndex + j);
15809                                                        ox = (iax | ibx);
15810                                                        oai64data[it.oIndex + j] = ox;
15811                                                }
15812                                        }
15813                                }
15814                        } else if (as == 1) {
15815                                {
15816                                        while (it.hasNext()) {
15817                                                final long iax = it.aLong;
15818                                                final long ibx = it.bLong;
15819                                                long ox;
15820                                                ox = (iax | ibx);
15821                                                for (int j = 0; j < is; j++) {
15822                                                        oai64data[it.oIndex + j] = ox;
15823                                                }
15824                                        }
15825                                }
15826                        } else {
15827                                {
15828                                        while (it.hasNext()) {
15829                                                long iax = it.aLong;
15830                                                long ibx = it.bLong;
15831                                                long ox;
15832                                                ox = (iax | ibx);
15833                                                oai64data[it.oIndex] = ox;
15834                                                for (int j = 1; j < is; j++) {
15835                                                        iax = da.getElementLongAbs(it.aIndex + j);
15836                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15837                                                        ox = (iax | ibx);
15838                                                        oai64data[it.oIndex + j] = ox;
15839                                                }
15840                                        }
15841                                }
15842                        }
15843                        break;
15844                case Dataset.ARRAYINT32:
15845                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
15846                        if (is == 1) {
15847                                {
15848                                        while (it.hasNext()) {
15849                                                final long iax = it.aLong;
15850                                                final long ibx = it.bLong;
15851                                                int ox;
15852                                                ox = (int) (iax | ibx);
15853                                                oai32data[it.oIndex] = ox;
15854                                        }
15855                                }
15856                        } else if (as < bs) {
15857                                {
15858                                        while (it.hasNext()) {
15859                                                final long iax = it.aLong;
15860                                                long ibx = it.bLong;
15861                                                int ox;
15862                                                ox = (int) (iax | ibx);
15863                                                oai32data[it.oIndex] = ox;
15864                                                for (int j = 1; j < is; j++) {
15865                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15866                                                        ox = (int) (iax | ibx);
15867                                                        oai32data[it.oIndex + j] = ox;
15868                                                }
15869                                        }
15870                                }
15871                        } else if (as > bs) {
15872                                {
15873                                        while (it.hasNext()) {
15874                                                long iax = it.aLong;
15875                                                final long ibx = it.bLong;
15876                                                int ox;
15877                                                ox = (int) (iax | ibx);
15878                                                oai32data[it.oIndex] = ox;
15879                                                for (int j = 1; j < is; j++) {
15880                                                        iax = da.getElementLongAbs(it.aIndex + j);
15881                                                        ox = (int) (iax | ibx);
15882                                                        oai32data[it.oIndex + j] = ox;
15883                                                }
15884                                        }
15885                                }
15886                        } else if (as == 1) {
15887                                {
15888                                        while (it.hasNext()) {
15889                                                final long iax = it.aLong;
15890                                                final long ibx = it.bLong;
15891                                                int ox;
15892                                                ox = (int) (iax | ibx);
15893                                                for (int j = 0; j < is; j++) {
15894                                                        oai32data[it.oIndex + j] = ox;
15895                                                }
15896                                        }
15897                                }
15898                        } else {
15899                                {
15900                                        while (it.hasNext()) {
15901                                                long iax = it.aLong;
15902                                                long ibx = it.bLong;
15903                                                int ox;
15904                                                ox = (int) (iax | ibx);
15905                                                oai32data[it.oIndex] = ox;
15906                                                for (int j = 1; j < is; j++) {
15907                                                        iax = da.getElementLongAbs(it.aIndex + j);
15908                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15909                                                        ox = (int) (iax | ibx);
15910                                                        oai32data[it.oIndex + j] = ox;
15911                                                }
15912                                        }
15913                                }
15914                        }
15915                        break;
15916                default:
15917                        throw new IllegalArgumentException("bitwiseOr supports integer, compound integer datasets only");
15918                }
15919
15920                addBinaryOperatorName(da, db, result, "|");
15921                return result;
15922        }
15923
15924        /**
15925         * bitwiseXor operator
15926         * @param a
15927         * @param b
15928         * @return {@code a ^ b}, bitwise exclusive OR of a and b
15929         */
15930        public static Dataset bitwiseXor(final Object a, final Object b) {
15931                return bitwiseXor(a, b, null);
15932        }
15933
15934        /**
15935         * bitwiseXor operator
15936         * @param a
15937         * @param b
15938         * @param o output can be null - in which case, a new dataset is created
15939         * @return {@code a ^ b}, bitwise exclusive OR of a and b
15940         */
15941        public static Dataset bitwiseXor(final Object a, final Object b, final Dataset o) {
15942                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
15943                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
15944                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
15945                it.setOutputDouble(false);
15946                final Dataset result = it.getOutput();
15947                if (!result.isComplex()) {
15948                        boolean change = false;
15949                        if (da.isComplex()) {
15950                                da = da.getRealView();
15951                                change = true;
15952                        }
15953                        if (db.isComplex()) {
15954                                db = db.getRealView();
15955                                change = true;
15956                        }
15957                        if (change) {
15958                                it = BroadcastIterator.createIterator(da, db, result, true);
15959                                it.setOutputDouble(false);
15960                        }
15961                }
15962                final int is = result.getElementsPerItem();
15963                final int as = da.getElementsPerItem();
15964                final int bs = db.getElementsPerItem();
15965                final int dt = result.getDType();
15966
15967                switch(dt) {
15968                case Dataset.INT8:
15969                        final byte[] oi8data = ((ByteDataset) result).getData();
15970                        {
15971                                while (it.hasNext()) {
15972                                        final long iax = it.aLong;
15973                                        final long ibx = it.bLong;
15974                                        byte ox;
15975                                        ox = (byte) (iax ^ ibx);
15976                                        oi8data[it.oIndex] = ox;
15977                                }
15978                        }
15979                        break;
15980                case Dataset.INT16:
15981                        final short[] oi16data = ((ShortDataset) result).getData();
15982                        {
15983                                while (it.hasNext()) {
15984                                        final long iax = it.aLong;
15985                                        final long ibx = it.bLong;
15986                                        short ox;
15987                                        ox = (short) (iax ^ ibx);
15988                                        oi16data[it.oIndex] = ox;
15989                                }
15990                        }
15991                        break;
15992                case Dataset.INT64:
15993                        final long[] oi64data = ((LongDataset) result).getData();
15994                        {
15995                                while (it.hasNext()) {
15996                                        final long iax = it.aLong;
15997                                        final long ibx = it.bLong;
15998                                        long ox;
15999                                        ox = (iax ^ ibx);
16000                                        oi64data[it.oIndex] = ox;
16001                                }
16002                        }
16003                        break;
16004                case Dataset.INT32:
16005                        final int[] oi32data = ((IntegerDataset) result).getData();
16006                        {
16007                                while (it.hasNext()) {
16008                                        final long iax = it.aLong;
16009                                        final long ibx = it.bLong;
16010                                        int ox;
16011                                        ox = (int) (iax ^ ibx);
16012                                        oi32data[it.oIndex] = ox;
16013                                }
16014                        }
16015                        break;
16016                case Dataset.ARRAYINT8:
16017                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
16018                        if (is == 1) {
16019                                {
16020                                        while (it.hasNext()) {
16021                                                final long iax = it.aLong;
16022                                                final long ibx = it.bLong;
16023                                                byte ox;
16024                                                ox = (byte) (iax ^ ibx);
16025                                                oai8data[it.oIndex] = ox;
16026                                        }
16027                                }
16028                        } else if (as < bs) {
16029                                {
16030                                        while (it.hasNext()) {
16031                                                final long iax = it.aLong;
16032                                                long ibx = it.bLong;
16033                                                byte ox;
16034                                                ox = (byte) (iax ^ ibx);
16035                                                oai8data[it.oIndex] = ox;
16036                                                for (int j = 1; j < is; j++) {
16037                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16038                                                        ox = (byte) (iax ^ ibx);
16039                                                        oai8data[it.oIndex + j] = ox;
16040                                                }
16041                                        }
16042                                }
16043                        } else if (as > bs) {
16044                                {
16045                                        while (it.hasNext()) {
16046                                                long iax = it.aLong;
16047                                                final long ibx = it.bLong;
16048                                                byte ox;
16049                                                ox = (byte) (iax ^ ibx);
16050                                                oai8data[it.oIndex] = ox;
16051                                                for (int j = 1; j < is; j++) {
16052                                                        iax = da.getElementLongAbs(it.aIndex + j);
16053                                                        ox = (byte) (iax ^ ibx);
16054                                                        oai8data[it.oIndex + j] = ox;
16055                                                }
16056                                        }
16057                                }
16058                        } else if (as == 1) {
16059                                {
16060                                        while (it.hasNext()) {
16061                                                final long iax = it.aLong;
16062                                                final long ibx = it.bLong;
16063                                                byte ox;
16064                                                ox = (byte) (iax ^ ibx);
16065                                                for (int j = 0; j < is; j++) {
16066                                                        oai8data[it.oIndex + j] = ox;
16067                                                }
16068                                        }
16069                                }
16070                        } else {
16071                                {
16072                                        while (it.hasNext()) {
16073                                                long iax = it.aLong;
16074                                                long ibx = it.bLong;
16075                                                byte ox;
16076                                                ox = (byte) (iax ^ ibx);
16077                                                oai8data[it.oIndex] = ox;
16078                                                for (int j = 1; j < is; j++) {
16079                                                        iax = da.getElementLongAbs(it.aIndex + j);
16080                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16081                                                        ox = (byte) (iax ^ ibx);
16082                                                        oai8data[it.oIndex + j] = ox;
16083                                                }
16084                                        }
16085                                }
16086                        }
16087                        break;
16088                case Dataset.ARRAYINT16:
16089                        final short[] oai16data = ((CompoundShortDataset) result).getData();
16090                        if (is == 1) {
16091                                {
16092                                        while (it.hasNext()) {
16093                                                final long iax = it.aLong;
16094                                                final long ibx = it.bLong;
16095                                                short ox;
16096                                                ox = (short) (iax ^ ibx);
16097                                                oai16data[it.oIndex] = ox;
16098                                        }
16099                                }
16100                        } else if (as < bs) {
16101                                {
16102                                        while (it.hasNext()) {
16103                                                final long iax = it.aLong;
16104                                                long ibx = it.bLong;
16105                                                short ox;
16106                                                ox = (short) (iax ^ ibx);
16107                                                oai16data[it.oIndex] = ox;
16108                                                for (int j = 1; j < is; j++) {
16109                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16110                                                        ox = (short) (iax ^ ibx);
16111                                                        oai16data[it.oIndex + j] = ox;
16112                                                }
16113                                        }
16114                                }
16115                        } else if (as > bs) {
16116                                {
16117                                        while (it.hasNext()) {
16118                                                long iax = it.aLong;
16119                                                final long ibx = it.bLong;
16120                                                short ox;
16121                                                ox = (short) (iax ^ ibx);
16122                                                oai16data[it.oIndex] = ox;
16123                                                for (int j = 1; j < is; j++) {
16124                                                        iax = da.getElementLongAbs(it.aIndex + j);
16125                                                        ox = (short) (iax ^ ibx);
16126                                                        oai16data[it.oIndex + j] = ox;
16127                                                }
16128                                        }
16129                                }
16130                        } else if (as == 1) {
16131                                {
16132                                        while (it.hasNext()) {
16133                                                final long iax = it.aLong;
16134                                                final long ibx = it.bLong;
16135                                                short ox;
16136                                                ox = (short) (iax ^ ibx);
16137                                                for (int j = 0; j < is; j++) {
16138                                                        oai16data[it.oIndex + j] = ox;
16139                                                }
16140                                        }
16141                                }
16142                        } else {
16143                                {
16144                                        while (it.hasNext()) {
16145                                                long iax = it.aLong;
16146                                                long ibx = it.bLong;
16147                                                short ox;
16148                                                ox = (short) (iax ^ ibx);
16149                                                oai16data[it.oIndex] = ox;
16150                                                for (int j = 1; j < is; j++) {
16151                                                        iax = da.getElementLongAbs(it.aIndex + j);
16152                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16153                                                        ox = (short) (iax ^ ibx);
16154                                                        oai16data[it.oIndex + j] = ox;
16155                                                }
16156                                        }
16157                                }
16158                        }
16159                        break;
16160                case Dataset.ARRAYINT64:
16161                        final long[] oai64data = ((CompoundLongDataset) result).getData();
16162                        if (is == 1) {
16163                                {
16164                                        while (it.hasNext()) {
16165                                                final long iax = it.aLong;
16166                                                final long ibx = it.bLong;
16167                                                long ox;
16168                                                ox = (iax ^ ibx);
16169                                                oai64data[it.oIndex] = ox;
16170                                        }
16171                                }
16172                        } else if (as < bs) {
16173                                {
16174                                        while (it.hasNext()) {
16175                                                final long iax = it.aLong;
16176                                                long ibx = it.bLong;
16177                                                long ox;
16178                                                ox = (iax ^ ibx);
16179                                                oai64data[it.oIndex] = ox;
16180                                                for (int j = 1; j < is; j++) {
16181                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16182                                                        ox = (iax ^ ibx);
16183                                                        oai64data[it.oIndex + j] = ox;
16184                                                }
16185                                        }
16186                                }
16187                        } else if (as > bs) {
16188                                {
16189                                        while (it.hasNext()) {
16190                                                long iax = it.aLong;
16191                                                final long ibx = it.bLong;
16192                                                long ox;
16193                                                ox = (iax ^ ibx);
16194                                                oai64data[it.oIndex] = ox;
16195                                                for (int j = 1; j < is; j++) {
16196                                                        iax = da.getElementLongAbs(it.aIndex + j);
16197                                                        ox = (iax ^ ibx);
16198                                                        oai64data[it.oIndex + j] = ox;
16199                                                }
16200                                        }
16201                                }
16202                        } else if (as == 1) {
16203                                {
16204                                        while (it.hasNext()) {
16205                                                final long iax = it.aLong;
16206                                                final long ibx = it.bLong;
16207                                                long ox;
16208                                                ox = (iax ^ ibx);
16209                                                for (int j = 0; j < is; j++) {
16210                                                        oai64data[it.oIndex + j] = ox;
16211                                                }
16212                                        }
16213                                }
16214                        } else {
16215                                {
16216                                        while (it.hasNext()) {
16217                                                long iax = it.aLong;
16218                                                long ibx = it.bLong;
16219                                                long ox;
16220                                                ox = (iax ^ ibx);
16221                                                oai64data[it.oIndex] = ox;
16222                                                for (int j = 1; j < is; j++) {
16223                                                        iax = da.getElementLongAbs(it.aIndex + j);
16224                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16225                                                        ox = (iax ^ ibx);
16226                                                        oai64data[it.oIndex + j] = ox;
16227                                                }
16228                                        }
16229                                }
16230                        }
16231                        break;
16232                case Dataset.ARRAYINT32:
16233                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
16234                        if (is == 1) {
16235                                {
16236                                        while (it.hasNext()) {
16237                                                final long iax = it.aLong;
16238                                                final long ibx = it.bLong;
16239                                                int ox;
16240                                                ox = (int) (iax ^ ibx);
16241                                                oai32data[it.oIndex] = ox;
16242                                        }
16243                                }
16244                        } else if (as < bs) {
16245                                {
16246                                        while (it.hasNext()) {
16247                                                final long iax = it.aLong;
16248                                                long ibx = it.bLong;
16249                                                int ox;
16250                                                ox = (int) (iax ^ ibx);
16251                                                oai32data[it.oIndex] = ox;
16252                                                for (int j = 1; j < is; j++) {
16253                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16254                                                        ox = (int) (iax ^ ibx);
16255                                                        oai32data[it.oIndex + j] = ox;
16256                                                }
16257                                        }
16258                                }
16259                        } else if (as > bs) {
16260                                {
16261                                        while (it.hasNext()) {
16262                                                long iax = it.aLong;
16263                                                final long ibx = it.bLong;
16264                                                int ox;
16265                                                ox = (int) (iax ^ ibx);
16266                                                oai32data[it.oIndex] = ox;
16267                                                for (int j = 1; j < is; j++) {
16268                                                        iax = da.getElementLongAbs(it.aIndex + j);
16269                                                        ox = (int) (iax ^ ibx);
16270                                                        oai32data[it.oIndex + j] = ox;
16271                                                }
16272                                        }
16273                                }
16274                        } else if (as == 1) {
16275                                {
16276                                        while (it.hasNext()) {
16277                                                final long iax = it.aLong;
16278                                                final long ibx = it.bLong;
16279                                                int ox;
16280                                                ox = (int) (iax ^ ibx);
16281                                                for (int j = 0; j < is; j++) {
16282                                                        oai32data[it.oIndex + j] = ox;
16283                                                }
16284                                        }
16285                                }
16286                        } else {
16287                                {
16288                                        while (it.hasNext()) {
16289                                                long iax = it.aLong;
16290                                                long ibx = it.bLong;
16291                                                int ox;
16292                                                ox = (int) (iax ^ ibx);
16293                                                oai32data[it.oIndex] = ox;
16294                                                for (int j = 1; j < is; j++) {
16295                                                        iax = da.getElementLongAbs(it.aIndex + j);
16296                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16297                                                        ox = (int) (iax ^ ibx);
16298                                                        oai32data[it.oIndex + j] = ox;
16299                                                }
16300                                        }
16301                                }
16302                        }
16303                        break;
16304                default:
16305                        throw new IllegalArgumentException("bitwiseXor supports integer, compound integer datasets only");
16306                }
16307
16308                addBinaryOperatorName(da, db, result, "^");
16309                return result;
16310        }
16311
16312        /**
16313         * leftShift operator
16314         * @param a
16315         * @param b
16316         * @return {@code a << b}, bitwise left shift of a by b
16317         */
16318        public static Dataset leftShift(final Object a, final Object b) {
16319                return leftShift(a, b, null);
16320        }
16321
16322        /**
16323         * leftShift operator
16324         * @param a
16325         * @param b
16326         * @param o output can be null - in which case, a new dataset is created
16327         * @return {@code a << b}, bitwise left shift of a by b
16328         */
16329        public static Dataset leftShift(final Object a, final Object b, final Dataset o) {
16330                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
16331                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
16332                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
16333                it.setOutputDouble(false);
16334                final Dataset result = it.getOutput();
16335                if (!result.isComplex()) {
16336                        boolean change = false;
16337                        if (da.isComplex()) {
16338                                da = da.getRealView();
16339                                change = true;
16340                        }
16341                        if (db.isComplex()) {
16342                                db = db.getRealView();
16343                                change = true;
16344                        }
16345                        if (change) {
16346                                it = BroadcastIterator.createIterator(da, db, result, true);
16347                                it.setOutputDouble(false);
16348                        }
16349                }
16350                final int is = result.getElementsPerItem();
16351                final int as = da.getElementsPerItem();
16352                final int bs = db.getElementsPerItem();
16353                final int dt = result.getDType();
16354
16355                switch(dt) {
16356                case Dataset.INT8:
16357                        final byte[] oi8data = ((ByteDataset) result).getData();
16358                        {
16359                                while (it.hasNext()) {
16360                                        final long iax = it.aLong;
16361                                        final long ibx = it.bLong;
16362                                        byte ox;
16363                                        ox = (byte) (iax << ibx);
16364                                        oi8data[it.oIndex] = ox;
16365                                }
16366                        }
16367                        break;
16368                case Dataset.INT16:
16369                        final short[] oi16data = ((ShortDataset) result).getData();
16370                        {
16371                                while (it.hasNext()) {
16372                                        final long iax = it.aLong;
16373                                        final long ibx = it.bLong;
16374                                        short ox;
16375                                        ox = (short) (iax << ibx);
16376                                        oi16data[it.oIndex] = ox;
16377                                }
16378                        }
16379                        break;
16380                case Dataset.INT64:
16381                        final long[] oi64data = ((LongDataset) result).getData();
16382                        {
16383                                while (it.hasNext()) {
16384                                        final long iax = it.aLong;
16385                                        final long ibx = it.bLong;
16386                                        long ox;
16387                                        ox = (iax << ibx);
16388                                        oi64data[it.oIndex] = ox;
16389                                }
16390                        }
16391                        break;
16392                case Dataset.INT32:
16393                        final int[] oi32data = ((IntegerDataset) result).getData();
16394                        {
16395                                while (it.hasNext()) {
16396                                        final long iax = it.aLong;
16397                                        final long ibx = it.bLong;
16398                                        int ox;
16399                                        ox = (int) (iax << ibx);
16400                                        oi32data[it.oIndex] = ox;
16401                                }
16402                        }
16403                        break;
16404                case Dataset.ARRAYINT8:
16405                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
16406                        if (is == 1) {
16407                                {
16408                                        while (it.hasNext()) {
16409                                                final long iax = it.aLong;
16410                                                final long ibx = it.bLong;
16411                                                byte ox;
16412                                                ox = (byte) (iax << ibx);
16413                                                oai8data[it.oIndex] = ox;
16414                                        }
16415                                }
16416                        } else if (as < bs) {
16417                                {
16418                                        while (it.hasNext()) {
16419                                                final long iax = it.aLong;
16420                                                long ibx = it.bLong;
16421                                                byte ox;
16422                                                ox = (byte) (iax << ibx);
16423                                                oai8data[it.oIndex] = ox;
16424                                                for (int j = 1; j < is; j++) {
16425                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16426                                                        ox = (byte) (iax << ibx);
16427                                                        oai8data[it.oIndex + j] = ox;
16428                                                }
16429                                        }
16430                                }
16431                        } else if (as > bs) {
16432                                {
16433                                        while (it.hasNext()) {
16434                                                long iax = it.aLong;
16435                                                final long ibx = it.bLong;
16436                                                byte ox;
16437                                                ox = (byte) (iax << ibx);
16438                                                oai8data[it.oIndex] = ox;
16439                                                for (int j = 1; j < is; j++) {
16440                                                        iax = da.getElementLongAbs(it.aIndex + j);
16441                                                        ox = (byte) (iax << ibx);
16442                                                        oai8data[it.oIndex + j] = ox;
16443                                                }
16444                                        }
16445                                }
16446                        } else if (as == 1) {
16447                                {
16448                                        while (it.hasNext()) {
16449                                                final long iax = it.aLong;
16450                                                final long ibx = it.bLong;
16451                                                byte ox;
16452                                                ox = (byte) (iax << ibx);
16453                                                for (int j = 0; j < is; j++) {
16454                                                        oai8data[it.oIndex + j] = ox;
16455                                                }
16456                                        }
16457                                }
16458                        } else {
16459                                {
16460                                        while (it.hasNext()) {
16461                                                long iax = it.aLong;
16462                                                long ibx = it.bLong;
16463                                                byte ox;
16464                                                ox = (byte) (iax << ibx);
16465                                                oai8data[it.oIndex] = ox;
16466                                                for (int j = 1; j < is; j++) {
16467                                                        iax = da.getElementLongAbs(it.aIndex + j);
16468                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16469                                                        ox = (byte) (iax << ibx);
16470                                                        oai8data[it.oIndex + j] = ox;
16471                                                }
16472                                        }
16473                                }
16474                        }
16475                        break;
16476                case Dataset.ARRAYINT16:
16477                        final short[] oai16data = ((CompoundShortDataset) result).getData();
16478                        if (is == 1) {
16479                                {
16480                                        while (it.hasNext()) {
16481                                                final long iax = it.aLong;
16482                                                final long ibx = it.bLong;
16483                                                short ox;
16484                                                ox = (short) (iax << ibx);
16485                                                oai16data[it.oIndex] = ox;
16486                                        }
16487                                }
16488                        } else if (as < bs) {
16489                                {
16490                                        while (it.hasNext()) {
16491                                                final long iax = it.aLong;
16492                                                long ibx = it.bLong;
16493                                                short ox;
16494                                                ox = (short) (iax << ibx);
16495                                                oai16data[it.oIndex] = ox;
16496                                                for (int j = 1; j < is; j++) {
16497                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16498                                                        ox = (short) (iax << ibx);
16499                                                        oai16data[it.oIndex + j] = ox;
16500                                                }
16501                                        }
16502                                }
16503                        } else if (as > bs) {
16504                                {
16505                                        while (it.hasNext()) {
16506                                                long iax = it.aLong;
16507                                                final long ibx = it.bLong;
16508                                                short ox;
16509                                                ox = (short) (iax << ibx);
16510                                                oai16data[it.oIndex] = ox;
16511                                                for (int j = 1; j < is; j++) {
16512                                                        iax = da.getElementLongAbs(it.aIndex + j);
16513                                                        ox = (short) (iax << ibx);
16514                                                        oai16data[it.oIndex + j] = ox;
16515                                                }
16516                                        }
16517                                }
16518                        } else if (as == 1) {
16519                                {
16520                                        while (it.hasNext()) {
16521                                                final long iax = it.aLong;
16522                                                final long ibx = it.bLong;
16523                                                short ox;
16524                                                ox = (short) (iax << ibx);
16525                                                for (int j = 0; j < is; j++) {
16526                                                        oai16data[it.oIndex + j] = ox;
16527                                                }
16528                                        }
16529                                }
16530                        } else {
16531                                {
16532                                        while (it.hasNext()) {
16533                                                long iax = it.aLong;
16534                                                long ibx = it.bLong;
16535                                                short ox;
16536                                                ox = (short) (iax << ibx);
16537                                                oai16data[it.oIndex] = ox;
16538                                                for (int j = 1; j < is; j++) {
16539                                                        iax = da.getElementLongAbs(it.aIndex + j);
16540                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16541                                                        ox = (short) (iax << ibx);
16542                                                        oai16data[it.oIndex + j] = ox;
16543                                                }
16544                                        }
16545                                }
16546                        }
16547                        break;
16548                case Dataset.ARRAYINT64:
16549                        final long[] oai64data = ((CompoundLongDataset) result).getData();
16550                        if (is == 1) {
16551                                {
16552                                        while (it.hasNext()) {
16553                                                final long iax = it.aLong;
16554                                                final long ibx = it.bLong;
16555                                                long ox;
16556                                                ox = (iax << ibx);
16557                                                oai64data[it.oIndex] = ox;
16558                                        }
16559                                }
16560                        } else if (as < bs) {
16561                                {
16562                                        while (it.hasNext()) {
16563                                                final long iax = it.aLong;
16564                                                long ibx = it.bLong;
16565                                                long ox;
16566                                                ox = (iax << ibx);
16567                                                oai64data[it.oIndex] = ox;
16568                                                for (int j = 1; j < is; j++) {
16569                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16570                                                        ox = (iax << ibx);
16571                                                        oai64data[it.oIndex + j] = ox;
16572                                                }
16573                                        }
16574                                }
16575                        } else if (as > bs) {
16576                                {
16577                                        while (it.hasNext()) {
16578                                                long iax = it.aLong;
16579                                                final long ibx = it.bLong;
16580                                                long ox;
16581                                                ox = (iax << ibx);
16582                                                oai64data[it.oIndex] = ox;
16583                                                for (int j = 1; j < is; j++) {
16584                                                        iax = da.getElementLongAbs(it.aIndex + j);
16585                                                        ox = (iax << ibx);
16586                                                        oai64data[it.oIndex + j] = ox;
16587                                                }
16588                                        }
16589                                }
16590                        } else if (as == 1) {
16591                                {
16592                                        while (it.hasNext()) {
16593                                                final long iax = it.aLong;
16594                                                final long ibx = it.bLong;
16595                                                long ox;
16596                                                ox = (iax << ibx);
16597                                                for (int j = 0; j < is; j++) {
16598                                                        oai64data[it.oIndex + j] = ox;
16599                                                }
16600                                        }
16601                                }
16602                        } else {
16603                                {
16604                                        while (it.hasNext()) {
16605                                                long iax = it.aLong;
16606                                                long ibx = it.bLong;
16607                                                long ox;
16608                                                ox = (iax << ibx);
16609                                                oai64data[it.oIndex] = ox;
16610                                                for (int j = 1; j < is; j++) {
16611                                                        iax = da.getElementLongAbs(it.aIndex + j);
16612                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16613                                                        ox = (iax << ibx);
16614                                                        oai64data[it.oIndex + j] = ox;
16615                                                }
16616                                        }
16617                                }
16618                        }
16619                        break;
16620                case Dataset.ARRAYINT32:
16621                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
16622                        if (is == 1) {
16623                                {
16624                                        while (it.hasNext()) {
16625                                                final long iax = it.aLong;
16626                                                final long ibx = it.bLong;
16627                                                int ox;
16628                                                ox = (int) (iax << ibx);
16629                                                oai32data[it.oIndex] = ox;
16630                                        }
16631                                }
16632                        } else if (as < bs) {
16633                                {
16634                                        while (it.hasNext()) {
16635                                                final long iax = it.aLong;
16636                                                long ibx = it.bLong;
16637                                                int ox;
16638                                                ox = (int) (iax << ibx);
16639                                                oai32data[it.oIndex] = ox;
16640                                                for (int j = 1; j < is; j++) {
16641                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16642                                                        ox = (int) (iax << ibx);
16643                                                        oai32data[it.oIndex + j] = ox;
16644                                                }
16645                                        }
16646                                }
16647                        } else if (as > bs) {
16648                                {
16649                                        while (it.hasNext()) {
16650                                                long iax = it.aLong;
16651                                                final long ibx = it.bLong;
16652                                                int ox;
16653                                                ox = (int) (iax << ibx);
16654                                                oai32data[it.oIndex] = ox;
16655                                                for (int j = 1; j < is; j++) {
16656                                                        iax = da.getElementLongAbs(it.aIndex + j);
16657                                                        ox = (int) (iax << ibx);
16658                                                        oai32data[it.oIndex + j] = ox;
16659                                                }
16660                                        }
16661                                }
16662                        } else if (as == 1) {
16663                                {
16664                                        while (it.hasNext()) {
16665                                                final long iax = it.aLong;
16666                                                final long ibx = it.bLong;
16667                                                int ox;
16668                                                ox = (int) (iax << ibx);
16669                                                for (int j = 0; j < is; j++) {
16670                                                        oai32data[it.oIndex + j] = ox;
16671                                                }
16672                                        }
16673                                }
16674                        } else {
16675                                {
16676                                        while (it.hasNext()) {
16677                                                long iax = it.aLong;
16678                                                long ibx = it.bLong;
16679                                                int ox;
16680                                                ox = (int) (iax << ibx);
16681                                                oai32data[it.oIndex] = ox;
16682                                                for (int j = 1; j < is; j++) {
16683                                                        iax = da.getElementLongAbs(it.aIndex + j);
16684                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16685                                                        ox = (int) (iax << ibx);
16686                                                        oai32data[it.oIndex + j] = ox;
16687                                                }
16688                                        }
16689                                }
16690                        }
16691                        break;
16692                default:
16693                        throw new IllegalArgumentException("leftShift supports integer, compound integer datasets only");
16694                }
16695
16696                addBinaryOperatorName(da, db, result, "<<");
16697                return result;
16698        }
16699
16700        /**
16701         * rightShift operator
16702         * @param a
16703         * @param b
16704         * @return {@code a >> b}, bitwise right shift of a by b
16705         */
16706        public static Dataset rightShift(final Object a, final Object b) {
16707                return rightShift(a, b, null);
16708        }
16709
16710        /**
16711         * rightShift operator
16712         * @param a
16713         * @param b
16714         * @param o output can be null - in which case, a new dataset is created
16715         * @return {@code a >> b}, bitwise right shift of a by b
16716         */
16717        public static Dataset rightShift(final Object a, final Object b, final Dataset o) {
16718                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
16719                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
16720                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
16721                it.setOutputDouble(false);
16722                final Dataset result = it.getOutput();
16723                if (!result.isComplex()) {
16724                        boolean change = false;
16725                        if (da.isComplex()) {
16726                                da = da.getRealView();
16727                                change = true;
16728                        }
16729                        if (db.isComplex()) {
16730                                db = db.getRealView();
16731                                change = true;
16732                        }
16733                        if (change) {
16734                                it = BroadcastIterator.createIterator(da, db, result, true);
16735                                it.setOutputDouble(false);
16736                        }
16737                }
16738                final int is = result.getElementsPerItem();
16739                final int as = da.getElementsPerItem();
16740                final int bs = db.getElementsPerItem();
16741                final int dt = result.getDType();
16742
16743                switch(dt) {
16744                case Dataset.INT8:
16745                        final byte[] oi8data = ((ByteDataset) result).getData();
16746                        {
16747                                while (it.hasNext()) {
16748                                        final long iax = it.aLong;
16749                                        final long ibx = it.bLong;
16750                                        byte ox;
16751                                        ox = (byte) (iax >> ibx);
16752                                        oi8data[it.oIndex] = ox;
16753                                }
16754                        }
16755                        break;
16756                case Dataset.INT16:
16757                        final short[] oi16data = ((ShortDataset) result).getData();
16758                        {
16759                                while (it.hasNext()) {
16760                                        final long iax = it.aLong;
16761                                        final long ibx = it.bLong;
16762                                        short ox;
16763                                        ox = (short) (iax >> ibx);
16764                                        oi16data[it.oIndex] = ox;
16765                                }
16766                        }
16767                        break;
16768                case Dataset.INT64:
16769                        final long[] oi64data = ((LongDataset) result).getData();
16770                        {
16771                                while (it.hasNext()) {
16772                                        final long iax = it.aLong;
16773                                        final long ibx = it.bLong;
16774                                        long ox;
16775                                        ox = (iax >> ibx);
16776                                        oi64data[it.oIndex] = ox;
16777                                }
16778                        }
16779                        break;
16780                case Dataset.INT32:
16781                        final int[] oi32data = ((IntegerDataset) result).getData();
16782                        {
16783                                while (it.hasNext()) {
16784                                        final long iax = it.aLong;
16785                                        final long ibx = it.bLong;
16786                                        int ox;
16787                                        ox = (int) (iax >> ibx);
16788                                        oi32data[it.oIndex] = ox;
16789                                }
16790                        }
16791                        break;
16792                case Dataset.ARRAYINT8:
16793                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
16794                        if (is == 1) {
16795                                {
16796                                        while (it.hasNext()) {
16797                                                final long iax = it.aLong;
16798                                                final long ibx = it.bLong;
16799                                                byte ox;
16800                                                ox = (byte) (iax >> ibx);
16801                                                oai8data[it.oIndex] = ox;
16802                                        }
16803                                }
16804                        } else if (as < bs) {
16805                                {
16806                                        while (it.hasNext()) {
16807                                                final long iax = it.aLong;
16808                                                long ibx = it.bLong;
16809                                                byte ox;
16810                                                ox = (byte) (iax >> ibx);
16811                                                oai8data[it.oIndex] = ox;
16812                                                for (int j = 1; j < is; j++) {
16813                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16814                                                        ox = (byte) (iax >> ibx);
16815                                                        oai8data[it.oIndex + j] = ox;
16816                                                }
16817                                        }
16818                                }
16819                        } else if (as > bs) {
16820                                {
16821                                        while (it.hasNext()) {
16822                                                long iax = it.aLong;
16823                                                final long ibx = it.bLong;
16824                                                byte ox;
16825                                                ox = (byte) (iax >> ibx);
16826                                                oai8data[it.oIndex] = ox;
16827                                                for (int j = 1; j < is; j++) {
16828                                                        iax = da.getElementLongAbs(it.aIndex + j);
16829                                                        ox = (byte) (iax >> ibx);
16830                                                        oai8data[it.oIndex + j] = ox;
16831                                                }
16832                                        }
16833                                }
16834                        } else if (as == 1) {
16835                                {
16836                                        while (it.hasNext()) {
16837                                                final long iax = it.aLong;
16838                                                final long ibx = it.bLong;
16839                                                byte ox;
16840                                                ox = (byte) (iax >> ibx);
16841                                                for (int j = 0; j < is; j++) {
16842                                                        oai8data[it.oIndex + j] = ox;
16843                                                }
16844                                        }
16845                                }
16846                        } else {
16847                                {
16848                                        while (it.hasNext()) {
16849                                                long iax = it.aLong;
16850                                                long ibx = it.bLong;
16851                                                byte ox;
16852                                                ox = (byte) (iax >> ibx);
16853                                                oai8data[it.oIndex] = ox;
16854                                                for (int j = 1; j < is; j++) {
16855                                                        iax = da.getElementLongAbs(it.aIndex + j);
16856                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16857                                                        ox = (byte) (iax >> ibx);
16858                                                        oai8data[it.oIndex + j] = ox;
16859                                                }
16860                                        }
16861                                }
16862                        }
16863                        break;
16864                case Dataset.ARRAYINT16:
16865                        final short[] oai16data = ((CompoundShortDataset) result).getData();
16866                        if (is == 1) {
16867                                {
16868                                        while (it.hasNext()) {
16869                                                final long iax = it.aLong;
16870                                                final long ibx = it.bLong;
16871                                                short ox;
16872                                                ox = (short) (iax >> ibx);
16873                                                oai16data[it.oIndex] = ox;
16874                                        }
16875                                }
16876                        } else if (as < bs) {
16877                                {
16878                                        while (it.hasNext()) {
16879                                                final long iax = it.aLong;
16880                                                long ibx = it.bLong;
16881                                                short ox;
16882                                                ox = (short) (iax >> ibx);
16883                                                oai16data[it.oIndex] = ox;
16884                                                for (int j = 1; j < is; j++) {
16885                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16886                                                        ox = (short) (iax >> ibx);
16887                                                        oai16data[it.oIndex + j] = ox;
16888                                                }
16889                                        }
16890                                }
16891                        } else if (as > bs) {
16892                                {
16893                                        while (it.hasNext()) {
16894                                                long iax = it.aLong;
16895                                                final long ibx = it.bLong;
16896                                                short ox;
16897                                                ox = (short) (iax >> ibx);
16898                                                oai16data[it.oIndex] = ox;
16899                                                for (int j = 1; j < is; j++) {
16900                                                        iax = da.getElementLongAbs(it.aIndex + j);
16901                                                        ox = (short) (iax >> ibx);
16902                                                        oai16data[it.oIndex + j] = ox;
16903                                                }
16904                                        }
16905                                }
16906                        } else if (as == 1) {
16907                                {
16908                                        while (it.hasNext()) {
16909                                                final long iax = it.aLong;
16910                                                final long ibx = it.bLong;
16911                                                short ox;
16912                                                ox = (short) (iax >> ibx);
16913                                                for (int j = 0; j < is; j++) {
16914                                                        oai16data[it.oIndex + j] = ox;
16915                                                }
16916                                        }
16917                                }
16918                        } else {
16919                                {
16920                                        while (it.hasNext()) {
16921                                                long iax = it.aLong;
16922                                                long ibx = it.bLong;
16923                                                short ox;
16924                                                ox = (short) (iax >> ibx);
16925                                                oai16data[it.oIndex] = ox;
16926                                                for (int j = 1; j < is; j++) {
16927                                                        iax = da.getElementLongAbs(it.aIndex + j);
16928                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16929                                                        ox = (short) (iax >> ibx);
16930                                                        oai16data[it.oIndex + j] = ox;
16931                                                }
16932                                        }
16933                                }
16934                        }
16935                        break;
16936                case Dataset.ARRAYINT64:
16937                        final long[] oai64data = ((CompoundLongDataset) result).getData();
16938                        if (is == 1) {
16939                                {
16940                                        while (it.hasNext()) {
16941                                                final long iax = it.aLong;
16942                                                final long ibx = it.bLong;
16943                                                long ox;
16944                                                ox = (iax >> ibx);
16945                                                oai64data[it.oIndex] = ox;
16946                                        }
16947                                }
16948                        } else if (as < bs) {
16949                                {
16950                                        while (it.hasNext()) {
16951                                                final long iax = it.aLong;
16952                                                long ibx = it.bLong;
16953                                                long ox;
16954                                                ox = (iax >> ibx);
16955                                                oai64data[it.oIndex] = ox;
16956                                                for (int j = 1; j < is; j++) {
16957                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16958                                                        ox = (iax >> ibx);
16959                                                        oai64data[it.oIndex + j] = ox;
16960                                                }
16961                                        }
16962                                }
16963                        } else if (as > bs) {
16964                                {
16965                                        while (it.hasNext()) {
16966                                                long iax = it.aLong;
16967                                                final long ibx = it.bLong;
16968                                                long ox;
16969                                                ox = (iax >> ibx);
16970                                                oai64data[it.oIndex] = ox;
16971                                                for (int j = 1; j < is; j++) {
16972                                                        iax = da.getElementLongAbs(it.aIndex + j);
16973                                                        ox = (iax >> ibx);
16974                                                        oai64data[it.oIndex + j] = ox;
16975                                                }
16976                                        }
16977                                }
16978                        } else if (as == 1) {
16979                                {
16980                                        while (it.hasNext()) {
16981                                                final long iax = it.aLong;
16982                                                final long ibx = it.bLong;
16983                                                long ox;
16984                                                ox = (iax >> ibx);
16985                                                for (int j = 0; j < is; j++) {
16986                                                        oai64data[it.oIndex + j] = ox;
16987                                                }
16988                                        }
16989                                }
16990                        } else {
16991                                {
16992                                        while (it.hasNext()) {
16993                                                long iax = it.aLong;
16994                                                long ibx = it.bLong;
16995                                                long ox;
16996                                                ox = (iax >> ibx);
16997                                                oai64data[it.oIndex] = ox;
16998                                                for (int j = 1; j < is; j++) {
16999                                                        iax = da.getElementLongAbs(it.aIndex + j);
17000                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17001                                                        ox = (iax >> ibx);
17002                                                        oai64data[it.oIndex + j] = ox;
17003                                                }
17004                                        }
17005                                }
17006                        }
17007                        break;
17008                case Dataset.ARRAYINT32:
17009                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
17010                        if (is == 1) {
17011                                {
17012                                        while (it.hasNext()) {
17013                                                final long iax = it.aLong;
17014                                                final long ibx = it.bLong;
17015                                                int ox;
17016                                                ox = (int) (iax >> ibx);
17017                                                oai32data[it.oIndex] = ox;
17018                                        }
17019                                }
17020                        } else if (as < bs) {
17021                                {
17022                                        while (it.hasNext()) {
17023                                                final long iax = it.aLong;
17024                                                long ibx = it.bLong;
17025                                                int ox;
17026                                                ox = (int) (iax >> ibx);
17027                                                oai32data[it.oIndex] = ox;
17028                                                for (int j = 1; j < is; j++) {
17029                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17030                                                        ox = (int) (iax >> ibx);
17031                                                        oai32data[it.oIndex + j] = ox;
17032                                                }
17033                                        }
17034                                }
17035                        } else if (as > bs) {
17036                                {
17037                                        while (it.hasNext()) {
17038                                                long iax = it.aLong;
17039                                                final long ibx = it.bLong;
17040                                                int ox;
17041                                                ox = (int) (iax >> ibx);
17042                                                oai32data[it.oIndex] = ox;
17043                                                for (int j = 1; j < is; j++) {
17044                                                        iax = da.getElementLongAbs(it.aIndex + j);
17045                                                        ox = (int) (iax >> ibx);
17046                                                        oai32data[it.oIndex + j] = ox;
17047                                                }
17048                                        }
17049                                }
17050                        } else if (as == 1) {
17051                                {
17052                                        while (it.hasNext()) {
17053                                                final long iax = it.aLong;
17054                                                final long ibx = it.bLong;
17055                                                int ox;
17056                                                ox = (int) (iax >> ibx);
17057                                                for (int j = 0; j < is; j++) {
17058                                                        oai32data[it.oIndex + j] = ox;
17059                                                }
17060                                        }
17061                                }
17062                        } else {
17063                                {
17064                                        while (it.hasNext()) {
17065                                                long iax = it.aLong;
17066                                                long ibx = it.bLong;
17067                                                int ox;
17068                                                ox = (int) (iax >> ibx);
17069                                                oai32data[it.oIndex] = ox;
17070                                                for (int j = 1; j < is; j++) {
17071                                                        iax = da.getElementLongAbs(it.aIndex + j);
17072                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17073                                                        ox = (int) (iax >> ibx);
17074                                                        oai32data[it.oIndex + j] = ox;
17075                                                }
17076                                        }
17077                                }
17078                        }
17079                        break;
17080                default:
17081                        throw new IllegalArgumentException("rightShift supports integer, compound integer datasets only");
17082                }
17083
17084                addBinaryOperatorName(da, db, result, ">>");
17085                return result;
17086        }
17087
17088        /**
17089         * unsignedRightShift operator
17090         * @param a
17091         * @param b
17092         * @return {@code a >>> b}, bitwise right shift of a by b with zeros added
17093         */
17094        public static Dataset unsignedRightShift(final Object a, final Object b) {
17095                return unsignedRightShift(a, b, null);
17096        }
17097
17098        /**
17099         * unsignedRightShift operator
17100         * @param a
17101         * @param b
17102         * @param o output can be null - in which case, a new dataset is created
17103         * @return {@code a >>> b}, bitwise right shift of a by b with zeros added
17104         */
17105        public static Dataset unsignedRightShift(final Object a, final Object b, final Dataset o) {
17106                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
17107                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
17108                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
17109                it.setOutputDouble(false);
17110                final long unsignedMask;
17111                final Dataset result = it.getOutput();
17112                if (!result.isComplex()) {
17113                        boolean change = false;
17114                        if (da.isComplex()) {
17115                                da = da.getRealView();
17116                                change = true;
17117                        }
17118                        if (db.isComplex()) {
17119                                db = db.getRealView();
17120                                change = true;
17121                        }
17122                        if (change) {
17123                                it = BroadcastIterator.createIterator(da, db, result, true);
17124                                it.setOutputDouble(false);
17125                        }
17126                }
17127                final int is = result.getElementsPerItem();
17128                final int as = da.getElementsPerItem();
17129                final int bs = db.getElementsPerItem();
17130                final int dt = result.getDType();
17131
17132                switch(dt) {
17133                case Dataset.INT8:
17134                        final byte[] oi8data = ((ByteDataset) result).getData();
17135                        unsignedMask = 0xffL;
17136                        {
17137                                while (it.hasNext()) {
17138                                        final long iax = it.aLong;
17139                                        final long ibx = it.bLong;
17140                                        byte ox;
17141                                        ox = (byte) ((unsignedMask & iax) >>> ibx);
17142                                        oi8data[it.oIndex] = ox;
17143                                }
17144                        }
17145                        break;
17146                case Dataset.INT16:
17147                        final short[] oi16data = ((ShortDataset) result).getData();
17148                        unsignedMask = 0xffffL;
17149                        {
17150                                while (it.hasNext()) {
17151                                        final long iax = it.aLong;
17152                                        final long ibx = it.bLong;
17153                                        short ox;
17154                                        ox = (short) ((unsignedMask & iax) >>> ibx);
17155                                        oi16data[it.oIndex] = ox;
17156                                }
17157                        }
17158                        break;
17159                case Dataset.INT64:
17160                        final long[] oi64data = ((LongDataset) result).getData();
17161                        unsignedMask = 0xffffffffffffffffL;
17162                        {
17163                                while (it.hasNext()) {
17164                                        final long iax = it.aLong;
17165                                        final long ibx = it.bLong;
17166                                        long ox;
17167                                        ox = ((unsignedMask & iax) >>> ibx);
17168                                        oi64data[it.oIndex] = ox;
17169                                }
17170                        }
17171                        break;
17172                case Dataset.INT32:
17173                        final int[] oi32data = ((IntegerDataset) result).getData();
17174                        unsignedMask = 0xffffffffL;
17175                        {
17176                                while (it.hasNext()) {
17177                                        final long iax = it.aLong;
17178                                        final long ibx = it.bLong;
17179                                        int ox;
17180                                        ox = (int) ((unsignedMask & iax) >>> ibx);
17181                                        oi32data[it.oIndex] = ox;
17182                                }
17183                        }
17184                        break;
17185                case Dataset.ARRAYINT8:
17186                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
17187                        unsignedMask = 0xffL;
17188                        if (is == 1) {
17189                                {
17190                                        while (it.hasNext()) {
17191                                                final long iax = it.aLong;
17192                                                final long ibx = it.bLong;
17193                                                byte ox;
17194                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
17195                                                oai8data[it.oIndex] = ox;
17196                                        }
17197                                }
17198                        } else if (as < bs) {
17199                                {
17200                                        while (it.hasNext()) {
17201                                                final long iax = it.aLong;
17202                                                long ibx = it.bLong;
17203                                                byte ox;
17204                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
17205                                                oai8data[it.oIndex] = ox;
17206                                                for (int j = 1; j < is; j++) {
17207                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17208                                                        ox = (byte) ((unsignedMask & iax) >>> ibx);
17209                                                        oai8data[it.oIndex + j] = ox;
17210                                                }
17211                                        }
17212                                }
17213                        } else if (as > bs) {
17214                                {
17215                                        while (it.hasNext()) {
17216                                                long iax = it.aLong;
17217                                                final long ibx = it.bLong;
17218                                                byte ox;
17219                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
17220                                                oai8data[it.oIndex] = ox;
17221                                                for (int j = 1; j < is; j++) {
17222                                                        iax = da.getElementLongAbs(it.aIndex + j);
17223                                                        ox = (byte) ((unsignedMask & iax) >>> ibx);
17224                                                        oai8data[it.oIndex + j] = ox;
17225                                                }
17226                                        }
17227                                }
17228                        } else if (as == 1) {
17229                                {
17230                                        while (it.hasNext()) {
17231                                                final long iax = it.aLong;
17232                                                final long ibx = it.bLong;
17233                                                byte ox;
17234                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
17235                                                for (int j = 0; j < is; j++) {
17236                                                        oai8data[it.oIndex + j] = ox;
17237                                                }
17238                                        }
17239                                }
17240                        } else {
17241                                {
17242                                        while (it.hasNext()) {
17243                                                long iax = it.aLong;
17244                                                long ibx = it.bLong;
17245                                                byte ox;
17246                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
17247                                                oai8data[it.oIndex] = ox;
17248                                                for (int j = 1; j < is; j++) {
17249                                                        iax = da.getElementLongAbs(it.aIndex + j);
17250                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17251                                                        ox = (byte) ((unsignedMask & iax) >>> ibx);
17252                                                        oai8data[it.oIndex + j] = ox;
17253                                                }
17254                                        }
17255                                }
17256                        }
17257                        break;
17258                case Dataset.ARRAYINT16:
17259                        final short[] oai16data = ((CompoundShortDataset) result).getData();
17260                        unsignedMask = 0xffffL;
17261                        if (is == 1) {
17262                                {
17263                                        while (it.hasNext()) {
17264                                                final long iax = it.aLong;
17265                                                final long ibx = it.bLong;
17266                                                short ox;
17267                                                ox = (short) ((unsignedMask & iax) >>> ibx);
17268                                                oai16data[it.oIndex] = ox;
17269                                        }
17270                                }
17271                        } else if (as < bs) {
17272                                {
17273                                        while (it.hasNext()) {
17274                                                final long iax = it.aLong;
17275                                                long ibx = it.bLong;
17276                                                short ox;
17277                                                ox = (short) ((unsignedMask & iax) >>> ibx);
17278                                                oai16data[it.oIndex] = ox;
17279                                                for (int j = 1; j < is; j++) {
17280                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17281                                                        ox = (short) ((unsignedMask & iax) >>> ibx);
17282                                                        oai16data[it.oIndex + j] = ox;
17283                                                }
17284                                        }
17285                                }
17286                        } else if (as > bs) {
17287                                {
17288                                        while (it.hasNext()) {
17289                                                long iax = it.aLong;
17290                                                final long ibx = it.bLong;
17291                                                short ox;
17292                                                ox = (short) ((unsignedMask & iax) >>> ibx);
17293                                                oai16data[it.oIndex] = ox;
17294                                                for (int j = 1; j < is; j++) {
17295                                                        iax = da.getElementLongAbs(it.aIndex + j);
17296                                                        ox = (short) ((unsignedMask & iax) >>> ibx);
17297                                                        oai16data[it.oIndex + j] = ox;
17298                                                }
17299                                        }
17300                                }
17301                        } else if (as == 1) {
17302                                {
17303                                        while (it.hasNext()) {
17304                                                final long iax = it.aLong;
17305                                                final long ibx = it.bLong;
17306                                                short ox;
17307                                                ox = (short) ((unsignedMask & iax) >>> ibx);
17308                                                for (int j = 0; j < is; j++) {
17309                                                        oai16data[it.oIndex + j] = ox;
17310                                                }
17311                                        }
17312                                }
17313                        } else {
17314                                {
17315                                        while (it.hasNext()) {
17316                                                long iax = it.aLong;
17317                                                long ibx = it.bLong;
17318                                                short ox;
17319                                                ox = (short) ((unsignedMask & iax) >>> ibx);
17320                                                oai16data[it.oIndex] = ox;
17321                                                for (int j = 1; j < is; j++) {
17322                                                        iax = da.getElementLongAbs(it.aIndex + j);
17323                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17324                                                        ox = (short) ((unsignedMask & iax) >>> ibx);
17325                                                        oai16data[it.oIndex + j] = ox;
17326                                                }
17327                                        }
17328                                }
17329                        }
17330                        break;
17331                case Dataset.ARRAYINT64:
17332                        final long[] oai64data = ((CompoundLongDataset) result).getData();
17333                        unsignedMask = 0xffffffffffffffffL;
17334                        if (is == 1) {
17335                                {
17336                                        while (it.hasNext()) {
17337                                                final long iax = it.aLong;
17338                                                final long ibx = it.bLong;
17339                                                long ox;
17340                                                ox = ((unsignedMask & iax) >>> ibx);
17341                                                oai64data[it.oIndex] = ox;
17342                                        }
17343                                }
17344                        } else if (as < bs) {
17345                                {
17346                                        while (it.hasNext()) {
17347                                                final long iax = it.aLong;
17348                                                long ibx = it.bLong;
17349                                                long ox;
17350                                                ox = ((unsignedMask & iax) >>> ibx);
17351                                                oai64data[it.oIndex] = ox;
17352                                                for (int j = 1; j < is; j++) {
17353                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17354                                                        ox = ((unsignedMask & iax) >>> ibx);
17355                                                        oai64data[it.oIndex + j] = ox;
17356                                                }
17357                                        }
17358                                }
17359                        } else if (as > bs) {
17360                                {
17361                                        while (it.hasNext()) {
17362                                                long iax = it.aLong;
17363                                                final long ibx = it.bLong;
17364                                                long ox;
17365                                                ox = ((unsignedMask & iax) >>> ibx);
17366                                                oai64data[it.oIndex] = ox;
17367                                                for (int j = 1; j < is; j++) {
17368                                                        iax = da.getElementLongAbs(it.aIndex + j);
17369                                                        ox = ((unsignedMask & iax) >>> ibx);
17370                                                        oai64data[it.oIndex + j] = ox;
17371                                                }
17372                                        }
17373                                }
17374                        } else if (as == 1) {
17375                                {
17376                                        while (it.hasNext()) {
17377                                                final long iax = it.aLong;
17378                                                final long ibx = it.bLong;
17379                                                long ox;
17380                                                ox = ((unsignedMask & iax) >>> ibx);
17381                                                for (int j = 0; j < is; j++) {
17382                                                        oai64data[it.oIndex + j] = ox;
17383                                                }
17384                                        }
17385                                }
17386                        } else {
17387                                {
17388                                        while (it.hasNext()) {
17389                                                long iax = it.aLong;
17390                                                long ibx = it.bLong;
17391                                                long ox;
17392                                                ox = ((unsignedMask & iax) >>> ibx);
17393                                                oai64data[it.oIndex] = ox;
17394                                                for (int j = 1; j < is; j++) {
17395                                                        iax = da.getElementLongAbs(it.aIndex + j);
17396                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17397                                                        ox = ((unsignedMask & iax) >>> ibx);
17398                                                        oai64data[it.oIndex + j] = ox;
17399                                                }
17400                                        }
17401                                }
17402                        }
17403                        break;
17404                case Dataset.ARRAYINT32:
17405                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
17406                        unsignedMask = 0xffffffffL;
17407                        if (is == 1) {
17408                                {
17409                                        while (it.hasNext()) {
17410                                                final long iax = it.aLong;
17411                                                final long ibx = it.bLong;
17412                                                int ox;
17413                                                ox = (int) ((unsignedMask & iax) >>> ibx);
17414                                                oai32data[it.oIndex] = ox;
17415                                        }
17416                                }
17417                        } else if (as < bs) {
17418                                {
17419                                        while (it.hasNext()) {
17420                                                final long iax = it.aLong;
17421                                                long ibx = it.bLong;
17422                                                int ox;
17423                                                ox = (int) ((unsignedMask & iax) >>> ibx);
17424                                                oai32data[it.oIndex] = ox;
17425                                                for (int j = 1; j < is; j++) {
17426                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17427                                                        ox = (int) ((unsignedMask & iax) >>> ibx);
17428                                                        oai32data[it.oIndex + j] = ox;
17429                                                }
17430                                        }
17431                                }
17432                        } else if (as > bs) {
17433                                {
17434                                        while (it.hasNext()) {
17435                                                long iax = it.aLong;
17436                                                final long ibx = it.bLong;
17437                                                int ox;
17438                                                ox = (int) ((unsignedMask & iax) >>> ibx);
17439                                                oai32data[it.oIndex] = ox;
17440                                                for (int j = 1; j < is; j++) {
17441                                                        iax = da.getElementLongAbs(it.aIndex + j);
17442                                                        ox = (int) ((unsignedMask & iax) >>> ibx);
17443                                                        oai32data[it.oIndex + j] = ox;
17444                                                }
17445                                        }
17446                                }
17447                        } else if (as == 1) {
17448                                {
17449                                        while (it.hasNext()) {
17450                                                final long iax = it.aLong;
17451                                                final long ibx = it.bLong;
17452                                                int ox;
17453                                                ox = (int) ((unsignedMask & iax) >>> ibx);
17454                                                for (int j = 0; j < is; j++) {
17455                                                        oai32data[it.oIndex + j] = ox;
17456                                                }
17457                                        }
17458                                }
17459                        } else {
17460                                {
17461                                        while (it.hasNext()) {
17462                                                long iax = it.aLong;
17463                                                long ibx = it.bLong;
17464                                                int ox;
17465                                                ox = (int) ((unsignedMask & iax) >>> ibx);
17466                                                oai32data[it.oIndex] = ox;
17467                                                for (int j = 1; j < is; j++) {
17468                                                        iax = da.getElementLongAbs(it.aIndex + j);
17469                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17470                                                        ox = (int) ((unsignedMask & iax) >>> ibx);
17471                                                        oai32data[it.oIndex + j] = ox;
17472                                                }
17473                                        }
17474                                }
17475                        }
17476                        break;
17477                default:
17478                        throw new IllegalArgumentException("unsignedRightShift supports integer, compound integer datasets only");
17479                }
17480
17481                addBinaryOperatorName(da, db, result, ">>>");
17482                return result;
17483        }
17484
17485        /**
17486         * bitwiseInvert - {@code ~a}, bitwise invert (or NOT) each element
17487         * @param a
17488         * @return dataset
17489         */
17490        public static Dataset bitwiseInvert(final Object a) {
17491                return bitwiseInvert(a, null);
17492        }
17493
17494        /**
17495         * bitwiseInvert - {@code ~a}, bitwise invert (or NOT) each element
17496         * @param a
17497         * @param o output can be null - in which case, a new dataset is created
17498         * @return dataset
17499         */
17500        public static Dataset bitwiseInvert(final Object a, final Dataset o) {
17501                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
17502                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true, true, true);
17503                final Dataset result = it.getOutput();
17504                if (!result.isComplex()) {
17505                        if (da.isComplex()) {
17506                                da = da.getRealView();
17507                                it = new SingleInputBroadcastIterator(da, result, true, true, true);
17508                        }
17509                }
17510                final int is = result.getElementsPerItem();
17511                final int as = da.getElementsPerItem();
17512                final int dt = result.getDType();
17513
17514                switch(dt) {
17515                case Dataset.INT8:
17516                        final byte[] oi8data = ((ByteDataset) result).getData();
17517                        {
17518                                while (it.hasNext()) {
17519                                        final long ix = it.aLong;
17520                                        byte ox;
17521                                        ox = (byte) toLong(~ix);
17522                                        oi8data[it.oIndex] = ox;
17523                                }
17524                        }
17525                        break;
17526                case Dataset.INT16:
17527                        final short[] oi16data = ((ShortDataset) result).getData();
17528                        {
17529                                while (it.hasNext()) {
17530                                        final long ix = it.aLong;
17531                                        short ox;
17532                                        ox = (short) toLong(~ix);
17533                                        oi16data[it.oIndex] = ox;
17534                                }
17535                        }
17536                        break;
17537                case Dataset.INT64:
17538                        final long[] oi64data = ((LongDataset) result).getData();
17539                        {
17540                                while (it.hasNext()) {
17541                                        final long ix = it.aLong;
17542                                        long ox;
17543                                        ox = toLong(~ix);
17544                                        oi64data[it.oIndex] = ox;
17545                                }
17546                        }
17547                        break;
17548                case Dataset.INT32:
17549                        final int[] oi32data = ((IntegerDataset) result).getData();
17550                        {
17551                                while (it.hasNext()) {
17552                                        final long ix = it.aLong;
17553                                        int ox;
17554                                        ox = (int) toLong(~ix);
17555                                        oi32data[it.oIndex] = ox;
17556                                }
17557                        }
17558                        break;
17559                case Dataset.ARRAYINT8:
17560                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
17561                        if (is == 1) {
17562                                {
17563                                        while (it.hasNext()) {
17564                                                final long ix = it.aLong;
17565                                                byte ox;
17566                                                ox = (byte) toLong(~ix);
17567                                                oai8data[it.oIndex] = ox;
17568                                        }
17569                                }
17570                        } else if (as == 1) {
17571                                {
17572                                        while (it.hasNext()) {
17573                                                final long ix = it.aLong;
17574                                                byte ox;
17575                                                ox = (byte) toLong(~ix);
17576                                                for (int j = 0; j < is; j++) {
17577                                                        oai8data[it.oIndex + j] = ox;
17578                                                }
17579                                        }
17580                                }
17581                        } else {
17582                                {
17583                                        while (it.hasNext()) {
17584                                                for (int j = 0; j < is; j++) {
17585                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17586                                                        byte ox;
17587                                                        ox = (byte) toLong(~ix);
17588                                                        oai8data[it.oIndex + j] = ox;
17589                                                }
17590                                        }
17591                                }
17592                        }
17593                        break;
17594                case Dataset.ARRAYINT16:
17595                        final short[] oai16data = ((CompoundShortDataset) result).getData();
17596                        if (is == 1) {
17597                                {
17598                                        while (it.hasNext()) {
17599                                                final long ix = it.aLong;
17600                                                short ox;
17601                                                ox = (short) toLong(~ix);
17602                                                oai16data[it.oIndex] = ox;
17603                                        }
17604                                }
17605                        } else if (as == 1) {
17606                                {
17607                                        while (it.hasNext()) {
17608                                                final long ix = it.aLong;
17609                                                short ox;
17610                                                ox = (short) toLong(~ix);
17611                                                for (int j = 0; j < is; j++) {
17612                                                        oai16data[it.oIndex + j] = ox;
17613                                                }
17614                                        }
17615                                }
17616                        } else {
17617                                {
17618                                        while (it.hasNext()) {
17619                                                for (int j = 0; j < is; j++) {
17620                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17621                                                        short ox;
17622                                                        ox = (short) toLong(~ix);
17623                                                        oai16data[it.oIndex + j] = ox;
17624                                                }
17625                                        }
17626                                }
17627                        }
17628                        break;
17629                case Dataset.ARRAYINT64:
17630                        final long[] oai64data = ((CompoundLongDataset) result).getData();
17631                        if (is == 1) {
17632                                {
17633                                        while (it.hasNext()) {
17634                                                final long ix = it.aLong;
17635                                                long ox;
17636                                                ox = toLong(~ix);
17637                                                oai64data[it.oIndex] = ox;
17638                                        }
17639                                }
17640                        } else if (as == 1) {
17641                                {
17642                                        while (it.hasNext()) {
17643                                                final long ix = it.aLong;
17644                                                long ox;
17645                                                ox = toLong(~ix);
17646                                                for (int j = 0; j < is; j++) {
17647                                                        oai64data[it.oIndex + j] = ox;
17648                                                }
17649                                        }
17650                                }
17651                        } else {
17652                                {
17653                                        while (it.hasNext()) {
17654                                                for (int j = 0; j < is; j++) {
17655                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17656                                                        long ox;
17657                                                        ox = toLong(~ix);
17658                                                        oai64data[it.oIndex + j] = ox;
17659                                                }
17660                                        }
17661                                }
17662                        }
17663                        break;
17664                case Dataset.ARRAYINT32:
17665                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
17666                        if (is == 1) {
17667                                {
17668                                        while (it.hasNext()) {
17669                                                final long ix = it.aLong;
17670                                                int ox;
17671                                                ox = (int) toLong(~ix);
17672                                                oai32data[it.oIndex] = ox;
17673                                        }
17674                                }
17675                        } else if (as == 1) {
17676                                {
17677                                        while (it.hasNext()) {
17678                                                final long ix = it.aLong;
17679                                                int ox;
17680                                                ox = (int) toLong(~ix);
17681                                                for (int j = 0; j < is; j++) {
17682                                                        oai32data[it.oIndex + j] = ox;
17683                                                }
17684                                        }
17685                                }
17686                        } else {
17687                                {
17688                                        while (it.hasNext()) {
17689                                                for (int j = 0; j < is; j++) {
17690                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17691                                                        int ox;
17692                                                        ox = (int) toLong(~ix);
17693                                                        oai32data[it.oIndex + j] = ox;
17694                                                }
17695                                        }
17696                                }
17697                        }
17698                        break;
17699                default:
17700                        throw new IllegalArgumentException("bitwiseInvert supports integer, compound integer datasets only");
17701                }
17702
17703                addFunctionName(result, "bitwiseInvert");
17704                return result;
17705        }
17706
17707        /**
17708         * sin - evaluate the sine function on each element of the dataset
17709         * @param a
17710         * @return dataset
17711         */
17712        public static Dataset sin(final Object a) {
17713                return sin(a, null);
17714        }
17715
17716        /**
17717         * sin - evaluate the sine function on each element of the dataset
17718         * @param a
17719         * @param o output can be null - in which case, a new dataset is created
17720         * @return dataset
17721         */
17722        public static Dataset sin(final Object a, final Dataset o) {
17723                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
17724                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
17725                final Dataset result = it.getOutput();
17726                if (!result.isComplex()) {
17727                        if (da.isComplex()) {
17728                                da = da.getRealView();
17729                                it = new SingleInputBroadcastIterator(da, result, true);
17730                        }
17731                }
17732                final int is = result.getElementsPerItem();
17733                final int as = da.getElementsPerItem();
17734                final int dt = result.getDType();
17735
17736                switch(dt) {
17737                case Dataset.INT8:
17738                        final byte[] oi8data = ((ByteDataset) result).getData();
17739                        if (it.isOutputDouble()) {
17740                                while (it.hasNext()) {
17741                                        final double ix = it.aDouble;
17742                                        byte ox;
17743                                        ox = (byte) toLong(Math.sin(ix));
17744                                        oi8data[it.oIndex] = ox;
17745                                }
17746                        } else {
17747                                while (it.hasNext()) {
17748                                        final long ix = it.aLong;
17749                                        byte ox;
17750                                        ox = (byte) toLong(Math.sin(ix));
17751                                        oi8data[it.oIndex] = ox;
17752                                }
17753                        }
17754                        break;
17755                case Dataset.INT16:
17756                        final short[] oi16data = ((ShortDataset) result).getData();
17757                        if (it.isOutputDouble()) {
17758                                while (it.hasNext()) {
17759                                        final double ix = it.aDouble;
17760                                        short ox;
17761                                        ox = (short) toLong(Math.sin(ix));
17762                                        oi16data[it.oIndex] = ox;
17763                                }
17764                        } else {
17765                                while (it.hasNext()) {
17766                                        final long ix = it.aLong;
17767                                        short ox;
17768                                        ox = (short) toLong(Math.sin(ix));
17769                                        oi16data[it.oIndex] = ox;
17770                                }
17771                        }
17772                        break;
17773                case Dataset.INT64:
17774                        final long[] oi64data = ((LongDataset) result).getData();
17775                        if (it.isOutputDouble()) {
17776                                while (it.hasNext()) {
17777                                        final double ix = it.aDouble;
17778                                        long ox;
17779                                        ox = toLong(Math.sin(ix));
17780                                        oi64data[it.oIndex] = ox;
17781                                }
17782                        } else {
17783                                while (it.hasNext()) {
17784                                        final long ix = it.aLong;
17785                                        long ox;
17786                                        ox = toLong(Math.sin(ix));
17787                                        oi64data[it.oIndex] = ox;
17788                                }
17789                        }
17790                        break;
17791                case Dataset.INT32:
17792                        final int[] oi32data = ((IntegerDataset) result).getData();
17793                        if (it.isOutputDouble()) {
17794                                while (it.hasNext()) {
17795                                        final double ix = it.aDouble;
17796                                        int ox;
17797                                        ox = (int) toLong(Math.sin(ix));
17798                                        oi32data[it.oIndex] = ox;
17799                                }
17800                        } else {
17801                                while (it.hasNext()) {
17802                                        final long ix = it.aLong;
17803                                        int ox;
17804                                        ox = (int) toLong(Math.sin(ix));
17805                                        oi32data[it.oIndex] = ox;
17806                                }
17807                        }
17808                        break;
17809                case Dataset.ARRAYINT8:
17810                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
17811                        if (is == 1) {
17812                                if (it.isOutputDouble()) {
17813                                        while (it.hasNext()) {
17814                                                final double ix = it.aDouble;
17815                                                byte ox;
17816                                                ox = (byte) toLong(Math.sin(ix));
17817                                                oai8data[it.oIndex] = ox;
17818                                        }
17819                                } else {
17820                                        while (it.hasNext()) {
17821                                                final long ix = it.aLong;
17822                                                byte ox;
17823                                                ox = (byte) toLong(Math.sin(ix));
17824                                                oai8data[it.oIndex] = ox;
17825                                        }
17826                                }
17827                        } else if (as == 1) {
17828                                if (it.isOutputDouble()) {
17829                                        while (it.hasNext()) {
17830                                                final double ix = it.aDouble;
17831                                                byte ox;
17832                                                ox = (byte) toLong(Math.sin(ix));
17833                                                for (int j = 0; j < is; j++) {
17834                                                        oai8data[it.oIndex + j] = ox;
17835                                                }
17836                                        }
17837                                } else {
17838                                        while (it.hasNext()) {
17839                                                final long ix = it.aLong;
17840                                                byte ox;
17841                                                ox = (byte) toLong(Math.sin(ix));
17842                                                for (int j = 0; j < is; j++) {
17843                                                        oai8data[it.oIndex + j] = ox;
17844                                                }
17845                                        }
17846                                }
17847                        } else {
17848                                if (it.isOutputDouble()) {
17849                                        while (it.hasNext()) {
17850                                                for (int j = 0; j < is; j++) {
17851                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
17852                                                        byte ox;
17853                                                        ox = (byte) toLong(Math.sin(ix));
17854                                                        oai8data[it.oIndex + j] = ox;
17855                                                }
17856                                        }
17857                                } else {
17858                                        while (it.hasNext()) {
17859                                                for (int j = 0; j < is; j++) {
17860                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17861                                                        byte ox;
17862                                                        ox = (byte) toLong(Math.sin(ix));
17863                                                        oai8data[it.oIndex + j] = ox;
17864                                                }
17865                                        }
17866                                }
17867                        }
17868                        break;
17869                case Dataset.ARRAYINT16:
17870                        final short[] oai16data = ((CompoundShortDataset) result).getData();
17871                        if (is == 1) {
17872                                if (it.isOutputDouble()) {
17873                                        while (it.hasNext()) {
17874                                                final double ix = it.aDouble;
17875                                                short ox;
17876                                                ox = (short) toLong(Math.sin(ix));
17877                                                oai16data[it.oIndex] = ox;
17878                                        }
17879                                } else {
17880                                        while (it.hasNext()) {
17881                                                final long ix = it.aLong;
17882                                                short ox;
17883                                                ox = (short) toLong(Math.sin(ix));
17884                                                oai16data[it.oIndex] = ox;
17885                                        }
17886                                }
17887                        } else if (as == 1) {
17888                                if (it.isOutputDouble()) {
17889                                        while (it.hasNext()) {
17890                                                final double ix = it.aDouble;
17891                                                short ox;
17892                                                ox = (short) toLong(Math.sin(ix));
17893                                                for (int j = 0; j < is; j++) {
17894                                                        oai16data[it.oIndex + j] = ox;
17895                                                }
17896                                        }
17897                                } else {
17898                                        while (it.hasNext()) {
17899                                                final long ix = it.aLong;
17900                                                short ox;
17901                                                ox = (short) toLong(Math.sin(ix));
17902                                                for (int j = 0; j < is; j++) {
17903                                                        oai16data[it.oIndex + j] = ox;
17904                                                }
17905                                        }
17906                                }
17907                        } else {
17908                                if (it.isOutputDouble()) {
17909                                        while (it.hasNext()) {
17910                                                for (int j = 0; j < is; j++) {
17911                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
17912                                                        short ox;
17913                                                        ox = (short) toLong(Math.sin(ix));
17914                                                        oai16data[it.oIndex + j] = ox;
17915                                                }
17916                                        }
17917                                } else {
17918                                        while (it.hasNext()) {
17919                                                for (int j = 0; j < is; j++) {
17920                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17921                                                        short ox;
17922                                                        ox = (short) toLong(Math.sin(ix));
17923                                                        oai16data[it.oIndex + j] = ox;
17924                                                }
17925                                        }
17926                                }
17927                        }
17928                        break;
17929                case Dataset.ARRAYINT64:
17930                        final long[] oai64data = ((CompoundLongDataset) result).getData();
17931                        if (is == 1) {
17932                                if (it.isOutputDouble()) {
17933                                        while (it.hasNext()) {
17934                                                final double ix = it.aDouble;
17935                                                long ox;
17936                                                ox = toLong(Math.sin(ix));
17937                                                oai64data[it.oIndex] = ox;
17938                                        }
17939                                } else {
17940                                        while (it.hasNext()) {
17941                                                final long ix = it.aLong;
17942                                                long ox;
17943                                                ox = toLong(Math.sin(ix));
17944                                                oai64data[it.oIndex] = ox;
17945                                        }
17946                                }
17947                        } else if (as == 1) {
17948                                if (it.isOutputDouble()) {
17949                                        while (it.hasNext()) {
17950                                                final double ix = it.aDouble;
17951                                                long ox;
17952                                                ox = toLong(Math.sin(ix));
17953                                                for (int j = 0; j < is; j++) {
17954                                                        oai64data[it.oIndex + j] = ox;
17955                                                }
17956                                        }
17957                                } else {
17958                                        while (it.hasNext()) {
17959                                                final long ix = it.aLong;
17960                                                long ox;
17961                                                ox = toLong(Math.sin(ix));
17962                                                for (int j = 0; j < is; j++) {
17963                                                        oai64data[it.oIndex + j] = ox;
17964                                                }
17965                                        }
17966                                }
17967                        } else {
17968                                if (it.isOutputDouble()) {
17969                                        while (it.hasNext()) {
17970                                                for (int j = 0; j < is; j++) {
17971                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
17972                                                        long ox;
17973                                                        ox = toLong(Math.sin(ix));
17974                                                        oai64data[it.oIndex + j] = ox;
17975                                                }
17976                                        }
17977                                } else {
17978                                        while (it.hasNext()) {
17979                                                for (int j = 0; j < is; j++) {
17980                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17981                                                        long ox;
17982                                                        ox = toLong(Math.sin(ix));
17983                                                        oai64data[it.oIndex + j] = ox;
17984                                                }
17985                                        }
17986                                }
17987                        }
17988                        break;
17989                case Dataset.ARRAYINT32:
17990                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
17991                        if (is == 1) {
17992                                if (it.isOutputDouble()) {
17993                                        while (it.hasNext()) {
17994                                                final double ix = it.aDouble;
17995                                                int ox;
17996                                                ox = (int) toLong(Math.sin(ix));
17997                                                oai32data[it.oIndex] = ox;
17998                                        }
17999                                } else {
18000                                        while (it.hasNext()) {
18001                                                final long ix = it.aLong;
18002                                                int ox;
18003                                                ox = (int) toLong(Math.sin(ix));
18004                                                oai32data[it.oIndex] = ox;
18005                                        }
18006                                }
18007                        } else if (as == 1) {
18008                                if (it.isOutputDouble()) {
18009                                        while (it.hasNext()) {
18010                                                final double ix = it.aDouble;
18011                                                int ox;
18012                                                ox = (int) toLong(Math.sin(ix));
18013                                                for (int j = 0; j < is; j++) {
18014                                                        oai32data[it.oIndex + j] = ox;
18015                                                }
18016                                        }
18017                                } else {
18018                                        while (it.hasNext()) {
18019                                                final long ix = it.aLong;
18020                                                int ox;
18021                                                ox = (int) toLong(Math.sin(ix));
18022                                                for (int j = 0; j < is; j++) {
18023                                                        oai32data[it.oIndex + j] = ox;
18024                                                }
18025                                        }
18026                                }
18027                        } else {
18028                                if (it.isOutputDouble()) {
18029                                        while (it.hasNext()) {
18030                                                for (int j = 0; j < is; j++) {
18031                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18032                                                        int ox;
18033                                                        ox = (int) toLong(Math.sin(ix));
18034                                                        oai32data[it.oIndex + j] = ox;
18035                                                }
18036                                        }
18037                                } else {
18038                                        while (it.hasNext()) {
18039                                                for (int j = 0; j < is; j++) {
18040                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18041                                                        int ox;
18042                                                        ox = (int) toLong(Math.sin(ix));
18043                                                        oai32data[it.oIndex + j] = ox;
18044                                                }
18045                                        }
18046                                }
18047                        }
18048                        break;
18049                case Dataset.FLOAT32:
18050                        final float[] of32data = ((FloatDataset) result).getData();
18051                        if (it.isOutputDouble()) {
18052                                while (it.hasNext()) {
18053                                        final double ix = it.aDouble;
18054                                        float ox;
18055                                        ox = (float) (Math.sin(ix));
18056                                        of32data[it.oIndex] = ox;
18057                                }
18058                        } else {
18059                                while (it.hasNext()) {
18060                                        final long ix = it.aLong;
18061                                        float ox;
18062                                        ox = (float) (Math.sin(ix));
18063                                        of32data[it.oIndex] = ox;
18064                                }
18065                        }
18066                        break;
18067                case Dataset.FLOAT64:
18068                        final double[] of64data = ((DoubleDataset) result).getData();
18069                        if (it.isOutputDouble()) {
18070                                while (it.hasNext()) {
18071                                        final double ix = it.aDouble;
18072                                        double ox;
18073                                        ox = (Math.sin(ix));
18074                                        of64data[it.oIndex] = ox;
18075                                }
18076                        } else {
18077                                while (it.hasNext()) {
18078                                        final long ix = it.aLong;
18079                                        double ox;
18080                                        ox = (Math.sin(ix));
18081                                        of64data[it.oIndex] = ox;
18082                                }
18083                        }
18084                        break;
18085                case Dataset.ARRAYFLOAT32:
18086                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
18087                        if (is == 1) {
18088                                if (it.isOutputDouble()) {
18089                                        while (it.hasNext()) {
18090                                                final double ix = it.aDouble;
18091                                                float ox;
18092                                                ox = (float) (Math.sin(ix));
18093                                                oaf32data[it.oIndex] = ox;
18094                                        }
18095                                } else {
18096                                        while (it.hasNext()) {
18097                                                final long ix = it.aLong;
18098                                                float ox;
18099                                                ox = (float) (Math.sin(ix));
18100                                                oaf32data[it.oIndex] = ox;
18101                                        }
18102                                }
18103                        } else if (as == 1) {
18104                                if (it.isOutputDouble()) {
18105                                        while (it.hasNext()) {
18106                                                final double ix = it.aDouble;
18107                                                float ox;
18108                                                ox = (float) (Math.sin(ix));
18109                                                for (int j = 0; j < is; j++) {
18110                                                        oaf32data[it.oIndex + j] = ox;
18111                                                }
18112                                        }
18113                                } else {
18114                                        while (it.hasNext()) {
18115                                                final long ix = it.aLong;
18116                                                float ox;
18117                                                ox = (float) (Math.sin(ix));
18118                                                for (int j = 0; j < is; j++) {
18119                                                        oaf32data[it.oIndex + j] = ox;
18120                                                }
18121                                        }
18122                                }
18123                        } else {
18124                                if (it.isOutputDouble()) {
18125                                        while (it.hasNext()) {
18126                                                for (int j = 0; j < is; j++) {
18127                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18128                                                        float ox;
18129                                                        ox = (float) (Math.sin(ix));
18130                                                        oaf32data[it.oIndex + j] = ox;
18131                                                }
18132                                        }
18133                                } else {
18134                                        while (it.hasNext()) {
18135                                                for (int j = 0; j < is; j++) {
18136                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18137                                                        float ox;
18138                                                        ox = (float) (Math.sin(ix));
18139                                                        oaf32data[it.oIndex + j] = ox;
18140                                                }
18141                                        }
18142                                }
18143                        }
18144                        break;
18145                case Dataset.ARRAYFLOAT64:
18146                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
18147                        if (is == 1) {
18148                                if (it.isOutputDouble()) {
18149                                        while (it.hasNext()) {
18150                                                final double ix = it.aDouble;
18151                                                double ox;
18152                                                ox = (Math.sin(ix));
18153                                                oaf64data[it.oIndex] = ox;
18154                                        }
18155                                } else {
18156                                        while (it.hasNext()) {
18157                                                final long ix = it.aLong;
18158                                                double ox;
18159                                                ox = (Math.sin(ix));
18160                                                oaf64data[it.oIndex] = ox;
18161                                        }
18162                                }
18163                        } else if (as == 1) {
18164                                if (it.isOutputDouble()) {
18165                                        while (it.hasNext()) {
18166                                                final double ix = it.aDouble;
18167                                                double ox;
18168                                                ox = (Math.sin(ix));
18169                                                for (int j = 0; j < is; j++) {
18170                                                        oaf64data[it.oIndex + j] = ox;
18171                                                }
18172                                        }
18173                                } else {
18174                                        while (it.hasNext()) {
18175                                                final long ix = it.aLong;
18176                                                double ox;
18177                                                ox = (Math.sin(ix));
18178                                                for (int j = 0; j < is; j++) {
18179                                                        oaf64data[it.oIndex + j] = ox;
18180                                                }
18181                                        }
18182                                }
18183                        } else {
18184                                if (it.isOutputDouble()) {
18185                                        while (it.hasNext()) {
18186                                                for (int j = 0; j < is; j++) {
18187                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18188                                                        double ox;
18189                                                        ox = (Math.sin(ix));
18190                                                        oaf64data[it.oIndex + j] = ox;
18191                                                }
18192                                        }
18193                                } else {
18194                                        while (it.hasNext()) {
18195                                                for (int j = 0; j < is; j++) {
18196                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18197                                                        double ox;
18198                                                        ox = (Math.sin(ix));
18199                                                        oaf64data[it.oIndex + j] = ox;
18200                                                }
18201                                        }
18202                                }
18203                        }
18204                        break;
18205                case Dataset.COMPLEX64:
18206                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
18207                        if (!da.isComplex()) {
18208                                if (it.isOutputDouble()) {
18209                                        final double iy = 0;
18210                                        while (it.hasNext()) {
18211                                                final double ix = it.aDouble;
18212                                                float ox;
18213                                                float oy;
18214                                                ox = (float) (Math.sin(ix)*Math.cosh(iy));
18215                                                oy = (float) (Math.cos(ix)*Math.sinh(iy));
18216                                                oc64data[it.oIndex] = ox;
18217                                                oc64data[it.oIndex + 1] = oy;
18218                                        }
18219                                } else {
18220                                        final long iy = 0;
18221                                        while (it.hasNext()) {
18222                                                final long ix = it.aLong;
18223                                                float ox;
18224                                                float oy;
18225                                                ox = (float) toLong(Math.sin(ix)*Math.cosh(iy));
18226                                                oy = (float) toLong(Math.cos(ix)*Math.sinh(iy));
18227                                                oc64data[it.oIndex] = ox;
18228                                                oc64data[it.oIndex + 1] = oy;
18229                                        }
18230                                }
18231                        } else {
18232                                while (it.hasNext()) {
18233                                        final double ix = it.aDouble;
18234                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
18235                                        float ox;
18236                                        float oy;
18237                                        ox = (float) (Math.sin(ix)*Math.cosh(iy));
18238                                        oy = (float) (Math.cos(ix)*Math.sinh(iy));
18239                                        oc64data[it.oIndex] = ox;
18240                                        oc64data[it.oIndex + 1] = oy;
18241                                }
18242                        }
18243                        break;
18244                case Dataset.COMPLEX128:
18245                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
18246                        if (!da.isComplex()) {
18247                                if (it.isOutputDouble()) {
18248                                        final double iy = 0;
18249                                        while (it.hasNext()) {
18250                                                final double ix = it.aDouble;
18251                                                double ox;
18252                                                double oy;
18253                                                ox = (Math.sin(ix)*Math.cosh(iy));
18254                                                oy = (Math.cos(ix)*Math.sinh(iy));
18255                                                oc128data[it.oIndex] = ox;
18256                                                oc128data[it.oIndex + 1] = oy;
18257                                        }
18258                                } else {
18259                                        final long iy = 0;
18260                                        while (it.hasNext()) {
18261                                                final long ix = it.aLong;
18262                                                double ox;
18263                                                double oy;
18264                                                ox = (double) (Math.sin(ix)*Math.cosh(iy));
18265                                                oy = (double) (Math.cos(ix)*Math.sinh(iy));
18266                                                oc128data[it.oIndex] = ox;
18267                                                oc128data[it.oIndex + 1] = oy;
18268                                        }
18269                                }
18270                        } else {
18271                                while (it.hasNext()) {
18272                                        final double ix = it.aDouble;
18273                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
18274                                        double ox;
18275                                        double oy;
18276                                        ox = (Math.sin(ix)*Math.cosh(iy));
18277                                        oy = (Math.cos(ix)*Math.sinh(iy));
18278                                        oc128data[it.oIndex] = ox;
18279                                        oc128data[it.oIndex + 1] = oy;
18280                                }
18281                        }
18282                        break;
18283                default:
18284                        throw new IllegalArgumentException("sin supports integer, compound integer, real, compound real, complex datasets only");
18285                }
18286
18287                addFunctionName(result, "sin");
18288                return result;
18289        }
18290
18291        /**
18292         * cos - evaluate the cosine function on each element of the dataset
18293         * @param a
18294         * @return dataset
18295         */
18296        public static Dataset cos(final Object a) {
18297                return cos(a, null);
18298        }
18299
18300        /**
18301         * cos - evaluate the cosine function on each element of the dataset
18302         * @param a
18303         * @param o output can be null - in which case, a new dataset is created
18304         * @return dataset
18305         */
18306        public static Dataset cos(final Object a, final Dataset o) {
18307                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
18308                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
18309                final Dataset result = it.getOutput();
18310                if (!result.isComplex()) {
18311                        if (da.isComplex()) {
18312                                da = da.getRealView();
18313                                it = new SingleInputBroadcastIterator(da, result, true);
18314                        }
18315                }
18316                final int is = result.getElementsPerItem();
18317                final int as = da.getElementsPerItem();
18318                final int dt = result.getDType();
18319
18320                switch(dt) {
18321                case Dataset.INT8:
18322                        final byte[] oi8data = ((ByteDataset) result).getData();
18323                        if (it.isOutputDouble()) {
18324                                while (it.hasNext()) {
18325                                        final double ix = it.aDouble;
18326                                        byte ox;
18327                                        ox = (byte) toLong(Math.cos(ix));
18328                                        oi8data[it.oIndex] = ox;
18329                                }
18330                        } else {
18331                                while (it.hasNext()) {
18332                                        final long ix = it.aLong;
18333                                        byte ox;
18334                                        ox = (byte) toLong(Math.cos(ix));
18335                                        oi8data[it.oIndex] = ox;
18336                                }
18337                        }
18338                        break;
18339                case Dataset.INT16:
18340                        final short[] oi16data = ((ShortDataset) result).getData();
18341                        if (it.isOutputDouble()) {
18342                                while (it.hasNext()) {
18343                                        final double ix = it.aDouble;
18344                                        short ox;
18345                                        ox = (short) toLong(Math.cos(ix));
18346                                        oi16data[it.oIndex] = ox;
18347                                }
18348                        } else {
18349                                while (it.hasNext()) {
18350                                        final long ix = it.aLong;
18351                                        short ox;
18352                                        ox = (short) toLong(Math.cos(ix));
18353                                        oi16data[it.oIndex] = ox;
18354                                }
18355                        }
18356                        break;
18357                case Dataset.INT64:
18358                        final long[] oi64data = ((LongDataset) result).getData();
18359                        if (it.isOutputDouble()) {
18360                                while (it.hasNext()) {
18361                                        final double ix = it.aDouble;
18362                                        long ox;
18363                                        ox = toLong(Math.cos(ix));
18364                                        oi64data[it.oIndex] = ox;
18365                                }
18366                        } else {
18367                                while (it.hasNext()) {
18368                                        final long ix = it.aLong;
18369                                        long ox;
18370                                        ox = toLong(Math.cos(ix));
18371                                        oi64data[it.oIndex] = ox;
18372                                }
18373                        }
18374                        break;
18375                case Dataset.INT32:
18376                        final int[] oi32data = ((IntegerDataset) result).getData();
18377                        if (it.isOutputDouble()) {
18378                                while (it.hasNext()) {
18379                                        final double ix = it.aDouble;
18380                                        int ox;
18381                                        ox = (int) toLong(Math.cos(ix));
18382                                        oi32data[it.oIndex] = ox;
18383                                }
18384                        } else {
18385                                while (it.hasNext()) {
18386                                        final long ix = it.aLong;
18387                                        int ox;
18388                                        ox = (int) toLong(Math.cos(ix));
18389                                        oi32data[it.oIndex] = ox;
18390                                }
18391                        }
18392                        break;
18393                case Dataset.ARRAYINT8:
18394                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
18395                        if (is == 1) {
18396                                if (it.isOutputDouble()) {
18397                                        while (it.hasNext()) {
18398                                                final double ix = it.aDouble;
18399                                                byte ox;
18400                                                ox = (byte) toLong(Math.cos(ix));
18401                                                oai8data[it.oIndex] = ox;
18402                                        }
18403                                } else {
18404                                        while (it.hasNext()) {
18405                                                final long ix = it.aLong;
18406                                                byte ox;
18407                                                ox = (byte) toLong(Math.cos(ix));
18408                                                oai8data[it.oIndex] = ox;
18409                                        }
18410                                }
18411                        } else if (as == 1) {
18412                                if (it.isOutputDouble()) {
18413                                        while (it.hasNext()) {
18414                                                final double ix = it.aDouble;
18415                                                byte ox;
18416                                                ox = (byte) toLong(Math.cos(ix));
18417                                                for (int j = 0; j < is; j++) {
18418                                                        oai8data[it.oIndex + j] = ox;
18419                                                }
18420                                        }
18421                                } else {
18422                                        while (it.hasNext()) {
18423                                                final long ix = it.aLong;
18424                                                byte ox;
18425                                                ox = (byte) toLong(Math.cos(ix));
18426                                                for (int j = 0; j < is; j++) {
18427                                                        oai8data[it.oIndex + j] = ox;
18428                                                }
18429                                        }
18430                                }
18431                        } else {
18432                                if (it.isOutputDouble()) {
18433                                        while (it.hasNext()) {
18434                                                for (int j = 0; j < is; j++) {
18435                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18436                                                        byte ox;
18437                                                        ox = (byte) toLong(Math.cos(ix));
18438                                                        oai8data[it.oIndex + j] = ox;
18439                                                }
18440                                        }
18441                                } else {
18442                                        while (it.hasNext()) {
18443                                                for (int j = 0; j < is; j++) {
18444                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18445                                                        byte ox;
18446                                                        ox = (byte) toLong(Math.cos(ix));
18447                                                        oai8data[it.oIndex + j] = ox;
18448                                                }
18449                                        }
18450                                }
18451                        }
18452                        break;
18453                case Dataset.ARRAYINT16:
18454                        final short[] oai16data = ((CompoundShortDataset) result).getData();
18455                        if (is == 1) {
18456                                if (it.isOutputDouble()) {
18457                                        while (it.hasNext()) {
18458                                                final double ix = it.aDouble;
18459                                                short ox;
18460                                                ox = (short) toLong(Math.cos(ix));
18461                                                oai16data[it.oIndex] = ox;
18462                                        }
18463                                } else {
18464                                        while (it.hasNext()) {
18465                                                final long ix = it.aLong;
18466                                                short ox;
18467                                                ox = (short) toLong(Math.cos(ix));
18468                                                oai16data[it.oIndex] = ox;
18469                                        }
18470                                }
18471                        } else if (as == 1) {
18472                                if (it.isOutputDouble()) {
18473                                        while (it.hasNext()) {
18474                                                final double ix = it.aDouble;
18475                                                short ox;
18476                                                ox = (short) toLong(Math.cos(ix));
18477                                                for (int j = 0; j < is; j++) {
18478                                                        oai16data[it.oIndex + j] = ox;
18479                                                }
18480                                        }
18481                                } else {
18482                                        while (it.hasNext()) {
18483                                                final long ix = it.aLong;
18484                                                short ox;
18485                                                ox = (short) toLong(Math.cos(ix));
18486                                                for (int j = 0; j < is; j++) {
18487                                                        oai16data[it.oIndex + j] = ox;
18488                                                }
18489                                        }
18490                                }
18491                        } else {
18492                                if (it.isOutputDouble()) {
18493                                        while (it.hasNext()) {
18494                                                for (int j = 0; j < is; j++) {
18495                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18496                                                        short ox;
18497                                                        ox = (short) toLong(Math.cos(ix));
18498                                                        oai16data[it.oIndex + j] = ox;
18499                                                }
18500                                        }
18501                                } else {
18502                                        while (it.hasNext()) {
18503                                                for (int j = 0; j < is; j++) {
18504                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18505                                                        short ox;
18506                                                        ox = (short) toLong(Math.cos(ix));
18507                                                        oai16data[it.oIndex + j] = ox;
18508                                                }
18509                                        }
18510                                }
18511                        }
18512                        break;
18513                case Dataset.ARRAYINT64:
18514                        final long[] oai64data = ((CompoundLongDataset) result).getData();
18515                        if (is == 1) {
18516                                if (it.isOutputDouble()) {
18517                                        while (it.hasNext()) {
18518                                                final double ix = it.aDouble;
18519                                                long ox;
18520                                                ox = toLong(Math.cos(ix));
18521                                                oai64data[it.oIndex] = ox;
18522                                        }
18523                                } else {
18524                                        while (it.hasNext()) {
18525                                                final long ix = it.aLong;
18526                                                long ox;
18527                                                ox = toLong(Math.cos(ix));
18528                                                oai64data[it.oIndex] = ox;
18529                                        }
18530                                }
18531                        } else if (as == 1) {
18532                                if (it.isOutputDouble()) {
18533                                        while (it.hasNext()) {
18534                                                final double ix = it.aDouble;
18535                                                long ox;
18536                                                ox = toLong(Math.cos(ix));
18537                                                for (int j = 0; j < is; j++) {
18538                                                        oai64data[it.oIndex + j] = ox;
18539                                                }
18540                                        }
18541                                } else {
18542                                        while (it.hasNext()) {
18543                                                final long ix = it.aLong;
18544                                                long ox;
18545                                                ox = toLong(Math.cos(ix));
18546                                                for (int j = 0; j < is; j++) {
18547                                                        oai64data[it.oIndex + j] = ox;
18548                                                }
18549                                        }
18550                                }
18551                        } else {
18552                                if (it.isOutputDouble()) {
18553                                        while (it.hasNext()) {
18554                                                for (int j = 0; j < is; j++) {
18555                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18556                                                        long ox;
18557                                                        ox = toLong(Math.cos(ix));
18558                                                        oai64data[it.oIndex + j] = ox;
18559                                                }
18560                                        }
18561                                } else {
18562                                        while (it.hasNext()) {
18563                                                for (int j = 0; j < is; j++) {
18564                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18565                                                        long ox;
18566                                                        ox = toLong(Math.cos(ix));
18567                                                        oai64data[it.oIndex + j] = ox;
18568                                                }
18569                                        }
18570                                }
18571                        }
18572                        break;
18573                case Dataset.ARRAYINT32:
18574                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
18575                        if (is == 1) {
18576                                if (it.isOutputDouble()) {
18577                                        while (it.hasNext()) {
18578                                                final double ix = it.aDouble;
18579                                                int ox;
18580                                                ox = (int) toLong(Math.cos(ix));
18581                                                oai32data[it.oIndex] = ox;
18582                                        }
18583                                } else {
18584                                        while (it.hasNext()) {
18585                                                final long ix = it.aLong;
18586                                                int ox;
18587                                                ox = (int) toLong(Math.cos(ix));
18588                                                oai32data[it.oIndex] = ox;
18589                                        }
18590                                }
18591                        } else if (as == 1) {
18592                                if (it.isOutputDouble()) {
18593                                        while (it.hasNext()) {
18594                                                final double ix = it.aDouble;
18595                                                int ox;
18596                                                ox = (int) toLong(Math.cos(ix));
18597                                                for (int j = 0; j < is; j++) {
18598                                                        oai32data[it.oIndex + j] = ox;
18599                                                }
18600                                        }
18601                                } else {
18602                                        while (it.hasNext()) {
18603                                                final long ix = it.aLong;
18604                                                int ox;
18605                                                ox = (int) toLong(Math.cos(ix));
18606                                                for (int j = 0; j < is; j++) {
18607                                                        oai32data[it.oIndex + j] = ox;
18608                                                }
18609                                        }
18610                                }
18611                        } else {
18612                                if (it.isOutputDouble()) {
18613                                        while (it.hasNext()) {
18614                                                for (int j = 0; j < is; j++) {
18615                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18616                                                        int ox;
18617                                                        ox = (int) toLong(Math.cos(ix));
18618                                                        oai32data[it.oIndex + j] = ox;
18619                                                }
18620                                        }
18621                                } else {
18622                                        while (it.hasNext()) {
18623                                                for (int j = 0; j < is; j++) {
18624                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18625                                                        int ox;
18626                                                        ox = (int) toLong(Math.cos(ix));
18627                                                        oai32data[it.oIndex + j] = ox;
18628                                                }
18629                                        }
18630                                }
18631                        }
18632                        break;
18633                case Dataset.FLOAT32:
18634                        final float[] of32data = ((FloatDataset) result).getData();
18635                        if (it.isOutputDouble()) {
18636                                while (it.hasNext()) {
18637                                        final double ix = it.aDouble;
18638                                        float ox;
18639                                        ox = (float) (Math.cos(ix));
18640                                        of32data[it.oIndex] = ox;
18641                                }
18642                        } else {
18643                                while (it.hasNext()) {
18644                                        final long ix = it.aLong;
18645                                        float ox;
18646                                        ox = (float) (Math.cos(ix));
18647                                        of32data[it.oIndex] = ox;
18648                                }
18649                        }
18650                        break;
18651                case Dataset.FLOAT64:
18652                        final double[] of64data = ((DoubleDataset) result).getData();
18653                        if (it.isOutputDouble()) {
18654                                while (it.hasNext()) {
18655                                        final double ix = it.aDouble;
18656                                        double ox;
18657                                        ox = (Math.cos(ix));
18658                                        of64data[it.oIndex] = ox;
18659                                }
18660                        } else {
18661                                while (it.hasNext()) {
18662                                        final long ix = it.aLong;
18663                                        double ox;
18664                                        ox = (Math.cos(ix));
18665                                        of64data[it.oIndex] = ox;
18666                                }
18667                        }
18668                        break;
18669                case Dataset.ARRAYFLOAT32:
18670                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
18671                        if (is == 1) {
18672                                if (it.isOutputDouble()) {
18673                                        while (it.hasNext()) {
18674                                                final double ix = it.aDouble;
18675                                                float ox;
18676                                                ox = (float) (Math.cos(ix));
18677                                                oaf32data[it.oIndex] = ox;
18678                                        }
18679                                } else {
18680                                        while (it.hasNext()) {
18681                                                final long ix = it.aLong;
18682                                                float ox;
18683                                                ox = (float) (Math.cos(ix));
18684                                                oaf32data[it.oIndex] = ox;
18685                                        }
18686                                }
18687                        } else if (as == 1) {
18688                                if (it.isOutputDouble()) {
18689                                        while (it.hasNext()) {
18690                                                final double ix = it.aDouble;
18691                                                float ox;
18692                                                ox = (float) (Math.cos(ix));
18693                                                for (int j = 0; j < is; j++) {
18694                                                        oaf32data[it.oIndex + j] = ox;
18695                                                }
18696                                        }
18697                                } else {
18698                                        while (it.hasNext()) {
18699                                                final long ix = it.aLong;
18700                                                float ox;
18701                                                ox = (float) (Math.cos(ix));
18702                                                for (int j = 0; j < is; j++) {
18703                                                        oaf32data[it.oIndex + j] = ox;
18704                                                }
18705                                        }
18706                                }
18707                        } else {
18708                                if (it.isOutputDouble()) {
18709                                        while (it.hasNext()) {
18710                                                for (int j = 0; j < is; j++) {
18711                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18712                                                        float ox;
18713                                                        ox = (float) (Math.cos(ix));
18714                                                        oaf32data[it.oIndex + j] = ox;
18715                                                }
18716                                        }
18717                                } else {
18718                                        while (it.hasNext()) {
18719                                                for (int j = 0; j < is; j++) {
18720                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18721                                                        float ox;
18722                                                        ox = (float) (Math.cos(ix));
18723                                                        oaf32data[it.oIndex + j] = ox;
18724                                                }
18725                                        }
18726                                }
18727                        }
18728                        break;
18729                case Dataset.ARRAYFLOAT64:
18730                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
18731                        if (is == 1) {
18732                                if (it.isOutputDouble()) {
18733                                        while (it.hasNext()) {
18734                                                final double ix = it.aDouble;
18735                                                double ox;
18736                                                ox = (Math.cos(ix));
18737                                                oaf64data[it.oIndex] = ox;
18738                                        }
18739                                } else {
18740                                        while (it.hasNext()) {
18741                                                final long ix = it.aLong;
18742                                                double ox;
18743                                                ox = (Math.cos(ix));
18744                                                oaf64data[it.oIndex] = ox;
18745                                        }
18746                                }
18747                        } else if (as == 1) {
18748                                if (it.isOutputDouble()) {
18749                                        while (it.hasNext()) {
18750                                                final double ix = it.aDouble;
18751                                                double ox;
18752                                                ox = (Math.cos(ix));
18753                                                for (int j = 0; j < is; j++) {
18754                                                        oaf64data[it.oIndex + j] = ox;
18755                                                }
18756                                        }
18757                                } else {
18758                                        while (it.hasNext()) {
18759                                                final long ix = it.aLong;
18760                                                double ox;
18761                                                ox = (Math.cos(ix));
18762                                                for (int j = 0; j < is; j++) {
18763                                                        oaf64data[it.oIndex + j] = ox;
18764                                                }
18765                                        }
18766                                }
18767                        } else {
18768                                if (it.isOutputDouble()) {
18769                                        while (it.hasNext()) {
18770                                                for (int j = 0; j < is; j++) {
18771                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18772                                                        double ox;
18773                                                        ox = (Math.cos(ix));
18774                                                        oaf64data[it.oIndex + j] = ox;
18775                                                }
18776                                        }
18777                                } else {
18778                                        while (it.hasNext()) {
18779                                                for (int j = 0; j < is; j++) {
18780                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18781                                                        double ox;
18782                                                        ox = (Math.cos(ix));
18783                                                        oaf64data[it.oIndex + j] = ox;
18784                                                }
18785                                        }
18786                                }
18787                        }
18788                        break;
18789                case Dataset.COMPLEX64:
18790                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
18791                        if (!da.isComplex()) {
18792                                if (it.isOutputDouble()) {
18793                                        final double iy = 0;
18794                                        while (it.hasNext()) {
18795                                                final double ix = it.aDouble;
18796                                                float ox;
18797                                                float oy;
18798                                                ox = (float) (Math.cos(ix)*Math.cosh(iy));
18799                                                oy = (float) (-Math.sin(ix)*Math.sinh(iy));
18800                                                oc64data[it.oIndex] = ox;
18801                                                oc64data[it.oIndex + 1] = oy;
18802                                        }
18803                                } else {
18804                                        final long iy = 0;
18805                                        while (it.hasNext()) {
18806                                                final long ix = it.aLong;
18807                                                float ox;
18808                                                float oy;
18809                                                ox = (float) toLong(Math.cos(ix)*Math.cosh(iy));
18810                                                oy = (float) toLong(-Math.sin(ix)*Math.sinh(iy));
18811                                                oc64data[it.oIndex] = ox;
18812                                                oc64data[it.oIndex + 1] = oy;
18813                                        }
18814                                }
18815                        } else {
18816                                while (it.hasNext()) {
18817                                        final double ix = it.aDouble;
18818                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
18819                                        float ox;
18820                                        float oy;
18821                                        ox = (float) (Math.cos(ix)*Math.cosh(iy));
18822                                        oy = (float) (-Math.sin(ix)*Math.sinh(iy));
18823                                        oc64data[it.oIndex] = ox;
18824                                        oc64data[it.oIndex + 1] = oy;
18825                                }
18826                        }
18827                        break;
18828                case Dataset.COMPLEX128:
18829                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
18830                        if (!da.isComplex()) {
18831                                if (it.isOutputDouble()) {
18832                                        final double iy = 0;
18833                                        while (it.hasNext()) {
18834                                                final double ix = it.aDouble;
18835                                                double ox;
18836                                                double oy;
18837                                                ox = (Math.cos(ix)*Math.cosh(iy));
18838                                                oy = (-Math.sin(ix)*Math.sinh(iy));
18839                                                oc128data[it.oIndex] = ox;
18840                                                oc128data[it.oIndex + 1] = oy;
18841                                        }
18842                                } else {
18843                                        final long iy = 0;
18844                                        while (it.hasNext()) {
18845                                                final long ix = it.aLong;
18846                                                double ox;
18847                                                double oy;
18848                                                ox = (double) (Math.cos(ix)*Math.cosh(iy));
18849                                                oy = (double) (-Math.sin(ix)*Math.sinh(iy));
18850                                                oc128data[it.oIndex] = ox;
18851                                                oc128data[it.oIndex + 1] = oy;
18852                                        }
18853                                }
18854                        } else {
18855                                while (it.hasNext()) {
18856                                        final double ix = it.aDouble;
18857                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
18858                                        double ox;
18859                                        double oy;
18860                                        ox = (Math.cos(ix)*Math.cosh(iy));
18861                                        oy = (-Math.sin(ix)*Math.sinh(iy));
18862                                        oc128data[it.oIndex] = ox;
18863                                        oc128data[it.oIndex + 1] = oy;
18864                                }
18865                        }
18866                        break;
18867                default:
18868                        throw new IllegalArgumentException("cos supports integer, compound integer, real, compound real, complex datasets only");
18869                }
18870
18871                addFunctionName(result, "cos");
18872                return result;
18873        }
18874
18875        /**
18876         * tan - evaluate the tangent function on each element of the dataset
18877         * @param a
18878         * @return dataset
18879         */
18880        public static Dataset tan(final Object a) {
18881                return tan(a, null);
18882        }
18883
18884        /**
18885         * tan - evaluate the tangent function on each element of the dataset
18886         * @param a
18887         * @param o output can be null - in which case, a new dataset is created
18888         * @return dataset
18889         */
18890        public static Dataset tan(final Object a, final Dataset o) {
18891                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
18892                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
18893                final Dataset result = it.getOutput();
18894                if (!result.isComplex()) {
18895                        if (da.isComplex()) {
18896                                da = da.getRealView();
18897                                it = new SingleInputBroadcastIterator(da, result, true);
18898                        }
18899                }
18900                final int is = result.getElementsPerItem();
18901                final int as = da.getElementsPerItem();
18902                final int dt = result.getDType();
18903
18904                switch(dt) {
18905                case Dataset.INT8:
18906                        final byte[] oi8data = ((ByteDataset) result).getData();
18907                        if (it.isOutputDouble()) {
18908                                while (it.hasNext()) {
18909                                        final double ix = it.aDouble;
18910                                        byte ox;
18911                                        ox = (byte) toLong(Math.tan(ix));
18912                                        oi8data[it.oIndex] = ox;
18913                                }
18914                        } else {
18915                                while (it.hasNext()) {
18916                                        final long ix = it.aLong;
18917                                        byte ox;
18918                                        ox = (byte) toLong(Math.tan(ix));
18919                                        oi8data[it.oIndex] = ox;
18920                                }
18921                        }
18922                        break;
18923                case Dataset.INT16:
18924                        final short[] oi16data = ((ShortDataset) result).getData();
18925                        if (it.isOutputDouble()) {
18926                                while (it.hasNext()) {
18927                                        final double ix = it.aDouble;
18928                                        short ox;
18929                                        ox = (short) toLong(Math.tan(ix));
18930                                        oi16data[it.oIndex] = ox;
18931                                }
18932                        } else {
18933                                while (it.hasNext()) {
18934                                        final long ix = it.aLong;
18935                                        short ox;
18936                                        ox = (short) toLong(Math.tan(ix));
18937                                        oi16data[it.oIndex] = ox;
18938                                }
18939                        }
18940                        break;
18941                case Dataset.INT64:
18942                        final long[] oi64data = ((LongDataset) result).getData();
18943                        if (it.isOutputDouble()) {
18944                                while (it.hasNext()) {
18945                                        final double ix = it.aDouble;
18946                                        long ox;
18947                                        ox = toLong(Math.tan(ix));
18948                                        oi64data[it.oIndex] = ox;
18949                                }
18950                        } else {
18951                                while (it.hasNext()) {
18952                                        final long ix = it.aLong;
18953                                        long ox;
18954                                        ox = toLong(Math.tan(ix));
18955                                        oi64data[it.oIndex] = ox;
18956                                }
18957                        }
18958                        break;
18959                case Dataset.INT32:
18960                        final int[] oi32data = ((IntegerDataset) result).getData();
18961                        if (it.isOutputDouble()) {
18962                                while (it.hasNext()) {
18963                                        final double ix = it.aDouble;
18964                                        int ox;
18965                                        ox = (int) toLong(Math.tan(ix));
18966                                        oi32data[it.oIndex] = ox;
18967                                }
18968                        } else {
18969                                while (it.hasNext()) {
18970                                        final long ix = it.aLong;
18971                                        int ox;
18972                                        ox = (int) toLong(Math.tan(ix));
18973                                        oi32data[it.oIndex] = ox;
18974                                }
18975                        }
18976                        break;
18977                case Dataset.ARRAYINT8:
18978                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
18979                        if (is == 1) {
18980                                if (it.isOutputDouble()) {
18981                                        while (it.hasNext()) {
18982                                                final double ix = it.aDouble;
18983                                                byte ox;
18984                                                ox = (byte) toLong(Math.tan(ix));
18985                                                oai8data[it.oIndex] = ox;
18986                                        }
18987                                } else {
18988                                        while (it.hasNext()) {
18989                                                final long ix = it.aLong;
18990                                                byte ox;
18991                                                ox = (byte) toLong(Math.tan(ix));
18992                                                oai8data[it.oIndex] = ox;
18993                                        }
18994                                }
18995                        } else if (as == 1) {
18996                                if (it.isOutputDouble()) {
18997                                        while (it.hasNext()) {
18998                                                final double ix = it.aDouble;
18999                                                byte ox;
19000                                                ox = (byte) toLong(Math.tan(ix));
19001                                                for (int j = 0; j < is; j++) {
19002                                                        oai8data[it.oIndex + j] = ox;
19003                                                }
19004                                        }
19005                                } else {
19006                                        while (it.hasNext()) {
19007                                                final long ix = it.aLong;
19008                                                byte ox;
19009                                                ox = (byte) toLong(Math.tan(ix));
19010                                                for (int j = 0; j < is; j++) {
19011                                                        oai8data[it.oIndex + j] = ox;
19012                                                }
19013                                        }
19014                                }
19015                        } else {
19016                                if (it.isOutputDouble()) {
19017                                        while (it.hasNext()) {
19018                                                for (int j = 0; j < is; j++) {
19019                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19020                                                        byte ox;
19021                                                        ox = (byte) toLong(Math.tan(ix));
19022                                                        oai8data[it.oIndex + j] = ox;
19023                                                }
19024                                        }
19025                                } else {
19026                                        while (it.hasNext()) {
19027                                                for (int j = 0; j < is; j++) {
19028                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19029                                                        byte ox;
19030                                                        ox = (byte) toLong(Math.tan(ix));
19031                                                        oai8data[it.oIndex + j] = ox;
19032                                                }
19033                                        }
19034                                }
19035                        }
19036                        break;
19037                case Dataset.ARRAYINT16:
19038                        final short[] oai16data = ((CompoundShortDataset) result).getData();
19039                        if (is == 1) {
19040                                if (it.isOutputDouble()) {
19041                                        while (it.hasNext()) {
19042                                                final double ix = it.aDouble;
19043                                                short ox;
19044                                                ox = (short) toLong(Math.tan(ix));
19045                                                oai16data[it.oIndex] = ox;
19046                                        }
19047                                } else {
19048                                        while (it.hasNext()) {
19049                                                final long ix = it.aLong;
19050                                                short ox;
19051                                                ox = (short) toLong(Math.tan(ix));
19052                                                oai16data[it.oIndex] = ox;
19053                                        }
19054                                }
19055                        } else if (as == 1) {
19056                                if (it.isOutputDouble()) {
19057                                        while (it.hasNext()) {
19058                                                final double ix = it.aDouble;
19059                                                short ox;
19060                                                ox = (short) toLong(Math.tan(ix));
19061                                                for (int j = 0; j < is; j++) {
19062                                                        oai16data[it.oIndex + j] = ox;
19063                                                }
19064                                        }
19065                                } else {
19066                                        while (it.hasNext()) {
19067                                                final long ix = it.aLong;
19068                                                short ox;
19069                                                ox = (short) toLong(Math.tan(ix));
19070                                                for (int j = 0; j < is; j++) {
19071                                                        oai16data[it.oIndex + j] = ox;
19072                                                }
19073                                        }
19074                                }
19075                        } else {
19076                                if (it.isOutputDouble()) {
19077                                        while (it.hasNext()) {
19078                                                for (int j = 0; j < is; j++) {
19079                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19080                                                        short ox;
19081                                                        ox = (short) toLong(Math.tan(ix));
19082                                                        oai16data[it.oIndex + j] = ox;
19083                                                }
19084                                        }
19085                                } else {
19086                                        while (it.hasNext()) {
19087                                                for (int j = 0; j < is; j++) {
19088                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19089                                                        short ox;
19090                                                        ox = (short) toLong(Math.tan(ix));
19091                                                        oai16data[it.oIndex + j] = ox;
19092                                                }
19093                                        }
19094                                }
19095                        }
19096                        break;
19097                case Dataset.ARRAYINT64:
19098                        final long[] oai64data = ((CompoundLongDataset) result).getData();
19099                        if (is == 1) {
19100                                if (it.isOutputDouble()) {
19101                                        while (it.hasNext()) {
19102                                                final double ix = it.aDouble;
19103                                                long ox;
19104                                                ox = toLong(Math.tan(ix));
19105                                                oai64data[it.oIndex] = ox;
19106                                        }
19107                                } else {
19108                                        while (it.hasNext()) {
19109                                                final long ix = it.aLong;
19110                                                long ox;
19111                                                ox = toLong(Math.tan(ix));
19112                                                oai64data[it.oIndex] = ox;
19113                                        }
19114                                }
19115                        } else if (as == 1) {
19116                                if (it.isOutputDouble()) {
19117                                        while (it.hasNext()) {
19118                                                final double ix = it.aDouble;
19119                                                long ox;
19120                                                ox = toLong(Math.tan(ix));
19121                                                for (int j = 0; j < is; j++) {
19122                                                        oai64data[it.oIndex + j] = ox;
19123                                                }
19124                                        }
19125                                } else {
19126                                        while (it.hasNext()) {
19127                                                final long ix = it.aLong;
19128                                                long ox;
19129                                                ox = toLong(Math.tan(ix));
19130                                                for (int j = 0; j < is; j++) {
19131                                                        oai64data[it.oIndex + j] = ox;
19132                                                }
19133                                        }
19134                                }
19135                        } else {
19136                                if (it.isOutputDouble()) {
19137                                        while (it.hasNext()) {
19138                                                for (int j = 0; j < is; j++) {
19139                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19140                                                        long ox;
19141                                                        ox = toLong(Math.tan(ix));
19142                                                        oai64data[it.oIndex + j] = ox;
19143                                                }
19144                                        }
19145                                } else {
19146                                        while (it.hasNext()) {
19147                                                for (int j = 0; j < is; j++) {
19148                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19149                                                        long ox;
19150                                                        ox = toLong(Math.tan(ix));
19151                                                        oai64data[it.oIndex + j] = ox;
19152                                                }
19153                                        }
19154                                }
19155                        }
19156                        break;
19157                case Dataset.ARRAYINT32:
19158                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
19159                        if (is == 1) {
19160                                if (it.isOutputDouble()) {
19161                                        while (it.hasNext()) {
19162                                                final double ix = it.aDouble;
19163                                                int ox;
19164                                                ox = (int) toLong(Math.tan(ix));
19165                                                oai32data[it.oIndex] = ox;
19166                                        }
19167                                } else {
19168                                        while (it.hasNext()) {
19169                                                final long ix = it.aLong;
19170                                                int ox;
19171                                                ox = (int) toLong(Math.tan(ix));
19172                                                oai32data[it.oIndex] = ox;
19173                                        }
19174                                }
19175                        } else if (as == 1) {
19176                                if (it.isOutputDouble()) {
19177                                        while (it.hasNext()) {
19178                                                final double ix = it.aDouble;
19179                                                int ox;
19180                                                ox = (int) toLong(Math.tan(ix));
19181                                                for (int j = 0; j < is; j++) {
19182                                                        oai32data[it.oIndex + j] = ox;
19183                                                }
19184                                        }
19185                                } else {
19186                                        while (it.hasNext()) {
19187                                                final long ix = it.aLong;
19188                                                int ox;
19189                                                ox = (int) toLong(Math.tan(ix));
19190                                                for (int j = 0; j < is; j++) {
19191                                                        oai32data[it.oIndex + j] = ox;
19192                                                }
19193                                        }
19194                                }
19195                        } else {
19196                                if (it.isOutputDouble()) {
19197                                        while (it.hasNext()) {
19198                                                for (int j = 0; j < is; j++) {
19199                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19200                                                        int ox;
19201                                                        ox = (int) toLong(Math.tan(ix));
19202                                                        oai32data[it.oIndex + j] = ox;
19203                                                }
19204                                        }
19205                                } else {
19206                                        while (it.hasNext()) {
19207                                                for (int j = 0; j < is; j++) {
19208                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19209                                                        int ox;
19210                                                        ox = (int) toLong(Math.tan(ix));
19211                                                        oai32data[it.oIndex + j] = ox;
19212                                                }
19213                                        }
19214                                }
19215                        }
19216                        break;
19217                case Dataset.FLOAT32:
19218                        final float[] of32data = ((FloatDataset) result).getData();
19219                        if (it.isOutputDouble()) {
19220                                while (it.hasNext()) {
19221                                        final double ix = it.aDouble;
19222                                        float ox;
19223                                        ox = (float) (Math.tan(ix));
19224                                        of32data[it.oIndex] = ox;
19225                                }
19226                        } else {
19227                                while (it.hasNext()) {
19228                                        final long ix = it.aLong;
19229                                        float ox;
19230                                        ox = (float) (Math.tan(ix));
19231                                        of32data[it.oIndex] = ox;
19232                                }
19233                        }
19234                        break;
19235                case Dataset.FLOAT64:
19236                        final double[] of64data = ((DoubleDataset) result).getData();
19237                        if (it.isOutputDouble()) {
19238                                while (it.hasNext()) {
19239                                        final double ix = it.aDouble;
19240                                        double ox;
19241                                        ox = (Math.tan(ix));
19242                                        of64data[it.oIndex] = ox;
19243                                }
19244                        } else {
19245                                while (it.hasNext()) {
19246                                        final long ix = it.aLong;
19247                                        double ox;
19248                                        ox = (Math.tan(ix));
19249                                        of64data[it.oIndex] = ox;
19250                                }
19251                        }
19252                        break;
19253                case Dataset.ARRAYFLOAT32:
19254                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
19255                        if (is == 1) {
19256                                if (it.isOutputDouble()) {
19257                                        while (it.hasNext()) {
19258                                                final double ix = it.aDouble;
19259                                                float ox;
19260                                                ox = (float) (Math.tan(ix));
19261                                                oaf32data[it.oIndex] = ox;
19262                                        }
19263                                } else {
19264                                        while (it.hasNext()) {
19265                                                final long ix = it.aLong;
19266                                                float ox;
19267                                                ox = (float) (Math.tan(ix));
19268                                                oaf32data[it.oIndex] = ox;
19269                                        }
19270                                }
19271                        } else if (as == 1) {
19272                                if (it.isOutputDouble()) {
19273                                        while (it.hasNext()) {
19274                                                final double ix = it.aDouble;
19275                                                float ox;
19276                                                ox = (float) (Math.tan(ix));
19277                                                for (int j = 0; j < is; j++) {
19278                                                        oaf32data[it.oIndex + j] = ox;
19279                                                }
19280                                        }
19281                                } else {
19282                                        while (it.hasNext()) {
19283                                                final long ix = it.aLong;
19284                                                float ox;
19285                                                ox = (float) (Math.tan(ix));
19286                                                for (int j = 0; j < is; j++) {
19287                                                        oaf32data[it.oIndex + j] = ox;
19288                                                }
19289                                        }
19290                                }
19291                        } else {
19292                                if (it.isOutputDouble()) {
19293                                        while (it.hasNext()) {
19294                                                for (int j = 0; j < is; j++) {
19295                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19296                                                        float ox;
19297                                                        ox = (float) (Math.tan(ix));
19298                                                        oaf32data[it.oIndex + j] = ox;
19299                                                }
19300                                        }
19301                                } else {
19302                                        while (it.hasNext()) {
19303                                                for (int j = 0; j < is; j++) {
19304                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19305                                                        float ox;
19306                                                        ox = (float) (Math.tan(ix));
19307                                                        oaf32data[it.oIndex + j] = ox;
19308                                                }
19309                                        }
19310                                }
19311                        }
19312                        break;
19313                case Dataset.ARRAYFLOAT64:
19314                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
19315                        if (is == 1) {
19316                                if (it.isOutputDouble()) {
19317                                        while (it.hasNext()) {
19318                                                final double ix = it.aDouble;
19319                                                double ox;
19320                                                ox = (Math.tan(ix));
19321                                                oaf64data[it.oIndex] = ox;
19322                                        }
19323                                } else {
19324                                        while (it.hasNext()) {
19325                                                final long ix = it.aLong;
19326                                                double ox;
19327                                                ox = (Math.tan(ix));
19328                                                oaf64data[it.oIndex] = ox;
19329                                        }
19330                                }
19331                        } else if (as == 1) {
19332                                if (it.isOutputDouble()) {
19333                                        while (it.hasNext()) {
19334                                                final double ix = it.aDouble;
19335                                                double ox;
19336                                                ox = (Math.tan(ix));
19337                                                for (int j = 0; j < is; j++) {
19338                                                        oaf64data[it.oIndex + j] = ox;
19339                                                }
19340                                        }
19341                                } else {
19342                                        while (it.hasNext()) {
19343                                                final long ix = it.aLong;
19344                                                double ox;
19345                                                ox = (Math.tan(ix));
19346                                                for (int j = 0; j < is; j++) {
19347                                                        oaf64data[it.oIndex + j] = ox;
19348                                                }
19349                                        }
19350                                }
19351                        } else {
19352                                if (it.isOutputDouble()) {
19353                                        while (it.hasNext()) {
19354                                                for (int j = 0; j < is; j++) {
19355                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19356                                                        double ox;
19357                                                        ox = (Math.tan(ix));
19358                                                        oaf64data[it.oIndex + j] = ox;
19359                                                }
19360                                        }
19361                                } else {
19362                                        while (it.hasNext()) {
19363                                                for (int j = 0; j < is; j++) {
19364                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19365                                                        double ox;
19366                                                        ox = (Math.tan(ix));
19367                                                        oaf64data[it.oIndex + j] = ox;
19368                                                }
19369                                        }
19370                                }
19371                        }
19372                        break;
19373                case Dataset.COMPLEX64:
19374                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
19375                        if (!da.isComplex()) {
19376                                if (it.isOutputDouble()) {
19377                                        final double iy = 0;
19378                                        while (it.hasNext()) {
19379                                                final double ix = it.aDouble;
19380                                                float x;
19381                                                float y;
19382                                                float tf;
19383                                                float ox;
19384                                                float oy;
19385                                                x = (float) (2.*ix);
19386                                                y = (float) (2.*iy);
19387                                                tf = (float) (1./(Math.cos(x)+Math.cosh(y)));
19388                                                ox = (float) (tf*Math.sin(x));
19389                                                oy = (float) (tf*Math.sinh(y));
19390                                                oc64data[it.oIndex] = ox;
19391                                                oc64data[it.oIndex + 1] = oy;
19392                                        }
19393                                } else {
19394                                        final long iy = 0;
19395                                        while (it.hasNext()) {
19396                                                final long ix = it.aLong;
19397                                                float x;
19398                                                float y;
19399                                                float tf;
19400                                                float ox;
19401                                                float oy;
19402                                                x = (float) toLong(2.*ix);
19403                                                y = (float) toLong(2.*iy);
19404                                                tf = (float) toLong(1./(Math.cos(x)+Math.cosh(y)));
19405                                                ox = (float) toLong(tf*Math.sin(x));
19406                                                oy = (float) toLong(tf*Math.sinh(y));
19407                                                oc64data[it.oIndex] = ox;
19408                                                oc64data[it.oIndex + 1] = oy;
19409                                        }
19410                                }
19411                        } else {
19412                                while (it.hasNext()) {
19413                                        final double ix = it.aDouble;
19414                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
19415                                        float x;
19416                                        float y;
19417                                        float tf;
19418                                        float ox;
19419                                        float oy;
19420                                        x = (float) (2.*ix);
19421                                        y = (float) (2.*iy);
19422                                        tf = (float) (1./(Math.cos(x)+Math.cosh(y)));
19423                                        ox = (float) (tf*Math.sin(x));
19424                                        oy = (float) (tf*Math.sinh(y));
19425                                        oc64data[it.oIndex] = ox;
19426                                        oc64data[it.oIndex + 1] = oy;
19427                                }
19428                        }
19429                        break;
19430                case Dataset.COMPLEX128:
19431                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
19432                        if (!da.isComplex()) {
19433                                if (it.isOutputDouble()) {
19434                                        final double iy = 0;
19435                                        while (it.hasNext()) {
19436                                                final double ix = it.aDouble;
19437                                                double x;
19438                                                double y;
19439                                                double tf;
19440                                                double ox;
19441                                                double oy;
19442                                                x = (2.*ix);
19443                                                y = (2.*iy);
19444                                                tf = (1./(Math.cos(x)+Math.cosh(y)));
19445                                                ox = (tf*Math.sin(x));
19446                                                oy = (tf*Math.sinh(y));
19447                                                oc128data[it.oIndex] = ox;
19448                                                oc128data[it.oIndex + 1] = oy;
19449                                        }
19450                                } else {
19451                                        final long iy = 0;
19452                                        while (it.hasNext()) {
19453                                                final long ix = it.aLong;
19454                                                double x;
19455                                                double y;
19456                                                double tf;
19457                                                double ox;
19458                                                double oy;
19459                                                x = (2.*ix);
19460                                                y = (2.*iy);
19461                                                tf = (double) (1./(Math.cos(x)+Math.cosh(y)));
19462                                                ox = (double) (tf*Math.sin(x));
19463                                                oy = (double) (tf*Math.sinh(y));
19464                                                oc128data[it.oIndex] = ox;
19465                                                oc128data[it.oIndex + 1] = oy;
19466                                        }
19467                                }
19468                        } else {
19469                                while (it.hasNext()) {
19470                                        final double ix = it.aDouble;
19471                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
19472                                        double x;
19473                                        double y;
19474                                        double tf;
19475                                        double ox;
19476                                        double oy;
19477                                        x = (2.*ix);
19478                                        y = (2.*iy);
19479                                        tf = (1./(Math.cos(x)+Math.cosh(y)));
19480                                        ox = (tf*Math.sin(x));
19481                                        oy = (tf*Math.sinh(y));
19482                                        oc128data[it.oIndex] = ox;
19483                                        oc128data[it.oIndex + 1] = oy;
19484                                }
19485                        }
19486                        break;
19487                default:
19488                        throw new IllegalArgumentException("tan supports integer, compound integer, real, compound real, complex datasets only");
19489                }
19490
19491                addFunctionName(result, "tan");
19492                return result;
19493        }
19494
19495        /**
19496         * arcsin - evaluate the inverse sine function on each element of the dataset
19497         * @param a
19498         * @return dataset
19499         */
19500        public static Dataset arcsin(final Object a) {
19501                return arcsin(a, null);
19502        }
19503
19504        /**
19505         * arcsin - evaluate the inverse sine function on each element of the dataset
19506         * @param a
19507         * @param o output can be null - in which case, a new dataset is created
19508         * @return dataset
19509         */
19510        public static Dataset arcsin(final Object a, final Dataset o) {
19511                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
19512                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
19513                final Dataset result = it.getOutput();
19514                if (!result.isComplex()) {
19515                        if (da.isComplex()) {
19516                                da = da.getRealView();
19517                                it = new SingleInputBroadcastIterator(da, result, true);
19518                        }
19519                }
19520                final int is = result.getElementsPerItem();
19521                final int as = da.getElementsPerItem();
19522                final int dt = result.getDType();
19523
19524                switch(dt) {
19525                case Dataset.INT8:
19526                        final byte[] oi8data = ((ByteDataset) result).getData();
19527                        if (it.isOutputDouble()) {
19528                                while (it.hasNext()) {
19529                                        final double ix = it.aDouble;
19530                                        byte ox;
19531                                        ox = (byte) toLong(Math.asin(ix));
19532                                        oi8data[it.oIndex] = ox;
19533                                }
19534                        } else {
19535                                while (it.hasNext()) {
19536                                        final long ix = it.aLong;
19537                                        byte ox;
19538                                        ox = (byte) toLong(Math.asin(ix));
19539                                        oi8data[it.oIndex] = ox;
19540                                }
19541                        }
19542                        break;
19543                case Dataset.INT16:
19544                        final short[] oi16data = ((ShortDataset) result).getData();
19545                        if (it.isOutputDouble()) {
19546                                while (it.hasNext()) {
19547                                        final double ix = it.aDouble;
19548                                        short ox;
19549                                        ox = (short) toLong(Math.asin(ix));
19550                                        oi16data[it.oIndex] = ox;
19551                                }
19552                        } else {
19553                                while (it.hasNext()) {
19554                                        final long ix = it.aLong;
19555                                        short ox;
19556                                        ox = (short) toLong(Math.asin(ix));
19557                                        oi16data[it.oIndex] = ox;
19558                                }
19559                        }
19560                        break;
19561                case Dataset.INT64:
19562                        final long[] oi64data = ((LongDataset) result).getData();
19563                        if (it.isOutputDouble()) {
19564                                while (it.hasNext()) {
19565                                        final double ix = it.aDouble;
19566                                        long ox;
19567                                        ox = toLong(Math.asin(ix));
19568                                        oi64data[it.oIndex] = ox;
19569                                }
19570                        } else {
19571                                while (it.hasNext()) {
19572                                        final long ix = it.aLong;
19573                                        long ox;
19574                                        ox = toLong(Math.asin(ix));
19575                                        oi64data[it.oIndex] = ox;
19576                                }
19577                        }
19578                        break;
19579                case Dataset.INT32:
19580                        final int[] oi32data = ((IntegerDataset) result).getData();
19581                        if (it.isOutputDouble()) {
19582                                while (it.hasNext()) {
19583                                        final double ix = it.aDouble;
19584                                        int ox;
19585                                        ox = (int) toLong(Math.asin(ix));
19586                                        oi32data[it.oIndex] = ox;
19587                                }
19588                        } else {
19589                                while (it.hasNext()) {
19590                                        final long ix = it.aLong;
19591                                        int ox;
19592                                        ox = (int) toLong(Math.asin(ix));
19593                                        oi32data[it.oIndex] = ox;
19594                                }
19595                        }
19596                        break;
19597                case Dataset.ARRAYINT8:
19598                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
19599                        if (is == 1) {
19600                                if (it.isOutputDouble()) {
19601                                        while (it.hasNext()) {
19602                                                final double ix = it.aDouble;
19603                                                byte ox;
19604                                                ox = (byte) toLong(Math.asin(ix));
19605                                                oai8data[it.oIndex] = ox;
19606                                        }
19607                                } else {
19608                                        while (it.hasNext()) {
19609                                                final long ix = it.aLong;
19610                                                byte ox;
19611                                                ox = (byte) toLong(Math.asin(ix));
19612                                                oai8data[it.oIndex] = ox;
19613                                        }
19614                                }
19615                        } else if (as == 1) {
19616                                if (it.isOutputDouble()) {
19617                                        while (it.hasNext()) {
19618                                                final double ix = it.aDouble;
19619                                                byte ox;
19620                                                ox = (byte) toLong(Math.asin(ix));
19621                                                for (int j = 0; j < is; j++) {
19622                                                        oai8data[it.oIndex + j] = ox;
19623                                                }
19624                                        }
19625                                } else {
19626                                        while (it.hasNext()) {
19627                                                final long ix = it.aLong;
19628                                                byte ox;
19629                                                ox = (byte) toLong(Math.asin(ix));
19630                                                for (int j = 0; j < is; j++) {
19631                                                        oai8data[it.oIndex + j] = ox;
19632                                                }
19633                                        }
19634                                }
19635                        } else {
19636                                if (it.isOutputDouble()) {
19637                                        while (it.hasNext()) {
19638                                                for (int j = 0; j < is; j++) {
19639                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19640                                                        byte ox;
19641                                                        ox = (byte) toLong(Math.asin(ix));
19642                                                        oai8data[it.oIndex + j] = ox;
19643                                                }
19644                                        }
19645                                } else {
19646                                        while (it.hasNext()) {
19647                                                for (int j = 0; j < is; j++) {
19648                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19649                                                        byte ox;
19650                                                        ox = (byte) toLong(Math.asin(ix));
19651                                                        oai8data[it.oIndex + j] = ox;
19652                                                }
19653                                        }
19654                                }
19655                        }
19656                        break;
19657                case Dataset.ARRAYINT16:
19658                        final short[] oai16data = ((CompoundShortDataset) result).getData();
19659                        if (is == 1) {
19660                                if (it.isOutputDouble()) {
19661                                        while (it.hasNext()) {
19662                                                final double ix = it.aDouble;
19663                                                short ox;
19664                                                ox = (short) toLong(Math.asin(ix));
19665                                                oai16data[it.oIndex] = ox;
19666                                        }
19667                                } else {
19668                                        while (it.hasNext()) {
19669                                                final long ix = it.aLong;
19670                                                short ox;
19671                                                ox = (short) toLong(Math.asin(ix));
19672                                                oai16data[it.oIndex] = ox;
19673                                        }
19674                                }
19675                        } else if (as == 1) {
19676                                if (it.isOutputDouble()) {
19677                                        while (it.hasNext()) {
19678                                                final double ix = it.aDouble;
19679                                                short ox;
19680                                                ox = (short) toLong(Math.asin(ix));
19681                                                for (int j = 0; j < is; j++) {
19682                                                        oai16data[it.oIndex + j] = ox;
19683                                                }
19684                                        }
19685                                } else {
19686                                        while (it.hasNext()) {
19687                                                final long ix = it.aLong;
19688                                                short ox;
19689                                                ox = (short) toLong(Math.asin(ix));
19690                                                for (int j = 0; j < is; j++) {
19691                                                        oai16data[it.oIndex + j] = ox;
19692                                                }
19693                                        }
19694                                }
19695                        } else {
19696                                if (it.isOutputDouble()) {
19697                                        while (it.hasNext()) {
19698                                                for (int j = 0; j < is; j++) {
19699                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19700                                                        short ox;
19701                                                        ox = (short) toLong(Math.asin(ix));
19702                                                        oai16data[it.oIndex + j] = ox;
19703                                                }
19704                                        }
19705                                } else {
19706                                        while (it.hasNext()) {
19707                                                for (int j = 0; j < is; j++) {
19708                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19709                                                        short ox;
19710                                                        ox = (short) toLong(Math.asin(ix));
19711                                                        oai16data[it.oIndex + j] = ox;
19712                                                }
19713                                        }
19714                                }
19715                        }
19716                        break;
19717                case Dataset.ARRAYINT64:
19718                        final long[] oai64data = ((CompoundLongDataset) result).getData();
19719                        if (is == 1) {
19720                                if (it.isOutputDouble()) {
19721                                        while (it.hasNext()) {
19722                                                final double ix = it.aDouble;
19723                                                long ox;
19724                                                ox = toLong(Math.asin(ix));
19725                                                oai64data[it.oIndex] = ox;
19726                                        }
19727                                } else {
19728                                        while (it.hasNext()) {
19729                                                final long ix = it.aLong;
19730                                                long ox;
19731                                                ox = toLong(Math.asin(ix));
19732                                                oai64data[it.oIndex] = ox;
19733                                        }
19734                                }
19735                        } else if (as == 1) {
19736                                if (it.isOutputDouble()) {
19737                                        while (it.hasNext()) {
19738                                                final double ix = it.aDouble;
19739                                                long ox;
19740                                                ox = toLong(Math.asin(ix));
19741                                                for (int j = 0; j < is; j++) {
19742                                                        oai64data[it.oIndex + j] = ox;
19743                                                }
19744                                        }
19745                                } else {
19746                                        while (it.hasNext()) {
19747                                                final long ix = it.aLong;
19748                                                long ox;
19749                                                ox = toLong(Math.asin(ix));
19750                                                for (int j = 0; j < is; j++) {
19751                                                        oai64data[it.oIndex + j] = ox;
19752                                                }
19753                                        }
19754                                }
19755                        } else {
19756                                if (it.isOutputDouble()) {
19757                                        while (it.hasNext()) {
19758                                                for (int j = 0; j < is; j++) {
19759                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19760                                                        long ox;
19761                                                        ox = toLong(Math.asin(ix));
19762                                                        oai64data[it.oIndex + j] = ox;
19763                                                }
19764                                        }
19765                                } else {
19766                                        while (it.hasNext()) {
19767                                                for (int j = 0; j < is; j++) {
19768                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19769                                                        long ox;
19770                                                        ox = toLong(Math.asin(ix));
19771                                                        oai64data[it.oIndex + j] = ox;
19772                                                }
19773                                        }
19774                                }
19775                        }
19776                        break;
19777                case Dataset.ARRAYINT32:
19778                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
19779                        if (is == 1) {
19780                                if (it.isOutputDouble()) {
19781                                        while (it.hasNext()) {
19782                                                final double ix = it.aDouble;
19783                                                int ox;
19784                                                ox = (int) toLong(Math.asin(ix));
19785                                                oai32data[it.oIndex] = ox;
19786                                        }
19787                                } else {
19788                                        while (it.hasNext()) {
19789                                                final long ix = it.aLong;
19790                                                int ox;
19791                                                ox = (int) toLong(Math.asin(ix));
19792                                                oai32data[it.oIndex] = ox;
19793                                        }
19794                                }
19795                        } else if (as == 1) {
19796                                if (it.isOutputDouble()) {
19797                                        while (it.hasNext()) {
19798                                                final double ix = it.aDouble;
19799                                                int ox;
19800                                                ox = (int) toLong(Math.asin(ix));
19801                                                for (int j = 0; j < is; j++) {
19802                                                        oai32data[it.oIndex + j] = ox;
19803                                                }
19804                                        }
19805                                } else {
19806                                        while (it.hasNext()) {
19807                                                final long ix = it.aLong;
19808                                                int ox;
19809                                                ox = (int) toLong(Math.asin(ix));
19810                                                for (int j = 0; j < is; j++) {
19811                                                        oai32data[it.oIndex + j] = ox;
19812                                                }
19813                                        }
19814                                }
19815                        } else {
19816                                if (it.isOutputDouble()) {
19817                                        while (it.hasNext()) {
19818                                                for (int j = 0; j < is; j++) {
19819                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19820                                                        int ox;
19821                                                        ox = (int) toLong(Math.asin(ix));
19822                                                        oai32data[it.oIndex + j] = ox;
19823                                                }
19824                                        }
19825                                } else {
19826                                        while (it.hasNext()) {
19827                                                for (int j = 0; j < is; j++) {
19828                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19829                                                        int ox;
19830                                                        ox = (int) toLong(Math.asin(ix));
19831                                                        oai32data[it.oIndex + j] = ox;
19832                                                }
19833                                        }
19834                                }
19835                        }
19836                        break;
19837                case Dataset.FLOAT32:
19838                        final float[] of32data = ((FloatDataset) result).getData();
19839                        if (it.isOutputDouble()) {
19840                                while (it.hasNext()) {
19841                                        final double ix = it.aDouble;
19842                                        float ox;
19843                                        ox = (float) (Math.asin(ix));
19844                                        of32data[it.oIndex] = ox;
19845                                }
19846                        } else {
19847                                while (it.hasNext()) {
19848                                        final long ix = it.aLong;
19849                                        float ox;
19850                                        ox = (float) (Math.asin(ix));
19851                                        of32data[it.oIndex] = ox;
19852                                }
19853                        }
19854                        break;
19855                case Dataset.FLOAT64:
19856                        final double[] of64data = ((DoubleDataset) result).getData();
19857                        if (it.isOutputDouble()) {
19858                                while (it.hasNext()) {
19859                                        final double ix = it.aDouble;
19860                                        double ox;
19861                                        ox = (Math.asin(ix));
19862                                        of64data[it.oIndex] = ox;
19863                                }
19864                        } else {
19865                                while (it.hasNext()) {
19866                                        final long ix = it.aLong;
19867                                        double ox;
19868                                        ox = (Math.asin(ix));
19869                                        of64data[it.oIndex] = ox;
19870                                }
19871                        }
19872                        break;
19873                case Dataset.ARRAYFLOAT32:
19874                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
19875                        if (is == 1) {
19876                                if (it.isOutputDouble()) {
19877                                        while (it.hasNext()) {
19878                                                final double ix = it.aDouble;
19879                                                float ox;
19880                                                ox = (float) (Math.asin(ix));
19881                                                oaf32data[it.oIndex] = ox;
19882                                        }
19883                                } else {
19884                                        while (it.hasNext()) {
19885                                                final long ix = it.aLong;
19886                                                float ox;
19887                                                ox = (float) (Math.asin(ix));
19888                                                oaf32data[it.oIndex] = ox;
19889                                        }
19890                                }
19891                        } else if (as == 1) {
19892                                if (it.isOutputDouble()) {
19893                                        while (it.hasNext()) {
19894                                                final double ix = it.aDouble;
19895                                                float ox;
19896                                                ox = (float) (Math.asin(ix));
19897                                                for (int j = 0; j < is; j++) {
19898                                                        oaf32data[it.oIndex + j] = ox;
19899                                                }
19900                                        }
19901                                } else {
19902                                        while (it.hasNext()) {
19903                                                final long ix = it.aLong;
19904                                                float ox;
19905                                                ox = (float) (Math.asin(ix));
19906                                                for (int j = 0; j < is; j++) {
19907                                                        oaf32data[it.oIndex + j] = ox;
19908                                                }
19909                                        }
19910                                }
19911                        } else {
19912                                if (it.isOutputDouble()) {
19913                                        while (it.hasNext()) {
19914                                                for (int j = 0; j < is; j++) {
19915                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19916                                                        float ox;
19917                                                        ox = (float) (Math.asin(ix));
19918                                                        oaf32data[it.oIndex + j] = ox;
19919                                                }
19920                                        }
19921                                } else {
19922                                        while (it.hasNext()) {
19923                                                for (int j = 0; j < is; j++) {
19924                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19925                                                        float ox;
19926                                                        ox = (float) (Math.asin(ix));
19927                                                        oaf32data[it.oIndex + j] = ox;
19928                                                }
19929                                        }
19930                                }
19931                        }
19932                        break;
19933                case Dataset.ARRAYFLOAT64:
19934                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
19935                        if (is == 1) {
19936                                if (it.isOutputDouble()) {
19937                                        while (it.hasNext()) {
19938                                                final double ix = it.aDouble;
19939                                                double ox;
19940                                                ox = (Math.asin(ix));
19941                                                oaf64data[it.oIndex] = ox;
19942                                        }
19943                                } else {
19944                                        while (it.hasNext()) {
19945                                                final long ix = it.aLong;
19946                                                double ox;
19947                                                ox = (Math.asin(ix));
19948                                                oaf64data[it.oIndex] = ox;
19949                                        }
19950                                }
19951                        } else if (as == 1) {
19952                                if (it.isOutputDouble()) {
19953                                        while (it.hasNext()) {
19954                                                final double ix = it.aDouble;
19955                                                double ox;
19956                                                ox = (Math.asin(ix));
19957                                                for (int j = 0; j < is; j++) {
19958                                                        oaf64data[it.oIndex + j] = ox;
19959                                                }
19960                                        }
19961                                } else {
19962                                        while (it.hasNext()) {
19963                                                final long ix = it.aLong;
19964                                                double ox;
19965                                                ox = (Math.asin(ix));
19966                                                for (int j = 0; j < is; j++) {
19967                                                        oaf64data[it.oIndex + j] = ox;
19968                                                }
19969                                        }
19970                                }
19971                        } else {
19972                                if (it.isOutputDouble()) {
19973                                        while (it.hasNext()) {
19974                                                for (int j = 0; j < is; j++) {
19975                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19976                                                        double ox;
19977                                                        ox = (Math.asin(ix));
19978                                                        oaf64data[it.oIndex + j] = ox;
19979                                                }
19980                                        }
19981                                } else {
19982                                        while (it.hasNext()) {
19983                                                for (int j = 0; j < is; j++) {
19984                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19985                                                        double ox;
19986                                                        ox = (Math.asin(ix));
19987                                                        oaf64data[it.oIndex + j] = ox;
19988                                                }
19989                                        }
19990                                }
19991                        }
19992                        break;
19993                case Dataset.COMPLEX64:
19994                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
19995                        if (!da.isComplex()) {
19996                                if (it.isOutputDouble()) {
19997                                        final double iy = 0;
19998                                        while (it.hasNext()) {
19999                                                final double ix = it.aDouble;
20000                                                Complex tz;
20001                                                float ox;
20002                                                float oy;
20003                                                tz = new Complex(ix, iy).asin();
20004                                                ox = (float) (tz.getReal());
20005                                                oy = (float) (tz.getImaginary());
20006                                                oc64data[it.oIndex] = ox;
20007                                                oc64data[it.oIndex + 1] = oy;
20008                                        }
20009                                } else {
20010                                        final long iy = 0;
20011                                        while (it.hasNext()) {
20012                                                final long ix = it.aLong;
20013                                                Complex tz;
20014                                                float ox;
20015                                                float oy;
20016                                                tz = new Complex(ix, iy).asin();
20017                                                ox = (float) toLong(tz.getReal());
20018                                                oy = (float) toLong(tz.getImaginary());
20019                                                oc64data[it.oIndex] = ox;
20020                                                oc64data[it.oIndex + 1] = oy;
20021                                        }
20022                                }
20023                        } else {
20024                                while (it.hasNext()) {
20025                                        final double ix = it.aDouble;
20026                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
20027                                        Complex tz;
20028                                        float ox;
20029                                        float oy;
20030                                        tz = new Complex(ix, iy).asin();
20031                                        ox = (float) (tz.getReal());
20032                                        oy = (float) (tz.getImaginary());
20033                                        oc64data[it.oIndex] = ox;
20034                                        oc64data[it.oIndex + 1] = oy;
20035                                }
20036                        }
20037                        break;
20038                case Dataset.COMPLEX128:
20039                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
20040                        if (!da.isComplex()) {
20041                                if (it.isOutputDouble()) {
20042                                        final double iy = 0;
20043                                        while (it.hasNext()) {
20044                                                final double ix = it.aDouble;
20045                                                Complex tz;
20046                                                double ox;
20047                                                double oy;
20048                                                tz = new Complex(ix, iy).asin();
20049                                                ox = (tz.getReal());
20050                                                oy = (tz.getImaginary());
20051                                                oc128data[it.oIndex] = ox;
20052                                                oc128data[it.oIndex + 1] = oy;
20053                                        }
20054                                } else {
20055                                        final long iy = 0;
20056                                        while (it.hasNext()) {
20057                                                final long ix = it.aLong;
20058                                                Complex tz;
20059                                                double ox;
20060                                                double oy;
20061                                                tz = new Complex(ix, iy).asin();
20062                                                ox = (tz.getReal());
20063                                                oy = (tz.getImaginary());
20064                                                oc128data[it.oIndex] = ox;
20065                                                oc128data[it.oIndex + 1] = oy;
20066                                        }
20067                                }
20068                        } else {
20069                                while (it.hasNext()) {
20070                                        final double ix = it.aDouble;
20071                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
20072                                        Complex tz;
20073                                        double ox;
20074                                        double oy;
20075                                        tz = new Complex(ix, iy).asin();
20076                                        ox = (tz.getReal());
20077                                        oy = (tz.getImaginary());
20078                                        oc128data[it.oIndex] = ox;
20079                                        oc128data[it.oIndex + 1] = oy;
20080                                }
20081                        }
20082                        break;
20083                default:
20084                        throw new IllegalArgumentException("arcsin supports integer, compound integer, real, compound real, complex datasets only");
20085                }
20086
20087                addFunctionName(result, "arcsin");
20088                return result;
20089        }
20090
20091        /**
20092         * arccos - evaluate the inverse cosine function on each element of the dataset
20093         * @param a
20094         * @return dataset
20095         */
20096        public static Dataset arccos(final Object a) {
20097                return arccos(a, null);
20098        }
20099
20100        /**
20101         * arccos - evaluate the inverse cosine function on each element of the dataset
20102         * @param a
20103         * @param o output can be null - in which case, a new dataset is created
20104         * @return dataset
20105         */
20106        public static Dataset arccos(final Object a, final Dataset o) {
20107                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
20108                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
20109                final Dataset result = it.getOutput();
20110                if (!result.isComplex()) {
20111                        if (da.isComplex()) {
20112                                da = da.getRealView();
20113                                it = new SingleInputBroadcastIterator(da, result, true);
20114                        }
20115                }
20116                final int is = result.getElementsPerItem();
20117                final int as = da.getElementsPerItem();
20118                final int dt = result.getDType();
20119
20120                switch(dt) {
20121                case Dataset.INT8:
20122                        final byte[] oi8data = ((ByteDataset) result).getData();
20123                        if (it.isOutputDouble()) {
20124                                while (it.hasNext()) {
20125                                        final double ix = it.aDouble;
20126                                        byte ox;
20127                                        ox = (byte) toLong(Math.acos(ix));
20128                                        oi8data[it.oIndex] = ox;
20129                                }
20130                        } else {
20131                                while (it.hasNext()) {
20132                                        final long ix = it.aLong;
20133                                        byte ox;
20134                                        ox = (byte) toLong(Math.acos(ix));
20135                                        oi8data[it.oIndex] = ox;
20136                                }
20137                        }
20138                        break;
20139                case Dataset.INT16:
20140                        final short[] oi16data = ((ShortDataset) result).getData();
20141                        if (it.isOutputDouble()) {
20142                                while (it.hasNext()) {
20143                                        final double ix = it.aDouble;
20144                                        short ox;
20145                                        ox = (short) toLong(Math.acos(ix));
20146                                        oi16data[it.oIndex] = ox;
20147                                }
20148                        } else {
20149                                while (it.hasNext()) {
20150                                        final long ix = it.aLong;
20151                                        short ox;
20152                                        ox = (short) toLong(Math.acos(ix));
20153                                        oi16data[it.oIndex] = ox;
20154                                }
20155                        }
20156                        break;
20157                case Dataset.INT64:
20158                        final long[] oi64data = ((LongDataset) result).getData();
20159                        if (it.isOutputDouble()) {
20160                                while (it.hasNext()) {
20161                                        final double ix = it.aDouble;
20162                                        long ox;
20163                                        ox = toLong(Math.acos(ix));
20164                                        oi64data[it.oIndex] = ox;
20165                                }
20166                        } else {
20167                                while (it.hasNext()) {
20168                                        final long ix = it.aLong;
20169                                        long ox;
20170                                        ox = toLong(Math.acos(ix));
20171                                        oi64data[it.oIndex] = ox;
20172                                }
20173                        }
20174                        break;
20175                case Dataset.INT32:
20176                        final int[] oi32data = ((IntegerDataset) result).getData();
20177                        if (it.isOutputDouble()) {
20178                                while (it.hasNext()) {
20179                                        final double ix = it.aDouble;
20180                                        int ox;
20181                                        ox = (int) toLong(Math.acos(ix));
20182                                        oi32data[it.oIndex] = ox;
20183                                }
20184                        } else {
20185                                while (it.hasNext()) {
20186                                        final long ix = it.aLong;
20187                                        int ox;
20188                                        ox = (int) toLong(Math.acos(ix));
20189                                        oi32data[it.oIndex] = ox;
20190                                }
20191                        }
20192                        break;
20193                case Dataset.ARRAYINT8:
20194                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
20195                        if (is == 1) {
20196                                if (it.isOutputDouble()) {
20197                                        while (it.hasNext()) {
20198                                                final double ix = it.aDouble;
20199                                                byte ox;
20200                                                ox = (byte) toLong(Math.acos(ix));
20201                                                oai8data[it.oIndex] = ox;
20202                                        }
20203                                } else {
20204                                        while (it.hasNext()) {
20205                                                final long ix = it.aLong;
20206                                                byte ox;
20207                                                ox = (byte) toLong(Math.acos(ix));
20208                                                oai8data[it.oIndex] = ox;
20209                                        }
20210                                }
20211                        } else if (as == 1) {
20212                                if (it.isOutputDouble()) {
20213                                        while (it.hasNext()) {
20214                                                final double ix = it.aDouble;
20215                                                byte ox;
20216                                                ox = (byte) toLong(Math.acos(ix));
20217                                                for (int j = 0; j < is; j++) {
20218                                                        oai8data[it.oIndex + j] = ox;
20219                                                }
20220                                        }
20221                                } else {
20222                                        while (it.hasNext()) {
20223                                                final long ix = it.aLong;
20224                                                byte ox;
20225                                                ox = (byte) toLong(Math.acos(ix));
20226                                                for (int j = 0; j < is; j++) {
20227                                                        oai8data[it.oIndex + j] = ox;
20228                                                }
20229                                        }
20230                                }
20231                        } else {
20232                                if (it.isOutputDouble()) {
20233                                        while (it.hasNext()) {
20234                                                for (int j = 0; j < is; j++) {
20235                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20236                                                        byte ox;
20237                                                        ox = (byte) toLong(Math.acos(ix));
20238                                                        oai8data[it.oIndex + j] = ox;
20239                                                }
20240                                        }
20241                                } else {
20242                                        while (it.hasNext()) {
20243                                                for (int j = 0; j < is; j++) {
20244                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20245                                                        byte ox;
20246                                                        ox = (byte) toLong(Math.acos(ix));
20247                                                        oai8data[it.oIndex + j] = ox;
20248                                                }
20249                                        }
20250                                }
20251                        }
20252                        break;
20253                case Dataset.ARRAYINT16:
20254                        final short[] oai16data = ((CompoundShortDataset) result).getData();
20255                        if (is == 1) {
20256                                if (it.isOutputDouble()) {
20257                                        while (it.hasNext()) {
20258                                                final double ix = it.aDouble;
20259                                                short ox;
20260                                                ox = (short) toLong(Math.acos(ix));
20261                                                oai16data[it.oIndex] = ox;
20262                                        }
20263                                } else {
20264                                        while (it.hasNext()) {
20265                                                final long ix = it.aLong;
20266                                                short ox;
20267                                                ox = (short) toLong(Math.acos(ix));
20268                                                oai16data[it.oIndex] = ox;
20269                                        }
20270                                }
20271                        } else if (as == 1) {
20272                                if (it.isOutputDouble()) {
20273                                        while (it.hasNext()) {
20274                                                final double ix = it.aDouble;
20275                                                short ox;
20276                                                ox = (short) toLong(Math.acos(ix));
20277                                                for (int j = 0; j < is; j++) {
20278                                                        oai16data[it.oIndex + j] = ox;
20279                                                }
20280                                        }
20281                                } else {
20282                                        while (it.hasNext()) {
20283                                                final long ix = it.aLong;
20284                                                short ox;
20285                                                ox = (short) toLong(Math.acos(ix));
20286                                                for (int j = 0; j < is; j++) {
20287                                                        oai16data[it.oIndex + j] = ox;
20288                                                }
20289                                        }
20290                                }
20291                        } else {
20292                                if (it.isOutputDouble()) {
20293                                        while (it.hasNext()) {
20294                                                for (int j = 0; j < is; j++) {
20295                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20296                                                        short ox;
20297                                                        ox = (short) toLong(Math.acos(ix));
20298                                                        oai16data[it.oIndex + j] = ox;
20299                                                }
20300                                        }
20301                                } else {
20302                                        while (it.hasNext()) {
20303                                                for (int j = 0; j < is; j++) {
20304                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20305                                                        short ox;
20306                                                        ox = (short) toLong(Math.acos(ix));
20307                                                        oai16data[it.oIndex + j] = ox;
20308                                                }
20309                                        }
20310                                }
20311                        }
20312                        break;
20313                case Dataset.ARRAYINT64:
20314                        final long[] oai64data = ((CompoundLongDataset) result).getData();
20315                        if (is == 1) {
20316                                if (it.isOutputDouble()) {
20317                                        while (it.hasNext()) {
20318                                                final double ix = it.aDouble;
20319                                                long ox;
20320                                                ox = toLong(Math.acos(ix));
20321                                                oai64data[it.oIndex] = ox;
20322                                        }
20323                                } else {
20324                                        while (it.hasNext()) {
20325                                                final long ix = it.aLong;
20326                                                long ox;
20327                                                ox = toLong(Math.acos(ix));
20328                                                oai64data[it.oIndex] = ox;
20329                                        }
20330                                }
20331                        } else if (as == 1) {
20332                                if (it.isOutputDouble()) {
20333                                        while (it.hasNext()) {
20334                                                final double ix = it.aDouble;
20335                                                long ox;
20336                                                ox = toLong(Math.acos(ix));
20337                                                for (int j = 0; j < is; j++) {
20338                                                        oai64data[it.oIndex + j] = ox;
20339                                                }
20340                                        }
20341                                } else {
20342                                        while (it.hasNext()) {
20343                                                final long ix = it.aLong;
20344                                                long ox;
20345                                                ox = toLong(Math.acos(ix));
20346                                                for (int j = 0; j < is; j++) {
20347                                                        oai64data[it.oIndex + j] = ox;
20348                                                }
20349                                        }
20350                                }
20351                        } else {
20352                                if (it.isOutputDouble()) {
20353                                        while (it.hasNext()) {
20354                                                for (int j = 0; j < is; j++) {
20355                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20356                                                        long ox;
20357                                                        ox = toLong(Math.acos(ix));
20358                                                        oai64data[it.oIndex + j] = ox;
20359                                                }
20360                                        }
20361                                } else {
20362                                        while (it.hasNext()) {
20363                                                for (int j = 0; j < is; j++) {
20364                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20365                                                        long ox;
20366                                                        ox = toLong(Math.acos(ix));
20367                                                        oai64data[it.oIndex + j] = ox;
20368                                                }
20369                                        }
20370                                }
20371                        }
20372                        break;
20373                case Dataset.ARRAYINT32:
20374                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
20375                        if (is == 1) {
20376                                if (it.isOutputDouble()) {
20377                                        while (it.hasNext()) {
20378                                                final double ix = it.aDouble;
20379                                                int ox;
20380                                                ox = (int) toLong(Math.acos(ix));
20381                                                oai32data[it.oIndex] = ox;
20382                                        }
20383                                } else {
20384                                        while (it.hasNext()) {
20385                                                final long ix = it.aLong;
20386                                                int ox;
20387                                                ox = (int) toLong(Math.acos(ix));
20388                                                oai32data[it.oIndex] = ox;
20389                                        }
20390                                }
20391                        } else if (as == 1) {
20392                                if (it.isOutputDouble()) {
20393                                        while (it.hasNext()) {
20394                                                final double ix = it.aDouble;
20395                                                int ox;
20396                                                ox = (int) toLong(Math.acos(ix));
20397                                                for (int j = 0; j < is; j++) {
20398                                                        oai32data[it.oIndex + j] = ox;
20399                                                }
20400                                        }
20401                                } else {
20402                                        while (it.hasNext()) {
20403                                                final long ix = it.aLong;
20404                                                int ox;
20405                                                ox = (int) toLong(Math.acos(ix));
20406                                                for (int j = 0; j < is; j++) {
20407                                                        oai32data[it.oIndex + j] = ox;
20408                                                }
20409                                        }
20410                                }
20411                        } else {
20412                                if (it.isOutputDouble()) {
20413                                        while (it.hasNext()) {
20414                                                for (int j = 0; j < is; j++) {
20415                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20416                                                        int ox;
20417                                                        ox = (int) toLong(Math.acos(ix));
20418                                                        oai32data[it.oIndex + j] = ox;
20419                                                }
20420                                        }
20421                                } else {
20422                                        while (it.hasNext()) {
20423                                                for (int j = 0; j < is; j++) {
20424                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20425                                                        int ox;
20426                                                        ox = (int) toLong(Math.acos(ix));
20427                                                        oai32data[it.oIndex + j] = ox;
20428                                                }
20429                                        }
20430                                }
20431                        }
20432                        break;
20433                case Dataset.FLOAT32:
20434                        final float[] of32data = ((FloatDataset) result).getData();
20435                        if (it.isOutputDouble()) {
20436                                while (it.hasNext()) {
20437                                        final double ix = it.aDouble;
20438                                        float ox;
20439                                        ox = (float) (Math.acos(ix));
20440                                        of32data[it.oIndex] = ox;
20441                                }
20442                        } else {
20443                                while (it.hasNext()) {
20444                                        final long ix = it.aLong;
20445                                        float ox;
20446                                        ox = (float) (Math.acos(ix));
20447                                        of32data[it.oIndex] = ox;
20448                                }
20449                        }
20450                        break;
20451                case Dataset.FLOAT64:
20452                        final double[] of64data = ((DoubleDataset) result).getData();
20453                        if (it.isOutputDouble()) {
20454                                while (it.hasNext()) {
20455                                        final double ix = it.aDouble;
20456                                        double ox;
20457                                        ox = (Math.acos(ix));
20458                                        of64data[it.oIndex] = ox;
20459                                }
20460                        } else {
20461                                while (it.hasNext()) {
20462                                        final long ix = it.aLong;
20463                                        double ox;
20464                                        ox = (Math.acos(ix));
20465                                        of64data[it.oIndex] = ox;
20466                                }
20467                        }
20468                        break;
20469                case Dataset.ARRAYFLOAT32:
20470                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
20471                        if (is == 1) {
20472                                if (it.isOutputDouble()) {
20473                                        while (it.hasNext()) {
20474                                                final double ix = it.aDouble;
20475                                                float ox;
20476                                                ox = (float) (Math.acos(ix));
20477                                                oaf32data[it.oIndex] = ox;
20478                                        }
20479                                } else {
20480                                        while (it.hasNext()) {
20481                                                final long ix = it.aLong;
20482                                                float ox;
20483                                                ox = (float) (Math.acos(ix));
20484                                                oaf32data[it.oIndex] = ox;
20485                                        }
20486                                }
20487                        } else if (as == 1) {
20488                                if (it.isOutputDouble()) {
20489                                        while (it.hasNext()) {
20490                                                final double ix = it.aDouble;
20491                                                float ox;
20492                                                ox = (float) (Math.acos(ix));
20493                                                for (int j = 0; j < is; j++) {
20494                                                        oaf32data[it.oIndex + j] = ox;
20495                                                }
20496                                        }
20497                                } else {
20498                                        while (it.hasNext()) {
20499                                                final long ix = it.aLong;
20500                                                float ox;
20501                                                ox = (float) (Math.acos(ix));
20502                                                for (int j = 0; j < is; j++) {
20503                                                        oaf32data[it.oIndex + j] = ox;
20504                                                }
20505                                        }
20506                                }
20507                        } else {
20508                                if (it.isOutputDouble()) {
20509                                        while (it.hasNext()) {
20510                                                for (int j = 0; j < is; j++) {
20511                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20512                                                        float ox;
20513                                                        ox = (float) (Math.acos(ix));
20514                                                        oaf32data[it.oIndex + j] = ox;
20515                                                }
20516                                        }
20517                                } else {
20518                                        while (it.hasNext()) {
20519                                                for (int j = 0; j < is; j++) {
20520                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20521                                                        float ox;
20522                                                        ox = (float) (Math.acos(ix));
20523                                                        oaf32data[it.oIndex + j] = ox;
20524                                                }
20525                                        }
20526                                }
20527                        }
20528                        break;
20529                case Dataset.ARRAYFLOAT64:
20530                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
20531                        if (is == 1) {
20532                                if (it.isOutputDouble()) {
20533                                        while (it.hasNext()) {
20534                                                final double ix = it.aDouble;
20535                                                double ox;
20536                                                ox = (Math.acos(ix));
20537                                                oaf64data[it.oIndex] = ox;
20538                                        }
20539                                } else {
20540                                        while (it.hasNext()) {
20541                                                final long ix = it.aLong;
20542                                                double ox;
20543                                                ox = (Math.acos(ix));
20544                                                oaf64data[it.oIndex] = ox;
20545                                        }
20546                                }
20547                        } else if (as == 1) {
20548                                if (it.isOutputDouble()) {
20549                                        while (it.hasNext()) {
20550                                                final double ix = it.aDouble;
20551                                                double ox;
20552                                                ox = (Math.acos(ix));
20553                                                for (int j = 0; j < is; j++) {
20554                                                        oaf64data[it.oIndex + j] = ox;
20555                                                }
20556                                        }
20557                                } else {
20558                                        while (it.hasNext()) {
20559                                                final long ix = it.aLong;
20560                                                double ox;
20561                                                ox = (Math.acos(ix));
20562                                                for (int j = 0; j < is; j++) {
20563                                                        oaf64data[it.oIndex + j] = ox;
20564                                                }
20565                                        }
20566                                }
20567                        } else {
20568                                if (it.isOutputDouble()) {
20569                                        while (it.hasNext()) {
20570                                                for (int j = 0; j < is; j++) {
20571                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20572                                                        double ox;
20573                                                        ox = (Math.acos(ix));
20574                                                        oaf64data[it.oIndex + j] = ox;
20575                                                }
20576                                        }
20577                                } else {
20578                                        while (it.hasNext()) {
20579                                                for (int j = 0; j < is; j++) {
20580                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20581                                                        double ox;
20582                                                        ox = (Math.acos(ix));
20583                                                        oaf64data[it.oIndex + j] = ox;
20584                                                }
20585                                        }
20586                                }
20587                        }
20588                        break;
20589                case Dataset.COMPLEX64:
20590                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
20591                        if (!da.isComplex()) {
20592                                if (it.isOutputDouble()) {
20593                                        final double iy = 0;
20594                                        while (it.hasNext()) {
20595                                                final double ix = it.aDouble;
20596                                                Complex tz;
20597                                                float ox;
20598                                                float oy;
20599                                                tz = new Complex(ix, iy).acos();
20600                                                ox = (float) (tz.getReal());
20601                                                oy = (float) (tz.getImaginary());
20602                                                oc64data[it.oIndex] = ox;
20603                                                oc64data[it.oIndex + 1] = oy;
20604                                        }
20605                                } else {
20606                                        final long iy = 0;
20607                                        while (it.hasNext()) {
20608                                                final long ix = it.aLong;
20609                                                Complex tz;
20610                                                float ox;
20611                                                float oy;
20612                                                tz = new Complex(ix, iy).acos();
20613                                                ox = (float) toLong(tz.getReal());
20614                                                oy = (float) toLong(tz.getImaginary());
20615                                                oc64data[it.oIndex] = ox;
20616                                                oc64data[it.oIndex + 1] = oy;
20617                                        }
20618                                }
20619                        } else {
20620                                while (it.hasNext()) {
20621                                        final double ix = it.aDouble;
20622                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
20623                                        Complex tz;
20624                                        float ox;
20625                                        float oy;
20626                                        tz = new Complex(ix, iy).acos();
20627                                        ox = (float) (tz.getReal());
20628                                        oy = (float) (tz.getImaginary());
20629                                        oc64data[it.oIndex] = ox;
20630                                        oc64data[it.oIndex + 1] = oy;
20631                                }
20632                        }
20633                        break;
20634                case Dataset.COMPLEX128:
20635                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
20636                        if (!da.isComplex()) {
20637                                if (it.isOutputDouble()) {
20638                                        final double iy = 0;
20639                                        while (it.hasNext()) {
20640                                                final double ix = it.aDouble;
20641                                                Complex tz;
20642                                                double ox;
20643                                                double oy;
20644                                                tz = new Complex(ix, iy).acos();
20645                                                ox = (tz.getReal());
20646                                                oy = (tz.getImaginary());
20647                                                oc128data[it.oIndex] = ox;
20648                                                oc128data[it.oIndex + 1] = oy;
20649                                        }
20650                                } else {
20651                                        final long iy = 0;
20652                                        while (it.hasNext()) {
20653                                                final long ix = it.aLong;
20654                                                Complex tz;
20655                                                double ox;
20656                                                double oy;
20657                                                tz = new Complex(ix, iy).acos();
20658                                                ox = (tz.getReal());
20659                                                oy = (tz.getImaginary());
20660                                                oc128data[it.oIndex] = ox;
20661                                                oc128data[it.oIndex + 1] = oy;
20662                                        }
20663                                }
20664                        } else {
20665                                while (it.hasNext()) {
20666                                        final double ix = it.aDouble;
20667                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
20668                                        Complex tz;
20669                                        double ox;
20670                                        double oy;
20671                                        tz = new Complex(ix, iy).acos();
20672                                        ox = (tz.getReal());
20673                                        oy = (tz.getImaginary());
20674                                        oc128data[it.oIndex] = ox;
20675                                        oc128data[it.oIndex + 1] = oy;
20676                                }
20677                        }
20678                        break;
20679                default:
20680                        throw new IllegalArgumentException("arccos supports integer, compound integer, real, compound real, complex datasets only");
20681                }
20682
20683                addFunctionName(result, "arccos");
20684                return result;
20685        }
20686
20687        /**
20688         * arctan - evaluate the inverse tangent function on each element of the dataset
20689         * @param a
20690         * @return dataset
20691         */
20692        public static Dataset arctan(final Object a) {
20693                return arctan(a, null);
20694        }
20695
20696        /**
20697         * arctan - evaluate the inverse tangent function on each element of the dataset
20698         * @param a
20699         * @param o output can be null - in which case, a new dataset is created
20700         * @return dataset
20701         */
20702        public static Dataset arctan(final Object a, final Dataset o) {
20703                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
20704                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
20705                final Dataset result = it.getOutput();
20706                if (!result.isComplex()) {
20707                        if (da.isComplex()) {
20708                                da = da.getRealView();
20709                                it = new SingleInputBroadcastIterator(da, result, true);
20710                        }
20711                }
20712                final int is = result.getElementsPerItem();
20713                final int as = da.getElementsPerItem();
20714                final int dt = result.getDType();
20715
20716                switch(dt) {
20717                case Dataset.INT8:
20718                        final byte[] oi8data = ((ByteDataset) result).getData();
20719                        if (it.isOutputDouble()) {
20720                                while (it.hasNext()) {
20721                                        final double ix = it.aDouble;
20722                                        byte ox;
20723                                        ox = (byte) toLong(Math.atan(ix));
20724                                        oi8data[it.oIndex] = ox;
20725                                }
20726                        } else {
20727                                while (it.hasNext()) {
20728                                        final long ix = it.aLong;
20729                                        byte ox;
20730                                        ox = (byte) toLong(Math.atan(ix));
20731                                        oi8data[it.oIndex] = ox;
20732                                }
20733                        }
20734                        break;
20735                case Dataset.INT16:
20736                        final short[] oi16data = ((ShortDataset) result).getData();
20737                        if (it.isOutputDouble()) {
20738                                while (it.hasNext()) {
20739                                        final double ix = it.aDouble;
20740                                        short ox;
20741                                        ox = (short) toLong(Math.atan(ix));
20742                                        oi16data[it.oIndex] = ox;
20743                                }
20744                        } else {
20745                                while (it.hasNext()) {
20746                                        final long ix = it.aLong;
20747                                        short ox;
20748                                        ox = (short) toLong(Math.atan(ix));
20749                                        oi16data[it.oIndex] = ox;
20750                                }
20751                        }
20752                        break;
20753                case Dataset.INT64:
20754                        final long[] oi64data = ((LongDataset) result).getData();
20755                        if (it.isOutputDouble()) {
20756                                while (it.hasNext()) {
20757                                        final double ix = it.aDouble;
20758                                        long ox;
20759                                        ox = toLong(Math.atan(ix));
20760                                        oi64data[it.oIndex] = ox;
20761                                }
20762                        } else {
20763                                while (it.hasNext()) {
20764                                        final long ix = it.aLong;
20765                                        long ox;
20766                                        ox = toLong(Math.atan(ix));
20767                                        oi64data[it.oIndex] = ox;
20768                                }
20769                        }
20770                        break;
20771                case Dataset.INT32:
20772                        final int[] oi32data = ((IntegerDataset) result).getData();
20773                        if (it.isOutputDouble()) {
20774                                while (it.hasNext()) {
20775                                        final double ix = it.aDouble;
20776                                        int ox;
20777                                        ox = (int) toLong(Math.atan(ix));
20778                                        oi32data[it.oIndex] = ox;
20779                                }
20780                        } else {
20781                                while (it.hasNext()) {
20782                                        final long ix = it.aLong;
20783                                        int ox;
20784                                        ox = (int) toLong(Math.atan(ix));
20785                                        oi32data[it.oIndex] = ox;
20786                                }
20787                        }
20788                        break;
20789                case Dataset.ARRAYINT8:
20790                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
20791                        if (is == 1) {
20792                                if (it.isOutputDouble()) {
20793                                        while (it.hasNext()) {
20794                                                final double ix = it.aDouble;
20795                                                byte ox;
20796                                                ox = (byte) toLong(Math.atan(ix));
20797                                                oai8data[it.oIndex] = ox;
20798                                        }
20799                                } else {
20800                                        while (it.hasNext()) {
20801                                                final long ix = it.aLong;
20802                                                byte ox;
20803                                                ox = (byte) toLong(Math.atan(ix));
20804                                                oai8data[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                                                byte ox;
20812                                                ox = (byte) toLong(Math.atan(ix));
20813                                                for (int j = 0; j < is; j++) {
20814                                                        oai8data[it.oIndex + j] = ox;
20815                                                }
20816                                        }
20817                                } else {
20818                                        while (it.hasNext()) {
20819                                                final long ix = it.aLong;
20820                                                byte ox;
20821                                                ox = (byte) toLong(Math.atan(ix));
20822                                                for (int j = 0; j < is; j++) {
20823                                                        oai8data[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                                                        byte ox;
20833                                                        ox = (byte) toLong(Math.atan(ix));
20834                                                        oai8data[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                                                        byte ox;
20842                                                        ox = (byte) toLong(Math.atan(ix));
20843                                                        oai8data[it.oIndex + j] = ox;
20844                                                }
20845                                        }
20846                                }
20847                        }
20848                        break;
20849                case Dataset.ARRAYINT16:
20850                        final short[] oai16data = ((CompoundShortDataset) result).getData();
20851                        if (is == 1) {
20852                                if (it.isOutputDouble()) {
20853                                        while (it.hasNext()) {
20854                                                final double ix = it.aDouble;
20855                                                short ox;
20856                                                ox = (short) toLong(Math.atan(ix));
20857                                                oai16data[it.oIndex] = ox;
20858                                        }
20859                                } else {
20860                                        while (it.hasNext()) {
20861                                                final long ix = it.aLong;
20862                                                short ox;
20863                                                ox = (short) toLong(Math.atan(ix));
20864                                                oai16data[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                                                short ox;
20872                                                ox = (short) toLong(Math.atan(ix));
20873                                                for (int j = 0; j < is; j++) {
20874                                                        oai16data[it.oIndex + j] = ox;
20875                                                }
20876                                        }
20877                                } else {
20878                                        while (it.hasNext()) {
20879                                                final long ix = it.aLong;
20880                                                short ox;
20881                                                ox = (short) toLong(Math.atan(ix));
20882                                                for (int j = 0; j < is; j++) {
20883                                                        oai16data[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                                                        short ox;
20893                                                        ox = (short) toLong(Math.atan(ix));
20894                                                        oai16data[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                                                        short ox;
20902                                                        ox = (short) toLong(Math.atan(ix));
20903                                                        oai16data[it.oIndex + j] = ox;
20904                                                }
20905                                        }
20906                                }
20907                        }
20908                        break;
20909                case Dataset.ARRAYINT64:
20910                        final long[] oai64data = ((CompoundLongDataset) result).getData();
20911                        if (is == 1) {
20912                                if (it.isOutputDouble()) {
20913                                        while (it.hasNext()) {
20914                                                final double ix = it.aDouble;
20915                                                long ox;
20916                                                ox = toLong(Math.atan(ix));
20917                                                oai64data[it.oIndex] = ox;
20918                                        }
20919                                } else {
20920                                        while (it.hasNext()) {
20921                                                final long ix = it.aLong;
20922                                                long ox;
20923                                                ox = toLong(Math.atan(ix));
20924                                                oai64data[it.oIndex] = ox;
20925                                        }
20926                                }
20927                        } else if (as == 1) {
20928                                if (it.isOutputDouble()) {
20929                                        while (it.hasNext()) {
20930                                                final double ix = it.aDouble;
20931                                                long ox;
20932                                                ox = toLong(Math.atan(ix));
20933                                                for (int j = 0; j < is; j++) {
20934                                                        oai64data[it.oIndex + j] = ox;
20935                                                }
20936                                        }
20937                                } else {
20938                                        while (it.hasNext()) {
20939                                                final long ix = it.aLong;
20940                                                long ox;
20941                                                ox = toLong(Math.atan(ix));
20942                                                for (int j = 0; j < is; j++) {
20943                                                        oai64data[it.oIndex + j] = ox;
20944                                                }
20945                                        }
20946                                }
20947                        } else {
20948                                if (it.isOutputDouble()) {
20949                                        while (it.hasNext()) {
20950                                                for (int j = 0; j < is; j++) {
20951                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20952                                                        long ox;
20953                                                        ox = toLong(Math.atan(ix));
20954                                                        oai64data[it.oIndex + j] = ox;
20955                                                }
20956                                        }
20957                                } else {
20958                                        while (it.hasNext()) {
20959                                                for (int j = 0; j < is; j++) {
20960                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20961                                                        long ox;
20962                                                        ox = toLong(Math.atan(ix));
20963                                                        oai64data[it.oIndex + j] = ox;
20964                                                }
20965                                        }
20966                                }
20967                        }
20968                        break;
20969                case Dataset.ARRAYINT32:
20970                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
20971                        if (is == 1) {
20972                                if (it.isOutputDouble()) {
20973                                        while (it.hasNext()) {
20974                                                final double ix = it.aDouble;
20975                                                int ox;
20976                                                ox = (int) toLong(Math.atan(ix));
20977                                                oai32data[it.oIndex] = ox;
20978                                        }
20979                                } else {
20980                                        while (it.hasNext()) {
20981                                                final long ix = it.aLong;
20982                                                int ox;
20983                                                ox = (int) toLong(Math.atan(ix));
20984                                                oai32data[it.oIndex] = ox;
20985                                        }
20986                                }
20987                        } else if (as == 1) {
20988                                if (it.isOutputDouble()) {
20989                                        while (it.hasNext()) {
20990                                                final double ix = it.aDouble;
20991                                                int ox;
20992                                                ox = (int) toLong(Math.atan(ix));
20993                                                for (int j = 0; j < is; j++) {
20994                                                        oai32data[it.oIndex + j] = ox;
20995                                                }
20996                                        }
20997                                } else {
20998                                        while (it.hasNext()) {
20999                                                final long ix = it.aLong;
21000                                                int ox;
21001                                                ox = (int) toLong(Math.atan(ix));
21002                                                for (int j = 0; j < is; j++) {
21003                                                        oai32data[it.oIndex + j] = ox;
21004                                                }
21005                                        }
21006                                }
21007                        } else {
21008                                if (it.isOutputDouble()) {
21009                                        while (it.hasNext()) {
21010                                                for (int j = 0; j < is; j++) {
21011                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21012                                                        int ox;
21013                                                        ox = (int) toLong(Math.atan(ix));
21014                                                        oai32data[it.oIndex + j] = ox;
21015                                                }
21016                                        }
21017                                } else {
21018                                        while (it.hasNext()) {
21019                                                for (int j = 0; j < is; j++) {
21020                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21021                                                        int ox;
21022                                                        ox = (int) toLong(Math.atan(ix));
21023                                                        oai32data[it.oIndex + j] = ox;
21024                                                }
21025                                        }
21026                                }
21027                        }
21028                        break;
21029                case Dataset.FLOAT32:
21030                        final float[] of32data = ((FloatDataset) result).getData();
21031                        if (it.isOutputDouble()) {
21032                                while (it.hasNext()) {
21033                                        final double ix = it.aDouble;
21034                                        float ox;
21035                                        ox = (float) (Math.atan(ix));
21036                                        of32data[it.oIndex] = ox;
21037                                }
21038                        } else {
21039                                while (it.hasNext()) {
21040                                        final long ix = it.aLong;
21041                                        float ox;
21042                                        ox = (float) (Math.atan(ix));
21043                                        of32data[it.oIndex] = ox;
21044                                }
21045                        }
21046                        break;
21047                case Dataset.FLOAT64:
21048                        final double[] of64data = ((DoubleDataset) result).getData();
21049                        if (it.isOutputDouble()) {
21050                                while (it.hasNext()) {
21051                                        final double ix = it.aDouble;
21052                                        double ox;
21053                                        ox = (Math.atan(ix));
21054                                        of64data[it.oIndex] = ox;
21055                                }
21056                        } else {
21057                                while (it.hasNext()) {
21058                                        final long ix = it.aLong;
21059                                        double ox;
21060                                        ox = (Math.atan(ix));
21061                                        of64data[it.oIndex] = ox;
21062                                }
21063                        }
21064                        break;
21065                case Dataset.ARRAYFLOAT32:
21066                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
21067                        if (is == 1) {
21068                                if (it.isOutputDouble()) {
21069                                        while (it.hasNext()) {
21070                                                final double ix = it.aDouble;
21071                                                float ox;
21072                                                ox = (float) (Math.atan(ix));
21073                                                oaf32data[it.oIndex] = ox;
21074                                        }
21075                                } else {
21076                                        while (it.hasNext()) {
21077                                                final long ix = it.aLong;
21078                                                float ox;
21079                                                ox = (float) (Math.atan(ix));
21080                                                oaf32data[it.oIndex] = ox;
21081                                        }
21082                                }
21083                        } else if (as == 1) {
21084                                if (it.isOutputDouble()) {
21085                                        while (it.hasNext()) {
21086                                                final double ix = it.aDouble;
21087                                                float ox;
21088                                                ox = (float) (Math.atan(ix));
21089                                                for (int j = 0; j < is; j++) {
21090                                                        oaf32data[it.oIndex + j] = ox;
21091                                                }
21092                                        }
21093                                } else {
21094                                        while (it.hasNext()) {
21095                                                final long ix = it.aLong;
21096                                                float ox;
21097                                                ox = (float) (Math.atan(ix));
21098                                                for (int j = 0; j < is; j++) {
21099                                                        oaf32data[it.oIndex + j] = ox;
21100                                                }
21101                                        }
21102                                }
21103                        } else {
21104                                if (it.isOutputDouble()) {
21105                                        while (it.hasNext()) {
21106                                                for (int j = 0; j < is; j++) {
21107                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21108                                                        float ox;
21109                                                        ox = (float) (Math.atan(ix));
21110                                                        oaf32data[it.oIndex + j] = ox;
21111                                                }
21112                                        }
21113                                } else {
21114                                        while (it.hasNext()) {
21115                                                for (int j = 0; j < is; j++) {
21116                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21117                                                        float ox;
21118                                                        ox = (float) (Math.atan(ix));
21119                                                        oaf32data[it.oIndex + j] = ox;
21120                                                }
21121                                        }
21122                                }
21123                        }
21124                        break;
21125                case Dataset.ARRAYFLOAT64:
21126                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
21127                        if (is == 1) {
21128                                if (it.isOutputDouble()) {
21129                                        while (it.hasNext()) {
21130                                                final double ix = it.aDouble;
21131                                                double ox;
21132                                                ox = (Math.atan(ix));
21133                                                oaf64data[it.oIndex] = ox;
21134                                        }
21135                                } else {
21136                                        while (it.hasNext()) {
21137                                                final long ix = it.aLong;
21138                                                double ox;
21139                                                ox = (Math.atan(ix));
21140                                                oaf64data[it.oIndex] = ox;
21141                                        }
21142                                }
21143                        } else if (as == 1) {
21144                                if (it.isOutputDouble()) {
21145                                        while (it.hasNext()) {
21146                                                final double ix = it.aDouble;
21147                                                double ox;
21148                                                ox = (Math.atan(ix));
21149                                                for (int j = 0; j < is; j++) {
21150                                                        oaf64data[it.oIndex + j] = ox;
21151                                                }
21152                                        }
21153                                } else {
21154                                        while (it.hasNext()) {
21155                                                final long ix = it.aLong;
21156                                                double ox;
21157                                                ox = (Math.atan(ix));
21158                                                for (int j = 0; j < is; j++) {
21159                                                        oaf64data[it.oIndex + j] = ox;
21160                                                }
21161                                        }
21162                                }
21163                        } else {
21164                                if (it.isOutputDouble()) {
21165                                        while (it.hasNext()) {
21166                                                for (int j = 0; j < is; j++) {
21167                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21168                                                        double ox;
21169                                                        ox = (Math.atan(ix));
21170                                                        oaf64data[it.oIndex + j] = ox;
21171                                                }
21172                                        }
21173                                } else {
21174                                        while (it.hasNext()) {
21175                                                for (int j = 0; j < is; j++) {
21176                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21177                                                        double ox;
21178                                                        ox = (Math.atan(ix));
21179                                                        oaf64data[it.oIndex + j] = ox;
21180                                                }
21181                                        }
21182                                }
21183                        }
21184                        break;
21185                case Dataset.COMPLEX64:
21186                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
21187                        if (!da.isComplex()) {
21188                                if (it.isOutputDouble()) {
21189                                        final double iy = 0;
21190                                        while (it.hasNext()) {
21191                                                final double ix = it.aDouble;
21192                                                Complex tz;
21193                                                float ox;
21194                                                float oy;
21195                                                tz = new Complex(ix, iy).atan();
21196                                                ox = (float) (tz.getReal());
21197                                                oy = (float) (tz.getImaginary());
21198                                                oc64data[it.oIndex] = ox;
21199                                                oc64data[it.oIndex + 1] = oy;
21200                                        }
21201                                } else {
21202                                        final long iy = 0;
21203                                        while (it.hasNext()) {
21204                                                final long ix = it.aLong;
21205                                                Complex tz;
21206                                                float ox;
21207                                                float oy;
21208                                                tz = new Complex(ix, iy).atan();
21209                                                ox = (float) toLong(tz.getReal());
21210                                                oy = (float) toLong(tz.getImaginary());
21211                                                oc64data[it.oIndex] = ox;
21212                                                oc64data[it.oIndex + 1] = oy;
21213                                        }
21214                                }
21215                        } else {
21216                                while (it.hasNext()) {
21217                                        final double ix = it.aDouble;
21218                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
21219                                        Complex tz;
21220                                        float ox;
21221                                        float oy;
21222                                        tz = new Complex(ix, iy).atan();
21223                                        ox = (float) (tz.getReal());
21224                                        oy = (float) (tz.getImaginary());
21225                                        oc64data[it.oIndex] = ox;
21226                                        oc64data[it.oIndex + 1] = oy;
21227                                }
21228                        }
21229                        break;
21230                case Dataset.COMPLEX128:
21231                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
21232                        if (!da.isComplex()) {
21233                                if (it.isOutputDouble()) {
21234                                        final double iy = 0;
21235                                        while (it.hasNext()) {
21236                                                final double ix = it.aDouble;
21237                                                Complex tz;
21238                                                double ox;
21239                                                double oy;
21240                                                tz = new Complex(ix, iy).atan();
21241                                                ox = (tz.getReal());
21242                                                oy = (tz.getImaginary());
21243                                                oc128data[it.oIndex] = ox;
21244                                                oc128data[it.oIndex + 1] = oy;
21245                                        }
21246                                } else {
21247                                        final long iy = 0;
21248                                        while (it.hasNext()) {
21249                                                final long ix = it.aLong;
21250                                                Complex tz;
21251                                                double ox;
21252                                                double oy;
21253                                                tz = new Complex(ix, iy).atan();
21254                                                ox = (tz.getReal());
21255                                                oy = (tz.getImaginary());
21256                                                oc128data[it.oIndex] = ox;
21257                                                oc128data[it.oIndex + 1] = oy;
21258                                        }
21259                                }
21260                        } else {
21261                                while (it.hasNext()) {
21262                                        final double ix = it.aDouble;
21263                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
21264                                        Complex tz;
21265                                        double ox;
21266                                        double oy;
21267                                        tz = new Complex(ix, iy).atan();
21268                                        ox = (tz.getReal());
21269                                        oy = (tz.getImaginary());
21270                                        oc128data[it.oIndex] = ox;
21271                                        oc128data[it.oIndex + 1] = oy;
21272                                }
21273                        }
21274                        break;
21275                default:
21276                        throw new IllegalArgumentException("arctan supports integer, compound integer, real, compound real, complex datasets only");
21277                }
21278
21279                addFunctionName(result, "arctan");
21280                return result;
21281        }
21282
21283        /**
21284         * sinh - evaluate the hyperbolic sine function on each element of the dataset
21285         * @param a
21286         * @return dataset
21287         */
21288        public static Dataset sinh(final Object a) {
21289                return sinh(a, null);
21290        }
21291
21292        /**
21293         * sinh - evaluate the hyperbolic sine function on each element of the dataset
21294         * @param a
21295         * @param o output can be null - in which case, a new dataset is created
21296         * @return dataset
21297         */
21298        public static Dataset sinh(final Object a, final Dataset o) {
21299                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
21300                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
21301                final Dataset result = it.getOutput();
21302                if (!result.isComplex()) {
21303                        if (da.isComplex()) {
21304                                da = da.getRealView();
21305                                it = new SingleInputBroadcastIterator(da, result, true);
21306                        }
21307                }
21308                final int is = result.getElementsPerItem();
21309                final int as = da.getElementsPerItem();
21310                final int dt = result.getDType();
21311
21312                switch(dt) {
21313                case Dataset.INT8:
21314                        final byte[] oi8data = ((ByteDataset) result).getData();
21315                        if (it.isOutputDouble()) {
21316                                while (it.hasNext()) {
21317                                        final double ix = it.aDouble;
21318                                        byte ox;
21319                                        ox = (byte) toLong(Math.sinh(ix));
21320                                        oi8data[it.oIndex] = ox;
21321                                }
21322                        } else {
21323                                while (it.hasNext()) {
21324                                        final long ix = it.aLong;
21325                                        byte ox;
21326                                        ox = (byte) toLong(Math.sinh(ix));
21327                                        oi8data[it.oIndex] = ox;
21328                                }
21329                        }
21330                        break;
21331                case Dataset.INT16:
21332                        final short[] oi16data = ((ShortDataset) result).getData();
21333                        if (it.isOutputDouble()) {
21334                                while (it.hasNext()) {
21335                                        final double ix = it.aDouble;
21336                                        short ox;
21337                                        ox = (short) toLong(Math.sinh(ix));
21338                                        oi16data[it.oIndex] = ox;
21339                                }
21340                        } else {
21341                                while (it.hasNext()) {
21342                                        final long ix = it.aLong;
21343                                        short ox;
21344                                        ox = (short) toLong(Math.sinh(ix));
21345                                        oi16data[it.oIndex] = ox;
21346                                }
21347                        }
21348                        break;
21349                case Dataset.INT64:
21350                        final long[] oi64data = ((LongDataset) result).getData();
21351                        if (it.isOutputDouble()) {
21352                                while (it.hasNext()) {
21353                                        final double ix = it.aDouble;
21354                                        long ox;
21355                                        ox = toLong(Math.sinh(ix));
21356                                        oi64data[it.oIndex] = ox;
21357                                }
21358                        } else {
21359                                while (it.hasNext()) {
21360                                        final long ix = it.aLong;
21361                                        long ox;
21362                                        ox = toLong(Math.sinh(ix));
21363                                        oi64data[it.oIndex] = ox;
21364                                }
21365                        }
21366                        break;
21367                case Dataset.INT32:
21368                        final int[] oi32data = ((IntegerDataset) result).getData();
21369                        if (it.isOutputDouble()) {
21370                                while (it.hasNext()) {
21371                                        final double ix = it.aDouble;
21372                                        int ox;
21373                                        ox = (int) toLong(Math.sinh(ix));
21374                                        oi32data[it.oIndex] = ox;
21375                                }
21376                        } else {
21377                                while (it.hasNext()) {
21378                                        final long ix = it.aLong;
21379                                        int ox;
21380                                        ox = (int) toLong(Math.sinh(ix));
21381                                        oi32data[it.oIndex] = ox;
21382                                }
21383                        }
21384                        break;
21385                case Dataset.ARRAYINT8:
21386                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
21387                        if (is == 1) {
21388                                if (it.isOutputDouble()) {
21389                                        while (it.hasNext()) {
21390                                                final double ix = it.aDouble;
21391                                                byte ox;
21392                                                ox = (byte) toLong(Math.sinh(ix));
21393                                                oai8data[it.oIndex] = ox;
21394                                        }
21395                                } else {
21396                                        while (it.hasNext()) {
21397                                                final long ix = it.aLong;
21398                                                byte ox;
21399                                                ox = (byte) toLong(Math.sinh(ix));
21400                                                oai8data[it.oIndex] = ox;
21401                                        }
21402                                }
21403                        } else if (as == 1) {
21404                                if (it.isOutputDouble()) {
21405                                        while (it.hasNext()) {
21406                                                final double ix = it.aDouble;
21407                                                byte ox;
21408                                                ox = (byte) toLong(Math.sinh(ix));
21409                                                for (int j = 0; j < is; j++) {
21410                                                        oai8data[it.oIndex + j] = ox;
21411                                                }
21412                                        }
21413                                } else {
21414                                        while (it.hasNext()) {
21415                                                final long ix = it.aLong;
21416                                                byte ox;
21417                                                ox = (byte) toLong(Math.sinh(ix));
21418                                                for (int j = 0; j < is; j++) {
21419                                                        oai8data[it.oIndex + j] = ox;
21420                                                }
21421                                        }
21422                                }
21423                        } else {
21424                                if (it.isOutputDouble()) {
21425                                        while (it.hasNext()) {
21426                                                for (int j = 0; j < is; j++) {
21427                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21428                                                        byte ox;
21429                                                        ox = (byte) toLong(Math.sinh(ix));
21430                                                        oai8data[it.oIndex + j] = ox;
21431                                                }
21432                                        }
21433                                } else {
21434                                        while (it.hasNext()) {
21435                                                for (int j = 0; j < is; j++) {
21436                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21437                                                        byte ox;
21438                                                        ox = (byte) toLong(Math.sinh(ix));
21439                                                        oai8data[it.oIndex + j] = ox;
21440                                                }
21441                                        }
21442                                }
21443                        }
21444                        break;
21445                case Dataset.ARRAYINT16:
21446                        final short[] oai16data = ((CompoundShortDataset) result).getData();
21447                        if (is == 1) {
21448                                if (it.isOutputDouble()) {
21449                                        while (it.hasNext()) {
21450                                                final double ix = it.aDouble;
21451                                                short ox;
21452                                                ox = (short) toLong(Math.sinh(ix));
21453                                                oai16data[it.oIndex] = ox;
21454                                        }
21455                                } else {
21456                                        while (it.hasNext()) {
21457                                                final long ix = it.aLong;
21458                                                short ox;
21459                                                ox = (short) toLong(Math.sinh(ix));
21460                                                oai16data[it.oIndex] = ox;
21461                                        }
21462                                }
21463                        } else if (as == 1) {
21464                                if (it.isOutputDouble()) {
21465                                        while (it.hasNext()) {
21466                                                final double ix = it.aDouble;
21467                                                short ox;
21468                                                ox = (short) toLong(Math.sinh(ix));
21469                                                for (int j = 0; j < is; j++) {
21470                                                        oai16data[it.oIndex + j] = ox;
21471                                                }
21472                                        }
21473                                } else {
21474                                        while (it.hasNext()) {
21475                                                final long ix = it.aLong;
21476                                                short ox;
21477                                                ox = (short) toLong(Math.sinh(ix));
21478                                                for (int j = 0; j < is; j++) {
21479                                                        oai16data[it.oIndex + j] = ox;
21480                                                }
21481                                        }
21482                                }
21483                        } else {
21484                                if (it.isOutputDouble()) {
21485                                        while (it.hasNext()) {
21486                                                for (int j = 0; j < is; j++) {
21487                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21488                                                        short ox;
21489                                                        ox = (short) toLong(Math.sinh(ix));
21490                                                        oai16data[it.oIndex + j] = ox;
21491                                                }
21492                                        }
21493                                } else {
21494                                        while (it.hasNext()) {
21495                                                for (int j = 0; j < is; j++) {
21496                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21497                                                        short ox;
21498                                                        ox = (short) toLong(Math.sinh(ix));
21499                                                        oai16data[it.oIndex + j] = ox;
21500                                                }
21501                                        }
21502                                }
21503                        }
21504                        break;
21505                case Dataset.ARRAYINT64:
21506                        final long[] oai64data = ((CompoundLongDataset) result).getData();
21507                        if (is == 1) {
21508                                if (it.isOutputDouble()) {
21509                                        while (it.hasNext()) {
21510                                                final double ix = it.aDouble;
21511                                                long ox;
21512                                                ox = toLong(Math.sinh(ix));
21513                                                oai64data[it.oIndex] = ox;
21514                                        }
21515                                } else {
21516                                        while (it.hasNext()) {
21517                                                final long ix = it.aLong;
21518                                                long ox;
21519                                                ox = toLong(Math.sinh(ix));
21520                                                oai64data[it.oIndex] = ox;
21521                                        }
21522                                }
21523                        } else if (as == 1) {
21524                                if (it.isOutputDouble()) {
21525                                        while (it.hasNext()) {
21526                                                final double ix = it.aDouble;
21527                                                long ox;
21528                                                ox = toLong(Math.sinh(ix));
21529                                                for (int j = 0; j < is; j++) {
21530                                                        oai64data[it.oIndex + j] = ox;
21531                                                }
21532                                        }
21533                                } else {
21534                                        while (it.hasNext()) {
21535                                                final long ix = it.aLong;
21536                                                long ox;
21537                                                ox = toLong(Math.sinh(ix));
21538                                                for (int j = 0; j < is; j++) {
21539                                                        oai64data[it.oIndex + j] = ox;
21540                                                }
21541                                        }
21542                                }
21543                        } else {
21544                                if (it.isOutputDouble()) {
21545                                        while (it.hasNext()) {
21546                                                for (int j = 0; j < is; j++) {
21547                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21548                                                        long ox;
21549                                                        ox = toLong(Math.sinh(ix));
21550                                                        oai64data[it.oIndex + j] = ox;
21551                                                }
21552                                        }
21553                                } else {
21554                                        while (it.hasNext()) {
21555                                                for (int j = 0; j < is; j++) {
21556                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21557                                                        long ox;
21558                                                        ox = toLong(Math.sinh(ix));
21559                                                        oai64data[it.oIndex + j] = ox;
21560                                                }
21561                                        }
21562                                }
21563                        }
21564                        break;
21565                case Dataset.ARRAYINT32:
21566                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
21567                        if (is == 1) {
21568                                if (it.isOutputDouble()) {
21569                                        while (it.hasNext()) {
21570                                                final double ix = it.aDouble;
21571                                                int ox;
21572                                                ox = (int) toLong(Math.sinh(ix));
21573                                                oai32data[it.oIndex] = ox;
21574                                        }
21575                                } else {
21576                                        while (it.hasNext()) {
21577                                                final long ix = it.aLong;
21578                                                int ox;
21579                                                ox = (int) toLong(Math.sinh(ix));
21580                                                oai32data[it.oIndex] = ox;
21581                                        }
21582                                }
21583                        } else if (as == 1) {
21584                                if (it.isOutputDouble()) {
21585                                        while (it.hasNext()) {
21586                                                final double ix = it.aDouble;
21587                                                int ox;
21588                                                ox = (int) toLong(Math.sinh(ix));
21589                                                for (int j = 0; j < is; j++) {
21590                                                        oai32data[it.oIndex + j] = ox;
21591                                                }
21592                                        }
21593                                } else {
21594                                        while (it.hasNext()) {
21595                                                final long ix = it.aLong;
21596                                                int ox;
21597                                                ox = (int) toLong(Math.sinh(ix));
21598                                                for (int j = 0; j < is; j++) {
21599                                                        oai32data[it.oIndex + j] = ox;
21600                                                }
21601                                        }
21602                                }
21603                        } else {
21604                                if (it.isOutputDouble()) {
21605                                        while (it.hasNext()) {
21606                                                for (int j = 0; j < is; j++) {
21607                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21608                                                        int ox;
21609                                                        ox = (int) toLong(Math.sinh(ix));
21610                                                        oai32data[it.oIndex + j] = ox;
21611                                                }
21612                                        }
21613                                } else {
21614                                        while (it.hasNext()) {
21615                                                for (int j = 0; j < is; j++) {
21616                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21617                                                        int ox;
21618                                                        ox = (int) toLong(Math.sinh(ix));
21619                                                        oai32data[it.oIndex + j] = ox;
21620                                                }
21621                                        }
21622                                }
21623                        }
21624                        break;
21625                case Dataset.FLOAT32:
21626                        final float[] of32data = ((FloatDataset) result).getData();
21627                        if (it.isOutputDouble()) {
21628                                while (it.hasNext()) {
21629                                        final double ix = it.aDouble;
21630                                        float ox;
21631                                        ox = (float) (Math.sinh(ix));
21632                                        of32data[it.oIndex] = ox;
21633                                }
21634                        } else {
21635                                while (it.hasNext()) {
21636                                        final long ix = it.aLong;
21637                                        float ox;
21638                                        ox = (float) (Math.sinh(ix));
21639                                        of32data[it.oIndex] = ox;
21640                                }
21641                        }
21642                        break;
21643                case Dataset.FLOAT64:
21644                        final double[] of64data = ((DoubleDataset) result).getData();
21645                        if (it.isOutputDouble()) {
21646                                while (it.hasNext()) {
21647                                        final double ix = it.aDouble;
21648                                        double ox;
21649                                        ox = (Math.sinh(ix));
21650                                        of64data[it.oIndex] = ox;
21651                                }
21652                        } else {
21653                                while (it.hasNext()) {
21654                                        final long ix = it.aLong;
21655                                        double ox;
21656                                        ox = (Math.sinh(ix));
21657                                        of64data[it.oIndex] = ox;
21658                                }
21659                        }
21660                        break;
21661                case Dataset.ARRAYFLOAT32:
21662                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
21663                        if (is == 1) {
21664                                if (it.isOutputDouble()) {
21665                                        while (it.hasNext()) {
21666                                                final double ix = it.aDouble;
21667                                                float ox;
21668                                                ox = (float) (Math.sinh(ix));
21669                                                oaf32data[it.oIndex] = ox;
21670                                        }
21671                                } else {
21672                                        while (it.hasNext()) {
21673                                                final long ix = it.aLong;
21674                                                float ox;
21675                                                ox = (float) (Math.sinh(ix));
21676                                                oaf32data[it.oIndex] = ox;
21677                                        }
21678                                }
21679                        } else if (as == 1) {
21680                                if (it.isOutputDouble()) {
21681                                        while (it.hasNext()) {
21682                                                final double ix = it.aDouble;
21683                                                float ox;
21684                                                ox = (float) (Math.sinh(ix));
21685                                                for (int j = 0; j < is; j++) {
21686                                                        oaf32data[it.oIndex + j] = ox;
21687                                                }
21688                                        }
21689                                } else {
21690                                        while (it.hasNext()) {
21691                                                final long ix = it.aLong;
21692                                                float ox;
21693                                                ox = (float) (Math.sinh(ix));
21694                                                for (int j = 0; j < is; j++) {
21695                                                        oaf32data[it.oIndex + j] = ox;
21696                                                }
21697                                        }
21698                                }
21699                        } else {
21700                                if (it.isOutputDouble()) {
21701                                        while (it.hasNext()) {
21702                                                for (int j = 0; j < is; j++) {
21703                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21704                                                        float ox;
21705                                                        ox = (float) (Math.sinh(ix));
21706                                                        oaf32data[it.oIndex + j] = ox;
21707                                                }
21708                                        }
21709                                } else {
21710                                        while (it.hasNext()) {
21711                                                for (int j = 0; j < is; j++) {
21712                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21713                                                        float ox;
21714                                                        ox = (float) (Math.sinh(ix));
21715                                                        oaf32data[it.oIndex + j] = ox;
21716                                                }
21717                                        }
21718                                }
21719                        }
21720                        break;
21721                case Dataset.ARRAYFLOAT64:
21722                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
21723                        if (is == 1) {
21724                                if (it.isOutputDouble()) {
21725                                        while (it.hasNext()) {
21726                                                final double ix = it.aDouble;
21727                                                double ox;
21728                                                ox = (Math.sinh(ix));
21729                                                oaf64data[it.oIndex] = ox;
21730                                        }
21731                                } else {
21732                                        while (it.hasNext()) {
21733                                                final long ix = it.aLong;
21734                                                double ox;
21735                                                ox = (Math.sinh(ix));
21736                                                oaf64data[it.oIndex] = ox;
21737                                        }
21738                                }
21739                        } else if (as == 1) {
21740                                if (it.isOutputDouble()) {
21741                                        while (it.hasNext()) {
21742                                                final double ix = it.aDouble;
21743                                                double ox;
21744                                                ox = (Math.sinh(ix));
21745                                                for (int j = 0; j < is; j++) {
21746                                                        oaf64data[it.oIndex + j] = ox;
21747                                                }
21748                                        }
21749                                } else {
21750                                        while (it.hasNext()) {
21751                                                final long ix = it.aLong;
21752                                                double ox;
21753                                                ox = (Math.sinh(ix));
21754                                                for (int j = 0; j < is; j++) {
21755                                                        oaf64data[it.oIndex + j] = ox;
21756                                                }
21757                                        }
21758                                }
21759                        } else {
21760                                if (it.isOutputDouble()) {
21761                                        while (it.hasNext()) {
21762                                                for (int j = 0; j < is; j++) {
21763                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21764                                                        double ox;
21765                                                        ox = (Math.sinh(ix));
21766                                                        oaf64data[it.oIndex + j] = ox;
21767                                                }
21768                                        }
21769                                } else {
21770                                        while (it.hasNext()) {
21771                                                for (int j = 0; j < is; j++) {
21772                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21773                                                        double ox;
21774                                                        ox = (Math.sinh(ix));
21775                                                        oaf64data[it.oIndex + j] = ox;
21776                                                }
21777                                        }
21778                                }
21779                        }
21780                        break;
21781                case Dataset.COMPLEX64:
21782                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
21783                        if (!da.isComplex()) {
21784                                if (it.isOutputDouble()) {
21785                                        final double iy = 0;
21786                                        while (it.hasNext()) {
21787                                                final double ix = it.aDouble;
21788                                                float ox;
21789                                                float oy;
21790                                                ox = (float) (Math.sinh(ix)*Math.cos(iy));
21791                                                oy = (float) (Math.cosh(ix)*Math.sin(iy));
21792                                                oc64data[it.oIndex] = ox;
21793                                                oc64data[it.oIndex + 1] = oy;
21794                                        }
21795                                } else {
21796                                        final long iy = 0;
21797                                        while (it.hasNext()) {
21798                                                final long ix = it.aLong;
21799                                                float ox;
21800                                                float oy;
21801                                                ox = (float) toLong(Math.sinh(ix)*Math.cos(iy));
21802                                                oy = (float) toLong(Math.cosh(ix)*Math.sin(iy));
21803                                                oc64data[it.oIndex] = ox;
21804                                                oc64data[it.oIndex + 1] = oy;
21805                                        }
21806                                }
21807                        } else {
21808                                while (it.hasNext()) {
21809                                        final double ix = it.aDouble;
21810                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
21811                                        float ox;
21812                                        float oy;
21813                                        ox = (float) (Math.sinh(ix)*Math.cos(iy));
21814                                        oy = (float) (Math.cosh(ix)*Math.sin(iy));
21815                                        oc64data[it.oIndex] = ox;
21816                                        oc64data[it.oIndex + 1] = oy;
21817                                }
21818                        }
21819                        break;
21820                case Dataset.COMPLEX128:
21821                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
21822                        if (!da.isComplex()) {
21823                                if (it.isOutputDouble()) {
21824                                        final double iy = 0;
21825                                        while (it.hasNext()) {
21826                                                final double ix = it.aDouble;
21827                                                double ox;
21828                                                double oy;
21829                                                ox = (Math.sinh(ix)*Math.cos(iy));
21830                                                oy = (Math.cosh(ix)*Math.sin(iy));
21831                                                oc128data[it.oIndex] = ox;
21832                                                oc128data[it.oIndex + 1] = oy;
21833                                        }
21834                                } else {
21835                                        final long iy = 0;
21836                                        while (it.hasNext()) {
21837                                                final long ix = it.aLong;
21838                                                double ox;
21839                                                double oy;
21840                                                ox = (double) (Math.sinh(ix)*Math.cos(iy));
21841                                                oy = (double) (Math.cosh(ix)*Math.sin(iy));
21842                                                oc128data[it.oIndex] = ox;
21843                                                oc128data[it.oIndex + 1] = oy;
21844                                        }
21845                                }
21846                        } else {
21847                                while (it.hasNext()) {
21848                                        final double ix = it.aDouble;
21849                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
21850                                        double ox;
21851                                        double oy;
21852                                        ox = (Math.sinh(ix)*Math.cos(iy));
21853                                        oy = (Math.cosh(ix)*Math.sin(iy));
21854                                        oc128data[it.oIndex] = ox;
21855                                        oc128data[it.oIndex + 1] = oy;
21856                                }
21857                        }
21858                        break;
21859                default:
21860                        throw new IllegalArgumentException("sinh supports integer, compound integer, real, compound real, complex datasets only");
21861                }
21862
21863                addFunctionName(result, "sinh");
21864                return result;
21865        }
21866
21867        /**
21868         * cosh - evaluate the hyperbolic cosine function on each element of the dataset
21869         * @param a
21870         * @return dataset
21871         */
21872        public static Dataset cosh(final Object a) {
21873                return cosh(a, null);
21874        }
21875
21876        /**
21877         * cosh - evaluate the hyperbolic cosine function on each element of the dataset
21878         * @param a
21879         * @param o output can be null - in which case, a new dataset is created
21880         * @return dataset
21881         */
21882        public static Dataset cosh(final Object a, final Dataset o) {
21883                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
21884                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
21885                final Dataset result = it.getOutput();
21886                if (!result.isComplex()) {
21887                        if (da.isComplex()) {
21888                                da = da.getRealView();
21889                                it = new SingleInputBroadcastIterator(da, result, true);
21890                        }
21891                }
21892                final int is = result.getElementsPerItem();
21893                final int as = da.getElementsPerItem();
21894                final int dt = result.getDType();
21895
21896                switch(dt) {
21897                case Dataset.INT8:
21898                        final byte[] oi8data = ((ByteDataset) result).getData();
21899                        if (it.isOutputDouble()) {
21900                                while (it.hasNext()) {
21901                                        final double ix = it.aDouble;
21902                                        byte ox;
21903                                        ox = (byte) toLong(Math.cosh(ix));
21904                                        oi8data[it.oIndex] = ox;
21905                                }
21906                        } else {
21907                                while (it.hasNext()) {
21908                                        final long ix = it.aLong;
21909                                        byte ox;
21910                                        ox = (byte) toLong(Math.cosh(ix));
21911                                        oi8data[it.oIndex] = ox;
21912                                }
21913                        }
21914                        break;
21915                case Dataset.INT16:
21916                        final short[] oi16data = ((ShortDataset) result).getData();
21917                        if (it.isOutputDouble()) {
21918                                while (it.hasNext()) {
21919                                        final double ix = it.aDouble;
21920                                        short ox;
21921                                        ox = (short) toLong(Math.cosh(ix));
21922                                        oi16data[it.oIndex] = ox;
21923                                }
21924                        } else {
21925                                while (it.hasNext()) {
21926                                        final long ix = it.aLong;
21927                                        short ox;
21928                                        ox = (short) toLong(Math.cosh(ix));
21929                                        oi16data[it.oIndex] = ox;
21930                                }
21931                        }
21932                        break;
21933                case Dataset.INT64:
21934                        final long[] oi64data = ((LongDataset) result).getData();
21935                        if (it.isOutputDouble()) {
21936                                while (it.hasNext()) {
21937                                        final double ix = it.aDouble;
21938                                        long ox;
21939                                        ox = toLong(Math.cosh(ix));
21940                                        oi64data[it.oIndex] = ox;
21941                                }
21942                        } else {
21943                                while (it.hasNext()) {
21944                                        final long ix = it.aLong;
21945                                        long ox;
21946                                        ox = toLong(Math.cosh(ix));
21947                                        oi64data[it.oIndex] = ox;
21948                                }
21949                        }
21950                        break;
21951                case Dataset.INT32:
21952                        final int[] oi32data = ((IntegerDataset) result).getData();
21953                        if (it.isOutputDouble()) {
21954                                while (it.hasNext()) {
21955                                        final double ix = it.aDouble;
21956                                        int ox;
21957                                        ox = (int) toLong(Math.cosh(ix));
21958                                        oi32data[it.oIndex] = ox;
21959                                }
21960                        } else {
21961                                while (it.hasNext()) {
21962                                        final long ix = it.aLong;
21963                                        int ox;
21964                                        ox = (int) toLong(Math.cosh(ix));
21965                                        oi32data[it.oIndex] = ox;
21966                                }
21967                        }
21968                        break;
21969                case Dataset.ARRAYINT8:
21970                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
21971                        if (is == 1) {
21972                                if (it.isOutputDouble()) {
21973                                        while (it.hasNext()) {
21974                                                final double ix = it.aDouble;
21975                                                byte ox;
21976                                                ox = (byte) toLong(Math.cosh(ix));
21977                                                oai8data[it.oIndex] = ox;
21978                                        }
21979                                } else {
21980                                        while (it.hasNext()) {
21981                                                final long ix = it.aLong;
21982                                                byte ox;
21983                                                ox = (byte) toLong(Math.cosh(ix));
21984                                                oai8data[it.oIndex] = ox;
21985                                        }
21986                                }
21987                        } else if (as == 1) {
21988                                if (it.isOutputDouble()) {
21989                                        while (it.hasNext()) {
21990                                                final double ix = it.aDouble;
21991                                                byte ox;
21992                                                ox = (byte) toLong(Math.cosh(ix));
21993                                                for (int j = 0; j < is; j++) {
21994                                                        oai8data[it.oIndex + j] = ox;
21995                                                }
21996                                        }
21997                                } else {
21998                                        while (it.hasNext()) {
21999                                                final long ix = it.aLong;
22000                                                byte ox;
22001                                                ox = (byte) toLong(Math.cosh(ix));
22002                                                for (int j = 0; j < is; j++) {
22003                                                        oai8data[it.oIndex + j] = ox;
22004                                                }
22005                                        }
22006                                }
22007                        } else {
22008                                if (it.isOutputDouble()) {
22009                                        while (it.hasNext()) {
22010                                                for (int j = 0; j < is; j++) {
22011                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22012                                                        byte ox;
22013                                                        ox = (byte) toLong(Math.cosh(ix));
22014                                                        oai8data[it.oIndex + j] = ox;
22015                                                }
22016                                        }
22017                                } else {
22018                                        while (it.hasNext()) {
22019                                                for (int j = 0; j < is; j++) {
22020                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22021                                                        byte ox;
22022                                                        ox = (byte) toLong(Math.cosh(ix));
22023                                                        oai8data[it.oIndex + j] = ox;
22024                                                }
22025                                        }
22026                                }
22027                        }
22028                        break;
22029                case Dataset.ARRAYINT16:
22030                        final short[] oai16data = ((CompoundShortDataset) result).getData();
22031                        if (is == 1) {
22032                                if (it.isOutputDouble()) {
22033                                        while (it.hasNext()) {
22034                                                final double ix = it.aDouble;
22035                                                short ox;
22036                                                ox = (short) toLong(Math.cosh(ix));
22037                                                oai16data[it.oIndex] = ox;
22038                                        }
22039                                } else {
22040                                        while (it.hasNext()) {
22041                                                final long ix = it.aLong;
22042                                                short ox;
22043                                                ox = (short) toLong(Math.cosh(ix));
22044                                                oai16data[it.oIndex] = ox;
22045                                        }
22046                                }
22047                        } else if (as == 1) {
22048                                if (it.isOutputDouble()) {
22049                                        while (it.hasNext()) {
22050                                                final double ix = it.aDouble;
22051                                                short ox;
22052                                                ox = (short) toLong(Math.cosh(ix));
22053                                                for (int j = 0; j < is; j++) {
22054                                                        oai16data[it.oIndex + j] = ox;
22055                                                }
22056                                        }
22057                                } else {
22058                                        while (it.hasNext()) {
22059                                                final long ix = it.aLong;
22060                                                short ox;
22061                                                ox = (short) toLong(Math.cosh(ix));
22062                                                for (int j = 0; j < is; j++) {
22063                                                        oai16data[it.oIndex + j] = ox;
22064                                                }
22065                                        }
22066                                }
22067                        } else {
22068                                if (it.isOutputDouble()) {
22069                                        while (it.hasNext()) {
22070                                                for (int j = 0; j < is; j++) {
22071                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22072                                                        short ox;
22073                                                        ox = (short) toLong(Math.cosh(ix));
22074                                                        oai16data[it.oIndex + j] = ox;
22075                                                }
22076                                        }
22077                                } else {
22078                                        while (it.hasNext()) {
22079                                                for (int j = 0; j < is; j++) {
22080                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22081                                                        short ox;
22082                                                        ox = (short) toLong(Math.cosh(ix));
22083                                                        oai16data[it.oIndex + j] = ox;
22084                                                }
22085                                        }
22086                                }
22087                        }
22088                        break;
22089                case Dataset.ARRAYINT64:
22090                        final long[] oai64data = ((CompoundLongDataset) result).getData();
22091                        if (is == 1) {
22092                                if (it.isOutputDouble()) {
22093                                        while (it.hasNext()) {
22094                                                final double ix = it.aDouble;
22095                                                long ox;
22096                                                ox = toLong(Math.cosh(ix));
22097                                                oai64data[it.oIndex] = ox;
22098                                        }
22099                                } else {
22100                                        while (it.hasNext()) {
22101                                                final long ix = it.aLong;
22102                                                long ox;
22103                                                ox = toLong(Math.cosh(ix));
22104                                                oai64data[it.oIndex] = ox;
22105                                        }
22106                                }
22107                        } else if (as == 1) {
22108                                if (it.isOutputDouble()) {
22109                                        while (it.hasNext()) {
22110                                                final double ix = it.aDouble;
22111                                                long ox;
22112                                                ox = toLong(Math.cosh(ix));
22113                                                for (int j = 0; j < is; j++) {
22114                                                        oai64data[it.oIndex + j] = ox;
22115                                                }
22116                                        }
22117                                } else {
22118                                        while (it.hasNext()) {
22119                                                final long ix = it.aLong;
22120                                                long ox;
22121                                                ox = toLong(Math.cosh(ix));
22122                                                for (int j = 0; j < is; j++) {
22123                                                        oai64data[it.oIndex + j] = ox;
22124                                                }
22125                                        }
22126                                }
22127                        } else {
22128                                if (it.isOutputDouble()) {
22129                                        while (it.hasNext()) {
22130                                                for (int j = 0; j < is; j++) {
22131                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22132                                                        long ox;
22133                                                        ox = toLong(Math.cosh(ix));
22134                                                        oai64data[it.oIndex + j] = ox;
22135                                                }
22136                                        }
22137                                } else {
22138                                        while (it.hasNext()) {
22139                                                for (int j = 0; j < is; j++) {
22140                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22141                                                        long ox;
22142                                                        ox = toLong(Math.cosh(ix));
22143                                                        oai64data[it.oIndex + j] = ox;
22144                                                }
22145                                        }
22146                                }
22147                        }
22148                        break;
22149                case Dataset.ARRAYINT32:
22150                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
22151                        if (is == 1) {
22152                                if (it.isOutputDouble()) {
22153                                        while (it.hasNext()) {
22154                                                final double ix = it.aDouble;
22155                                                int ox;
22156                                                ox = (int) toLong(Math.cosh(ix));
22157                                                oai32data[it.oIndex] = ox;
22158                                        }
22159                                } else {
22160                                        while (it.hasNext()) {
22161                                                final long ix = it.aLong;
22162                                                int ox;
22163                                                ox = (int) toLong(Math.cosh(ix));
22164                                                oai32data[it.oIndex] = ox;
22165                                        }
22166                                }
22167                        } else if (as == 1) {
22168                                if (it.isOutputDouble()) {
22169                                        while (it.hasNext()) {
22170                                                final double ix = it.aDouble;
22171                                                int ox;
22172                                                ox = (int) toLong(Math.cosh(ix));
22173                                                for (int j = 0; j < is; j++) {
22174                                                        oai32data[it.oIndex + j] = ox;
22175                                                }
22176                                        }
22177                                } else {
22178                                        while (it.hasNext()) {
22179                                                final long ix = it.aLong;
22180                                                int ox;
22181                                                ox = (int) toLong(Math.cosh(ix));
22182                                                for (int j = 0; j < is; j++) {
22183                                                        oai32data[it.oIndex + j] = ox;
22184                                                }
22185                                        }
22186                                }
22187                        } else {
22188                                if (it.isOutputDouble()) {
22189                                        while (it.hasNext()) {
22190                                                for (int j = 0; j < is; j++) {
22191                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22192                                                        int ox;
22193                                                        ox = (int) toLong(Math.cosh(ix));
22194                                                        oai32data[it.oIndex + j] = ox;
22195                                                }
22196                                        }
22197                                } else {
22198                                        while (it.hasNext()) {
22199                                                for (int j = 0; j < is; j++) {
22200                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22201                                                        int ox;
22202                                                        ox = (int) toLong(Math.cosh(ix));
22203                                                        oai32data[it.oIndex + j] = ox;
22204                                                }
22205                                        }
22206                                }
22207                        }
22208                        break;
22209                case Dataset.FLOAT32:
22210                        final float[] of32data = ((FloatDataset) result).getData();
22211                        if (it.isOutputDouble()) {
22212                                while (it.hasNext()) {
22213                                        final double ix = it.aDouble;
22214                                        float ox;
22215                                        ox = (float) (Math.cosh(ix));
22216                                        of32data[it.oIndex] = ox;
22217                                }
22218                        } else {
22219                                while (it.hasNext()) {
22220                                        final long ix = it.aLong;
22221                                        float ox;
22222                                        ox = (float) (Math.cosh(ix));
22223                                        of32data[it.oIndex] = ox;
22224                                }
22225                        }
22226                        break;
22227                case Dataset.FLOAT64:
22228                        final double[] of64data = ((DoubleDataset) result).getData();
22229                        if (it.isOutputDouble()) {
22230                                while (it.hasNext()) {
22231                                        final double ix = it.aDouble;
22232                                        double ox;
22233                                        ox = (Math.cosh(ix));
22234                                        of64data[it.oIndex] = ox;
22235                                }
22236                        } else {
22237                                while (it.hasNext()) {
22238                                        final long ix = it.aLong;
22239                                        double ox;
22240                                        ox = (Math.cosh(ix));
22241                                        of64data[it.oIndex] = ox;
22242                                }
22243                        }
22244                        break;
22245                case Dataset.ARRAYFLOAT32:
22246                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
22247                        if (is == 1) {
22248                                if (it.isOutputDouble()) {
22249                                        while (it.hasNext()) {
22250                                                final double ix = it.aDouble;
22251                                                float ox;
22252                                                ox = (float) (Math.cosh(ix));
22253                                                oaf32data[it.oIndex] = ox;
22254                                        }
22255                                } else {
22256                                        while (it.hasNext()) {
22257                                                final long ix = it.aLong;
22258                                                float ox;
22259                                                ox = (float) (Math.cosh(ix));
22260                                                oaf32data[it.oIndex] = ox;
22261                                        }
22262                                }
22263                        } else if (as == 1) {
22264                                if (it.isOutputDouble()) {
22265                                        while (it.hasNext()) {
22266                                                final double ix = it.aDouble;
22267                                                float ox;
22268                                                ox = (float) (Math.cosh(ix));
22269                                                for (int j = 0; j < is; j++) {
22270                                                        oaf32data[it.oIndex + j] = ox;
22271                                                }
22272                                        }
22273                                } else {
22274                                        while (it.hasNext()) {
22275                                                final long ix = it.aLong;
22276                                                float ox;
22277                                                ox = (float) (Math.cosh(ix));
22278                                                for (int j = 0; j < is; j++) {
22279                                                        oaf32data[it.oIndex + j] = ox;
22280                                                }
22281                                        }
22282                                }
22283                        } else {
22284                                if (it.isOutputDouble()) {
22285                                        while (it.hasNext()) {
22286                                                for (int j = 0; j < is; j++) {
22287                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22288                                                        float ox;
22289                                                        ox = (float) (Math.cosh(ix));
22290                                                        oaf32data[it.oIndex + j] = ox;
22291                                                }
22292                                        }
22293                                } else {
22294                                        while (it.hasNext()) {
22295                                                for (int j = 0; j < is; j++) {
22296                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22297                                                        float ox;
22298                                                        ox = (float) (Math.cosh(ix));
22299                                                        oaf32data[it.oIndex + j] = ox;
22300                                                }
22301                                        }
22302                                }
22303                        }
22304                        break;
22305                case Dataset.ARRAYFLOAT64:
22306                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
22307                        if (is == 1) {
22308                                if (it.isOutputDouble()) {
22309                                        while (it.hasNext()) {
22310                                                final double ix = it.aDouble;
22311                                                double ox;
22312                                                ox = (Math.cosh(ix));
22313                                                oaf64data[it.oIndex] = ox;
22314                                        }
22315                                } else {
22316                                        while (it.hasNext()) {
22317                                                final long ix = it.aLong;
22318                                                double ox;
22319                                                ox = (Math.cosh(ix));
22320                                                oaf64data[it.oIndex] = ox;
22321                                        }
22322                                }
22323                        } else if (as == 1) {
22324                                if (it.isOutputDouble()) {
22325                                        while (it.hasNext()) {
22326                                                final double ix = it.aDouble;
22327                                                double ox;
22328                                                ox = (Math.cosh(ix));
22329                                                for (int j = 0; j < is; j++) {
22330                                                        oaf64data[it.oIndex + j] = ox;
22331                                                }
22332                                        }
22333                                } else {
22334                                        while (it.hasNext()) {
22335                                                final long ix = it.aLong;
22336                                                double ox;
22337                                                ox = (Math.cosh(ix));
22338                                                for (int j = 0; j < is; j++) {
22339                                                        oaf64data[it.oIndex + j] = ox;
22340                                                }
22341                                        }
22342                                }
22343                        } else {
22344                                if (it.isOutputDouble()) {
22345                                        while (it.hasNext()) {
22346                                                for (int j = 0; j < is; j++) {
22347                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22348                                                        double ox;
22349                                                        ox = (Math.cosh(ix));
22350                                                        oaf64data[it.oIndex + j] = ox;
22351                                                }
22352                                        }
22353                                } else {
22354                                        while (it.hasNext()) {
22355                                                for (int j = 0; j < is; j++) {
22356                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22357                                                        double ox;
22358                                                        ox = (Math.cosh(ix));
22359                                                        oaf64data[it.oIndex + j] = ox;
22360                                                }
22361                                        }
22362                                }
22363                        }
22364                        break;
22365                case Dataset.COMPLEX64:
22366                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
22367                        if (!da.isComplex()) {
22368                                if (it.isOutputDouble()) {
22369                                        final double iy = 0;
22370                                        while (it.hasNext()) {
22371                                                final double ix = it.aDouble;
22372                                                float ox;
22373                                                float oy;
22374                                                ox = (float) (Math.cosh(ix)*Math.cos(iy));
22375                                                oy = (float) (Math.sinh(ix)*Math.sin(iy));
22376                                                oc64data[it.oIndex] = ox;
22377                                                oc64data[it.oIndex + 1] = oy;
22378                                        }
22379                                } else {
22380                                        final long iy = 0;
22381                                        while (it.hasNext()) {
22382                                                final long ix = it.aLong;
22383                                                float ox;
22384                                                float oy;
22385                                                ox = (float) toLong(Math.cosh(ix)*Math.cos(iy));
22386                                                oy = (float) toLong(Math.sinh(ix)*Math.sin(iy));
22387                                                oc64data[it.oIndex] = ox;
22388                                                oc64data[it.oIndex + 1] = oy;
22389                                        }
22390                                }
22391                        } else {
22392                                while (it.hasNext()) {
22393                                        final double ix = it.aDouble;
22394                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
22395                                        float ox;
22396                                        float oy;
22397                                        ox = (float) (Math.cosh(ix)*Math.cos(iy));
22398                                        oy = (float) (Math.sinh(ix)*Math.sin(iy));
22399                                        oc64data[it.oIndex] = ox;
22400                                        oc64data[it.oIndex + 1] = oy;
22401                                }
22402                        }
22403                        break;
22404                case Dataset.COMPLEX128:
22405                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
22406                        if (!da.isComplex()) {
22407                                if (it.isOutputDouble()) {
22408                                        final double iy = 0;
22409                                        while (it.hasNext()) {
22410                                                final double ix = it.aDouble;
22411                                                double ox;
22412                                                double oy;
22413                                                ox = (Math.cosh(ix)*Math.cos(iy));
22414                                                oy = (Math.sinh(ix)*Math.sin(iy));
22415                                                oc128data[it.oIndex] = ox;
22416                                                oc128data[it.oIndex + 1] = oy;
22417                                        }
22418                                } else {
22419                                        final long iy = 0;
22420                                        while (it.hasNext()) {
22421                                                final long ix = it.aLong;
22422                                                double ox;
22423                                                double oy;
22424                                                ox = (double) (Math.cosh(ix)*Math.cos(iy));
22425                                                oy = (double) (Math.sinh(ix)*Math.sin(iy));
22426                                                oc128data[it.oIndex] = ox;
22427                                                oc128data[it.oIndex + 1] = oy;
22428                                        }
22429                                }
22430                        } else {
22431                                while (it.hasNext()) {
22432                                        final double ix = it.aDouble;
22433                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
22434                                        double ox;
22435                                        double oy;
22436                                        ox = (Math.cosh(ix)*Math.cos(iy));
22437                                        oy = (Math.sinh(ix)*Math.sin(iy));
22438                                        oc128data[it.oIndex] = ox;
22439                                        oc128data[it.oIndex + 1] = oy;
22440                                }
22441                        }
22442                        break;
22443                default:
22444                        throw new IllegalArgumentException("cosh supports integer, compound integer, real, compound real, complex datasets only");
22445                }
22446
22447                addFunctionName(result, "cosh");
22448                return result;
22449        }
22450
22451        /**
22452         * tanh - evaluate the tangent hyperbolic function on each element of the dataset
22453         * @param a
22454         * @return dataset
22455         */
22456        public static Dataset tanh(final Object a) {
22457                return tanh(a, null);
22458        }
22459
22460        /**
22461         * tanh - evaluate the tangent hyperbolic function on each element of the dataset
22462         * @param a
22463         * @param o output can be null - in which case, a new dataset is created
22464         * @return dataset
22465         */
22466        public static Dataset tanh(final Object a, final Dataset o) {
22467                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
22468                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
22469                final Dataset result = it.getOutput();
22470                if (!result.isComplex()) {
22471                        if (da.isComplex()) {
22472                                da = da.getRealView();
22473                                it = new SingleInputBroadcastIterator(da, result, true);
22474                        }
22475                }
22476                final int is = result.getElementsPerItem();
22477                final int as = da.getElementsPerItem();
22478                final int dt = result.getDType();
22479
22480                switch(dt) {
22481                case Dataset.INT8:
22482                        final byte[] oi8data = ((ByteDataset) result).getData();
22483                        if (it.isOutputDouble()) {
22484                                while (it.hasNext()) {
22485                                        final double ix = it.aDouble;
22486                                        byte ox;
22487                                        ox = (byte) toLong(Math.tanh(ix));
22488                                        oi8data[it.oIndex] = ox;
22489                                }
22490                        } else {
22491                                while (it.hasNext()) {
22492                                        final long ix = it.aLong;
22493                                        byte ox;
22494                                        ox = (byte) toLong(Math.tanh(ix));
22495                                        oi8data[it.oIndex] = ox;
22496                                }
22497                        }
22498                        break;
22499                case Dataset.INT16:
22500                        final short[] oi16data = ((ShortDataset) result).getData();
22501                        if (it.isOutputDouble()) {
22502                                while (it.hasNext()) {
22503                                        final double ix = it.aDouble;
22504                                        short ox;
22505                                        ox = (short) toLong(Math.tanh(ix));
22506                                        oi16data[it.oIndex] = ox;
22507                                }
22508                        } else {
22509                                while (it.hasNext()) {
22510                                        final long ix = it.aLong;
22511                                        short ox;
22512                                        ox = (short) toLong(Math.tanh(ix));
22513                                        oi16data[it.oIndex] = ox;
22514                                }
22515                        }
22516                        break;
22517                case Dataset.INT64:
22518                        final long[] oi64data = ((LongDataset) result).getData();
22519                        if (it.isOutputDouble()) {
22520                                while (it.hasNext()) {
22521                                        final double ix = it.aDouble;
22522                                        long ox;
22523                                        ox = toLong(Math.tanh(ix));
22524                                        oi64data[it.oIndex] = ox;
22525                                }
22526                        } else {
22527                                while (it.hasNext()) {
22528                                        final long ix = it.aLong;
22529                                        long ox;
22530                                        ox = toLong(Math.tanh(ix));
22531                                        oi64data[it.oIndex] = ox;
22532                                }
22533                        }
22534                        break;
22535                case Dataset.INT32:
22536                        final int[] oi32data = ((IntegerDataset) result).getData();
22537                        if (it.isOutputDouble()) {
22538                                while (it.hasNext()) {
22539                                        final double ix = it.aDouble;
22540                                        int ox;
22541                                        ox = (int) toLong(Math.tanh(ix));
22542                                        oi32data[it.oIndex] = ox;
22543                                }
22544                        } else {
22545                                while (it.hasNext()) {
22546                                        final long ix = it.aLong;
22547                                        int ox;
22548                                        ox = (int) toLong(Math.tanh(ix));
22549                                        oi32data[it.oIndex] = ox;
22550                                }
22551                        }
22552                        break;
22553                case Dataset.ARRAYINT8:
22554                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
22555                        if (is == 1) {
22556                                if (it.isOutputDouble()) {
22557                                        while (it.hasNext()) {
22558                                                final double ix = it.aDouble;
22559                                                byte ox;
22560                                                ox = (byte) toLong(Math.tanh(ix));
22561                                                oai8data[it.oIndex] = ox;
22562                                        }
22563                                } else {
22564                                        while (it.hasNext()) {
22565                                                final long ix = it.aLong;
22566                                                byte ox;
22567                                                ox = (byte) toLong(Math.tanh(ix));
22568                                                oai8data[it.oIndex] = ox;
22569                                        }
22570                                }
22571                        } else if (as == 1) {
22572                                if (it.isOutputDouble()) {
22573                                        while (it.hasNext()) {
22574                                                final double ix = it.aDouble;
22575                                                byte ox;
22576                                                ox = (byte) toLong(Math.tanh(ix));
22577                                                for (int j = 0; j < is; j++) {
22578                                                        oai8data[it.oIndex + j] = ox;
22579                                                }
22580                                        }
22581                                } else {
22582                                        while (it.hasNext()) {
22583                                                final long ix = it.aLong;
22584                                                byte ox;
22585                                                ox = (byte) toLong(Math.tanh(ix));
22586                                                for (int j = 0; j < is; j++) {
22587                                                        oai8data[it.oIndex + j] = ox;
22588                                                }
22589                                        }
22590                                }
22591                        } else {
22592                                if (it.isOutputDouble()) {
22593                                        while (it.hasNext()) {
22594                                                for (int j = 0; j < is; j++) {
22595                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22596                                                        byte ox;
22597                                                        ox = (byte) toLong(Math.tanh(ix));
22598                                                        oai8data[it.oIndex + j] = ox;
22599                                                }
22600                                        }
22601                                } else {
22602                                        while (it.hasNext()) {
22603                                                for (int j = 0; j < is; j++) {
22604                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22605                                                        byte ox;
22606                                                        ox = (byte) toLong(Math.tanh(ix));
22607                                                        oai8data[it.oIndex + j] = ox;
22608                                                }
22609                                        }
22610                                }
22611                        }
22612                        break;
22613                case Dataset.ARRAYINT16:
22614                        final short[] oai16data = ((CompoundShortDataset) result).getData();
22615                        if (is == 1) {
22616                                if (it.isOutputDouble()) {
22617                                        while (it.hasNext()) {
22618                                                final double ix = it.aDouble;
22619                                                short ox;
22620                                                ox = (short) toLong(Math.tanh(ix));
22621                                                oai16data[it.oIndex] = ox;
22622                                        }
22623                                } else {
22624                                        while (it.hasNext()) {
22625                                                final long ix = it.aLong;
22626                                                short ox;
22627                                                ox = (short) toLong(Math.tanh(ix));
22628                                                oai16data[it.oIndex] = ox;
22629                                        }
22630                                }
22631                        } else if (as == 1) {
22632                                if (it.isOutputDouble()) {
22633                                        while (it.hasNext()) {
22634                                                final double ix = it.aDouble;
22635                                                short ox;
22636                                                ox = (short) toLong(Math.tanh(ix));
22637                                                for (int j = 0; j < is; j++) {
22638                                                        oai16data[it.oIndex + j] = ox;
22639                                                }
22640                                        }
22641                                } else {
22642                                        while (it.hasNext()) {
22643                                                final long ix = it.aLong;
22644                                                short ox;
22645                                                ox = (short) toLong(Math.tanh(ix));
22646                                                for (int j = 0; j < is; j++) {
22647                                                        oai16data[it.oIndex + j] = ox;
22648                                                }
22649                                        }
22650                                }
22651                        } else {
22652                                if (it.isOutputDouble()) {
22653                                        while (it.hasNext()) {
22654                                                for (int j = 0; j < is; j++) {
22655                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22656                                                        short ox;
22657                                                        ox = (short) toLong(Math.tanh(ix));
22658                                                        oai16data[it.oIndex + j] = ox;
22659                                                }
22660                                        }
22661                                } else {
22662                                        while (it.hasNext()) {
22663                                                for (int j = 0; j < is; j++) {
22664                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22665                                                        short ox;
22666                                                        ox = (short) toLong(Math.tanh(ix));
22667                                                        oai16data[it.oIndex + j] = ox;
22668                                                }
22669                                        }
22670                                }
22671                        }
22672                        break;
22673                case Dataset.ARRAYINT64:
22674                        final long[] oai64data = ((CompoundLongDataset) result).getData();
22675                        if (is == 1) {
22676                                if (it.isOutputDouble()) {
22677                                        while (it.hasNext()) {
22678                                                final double ix = it.aDouble;
22679                                                long ox;
22680                                                ox = toLong(Math.tanh(ix));
22681                                                oai64data[it.oIndex] = ox;
22682                                        }
22683                                } else {
22684                                        while (it.hasNext()) {
22685                                                final long ix = it.aLong;
22686                                                long ox;
22687                                                ox = toLong(Math.tanh(ix));
22688                                                oai64data[it.oIndex] = ox;
22689                                        }
22690                                }
22691                        } else if (as == 1) {
22692                                if (it.isOutputDouble()) {
22693                                        while (it.hasNext()) {
22694                                                final double ix = it.aDouble;
22695                                                long ox;
22696                                                ox = toLong(Math.tanh(ix));
22697                                                for (int j = 0; j < is; j++) {
22698                                                        oai64data[it.oIndex + j] = ox;
22699                                                }
22700                                        }
22701                                } else {
22702                                        while (it.hasNext()) {
22703                                                final long ix = it.aLong;
22704                                                long ox;
22705                                                ox = toLong(Math.tanh(ix));
22706                                                for (int j = 0; j < is; j++) {
22707                                                        oai64data[it.oIndex + j] = ox;
22708                                                }
22709                                        }
22710                                }
22711                        } else {
22712                                if (it.isOutputDouble()) {
22713                                        while (it.hasNext()) {
22714                                                for (int j = 0; j < is; j++) {
22715                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22716                                                        long ox;
22717                                                        ox = toLong(Math.tanh(ix));
22718                                                        oai64data[it.oIndex + j] = ox;
22719                                                }
22720                                        }
22721                                } else {
22722                                        while (it.hasNext()) {
22723                                                for (int j = 0; j < is; j++) {
22724                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22725                                                        long ox;
22726                                                        ox = toLong(Math.tanh(ix));
22727                                                        oai64data[it.oIndex + j] = ox;
22728                                                }
22729                                        }
22730                                }
22731                        }
22732                        break;
22733                case Dataset.ARRAYINT32:
22734                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
22735                        if (is == 1) {
22736                                if (it.isOutputDouble()) {
22737                                        while (it.hasNext()) {
22738                                                final double ix = it.aDouble;
22739                                                int ox;
22740                                                ox = (int) toLong(Math.tanh(ix));
22741                                                oai32data[it.oIndex] = ox;
22742                                        }
22743                                } else {
22744                                        while (it.hasNext()) {
22745                                                final long ix = it.aLong;
22746                                                int ox;
22747                                                ox = (int) toLong(Math.tanh(ix));
22748                                                oai32data[it.oIndex] = ox;
22749                                        }
22750                                }
22751                        } else if (as == 1) {
22752                                if (it.isOutputDouble()) {
22753                                        while (it.hasNext()) {
22754                                                final double ix = it.aDouble;
22755                                                int ox;
22756                                                ox = (int) toLong(Math.tanh(ix));
22757                                                for (int j = 0; j < is; j++) {
22758                                                        oai32data[it.oIndex + j] = ox;
22759                                                }
22760                                        }
22761                                } else {
22762                                        while (it.hasNext()) {
22763                                                final long ix = it.aLong;
22764                                                int ox;
22765                                                ox = (int) toLong(Math.tanh(ix));
22766                                                for (int j = 0; j < is; j++) {
22767                                                        oai32data[it.oIndex + j] = ox;
22768                                                }
22769                                        }
22770                                }
22771                        } else {
22772                                if (it.isOutputDouble()) {
22773                                        while (it.hasNext()) {
22774                                                for (int j = 0; j < is; j++) {
22775                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22776                                                        int ox;
22777                                                        ox = (int) toLong(Math.tanh(ix));
22778                                                        oai32data[it.oIndex + j] = ox;
22779                                                }
22780                                        }
22781                                } else {
22782                                        while (it.hasNext()) {
22783                                                for (int j = 0; j < is; j++) {
22784                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22785                                                        int ox;
22786                                                        ox = (int) toLong(Math.tanh(ix));
22787                                                        oai32data[it.oIndex + j] = ox;
22788                                                }
22789                                        }
22790                                }
22791                        }
22792                        break;
22793                case Dataset.FLOAT32:
22794                        final float[] of32data = ((FloatDataset) result).getData();
22795                        if (it.isOutputDouble()) {
22796                                while (it.hasNext()) {
22797                                        final double ix = it.aDouble;
22798                                        float ox;
22799                                        ox = (float) (Math.tanh(ix));
22800                                        of32data[it.oIndex] = ox;
22801                                }
22802                        } else {
22803                                while (it.hasNext()) {
22804                                        final long ix = it.aLong;
22805                                        float ox;
22806                                        ox = (float) (Math.tanh(ix));
22807                                        of32data[it.oIndex] = ox;
22808                                }
22809                        }
22810                        break;
22811                case Dataset.FLOAT64:
22812                        final double[] of64data = ((DoubleDataset) result).getData();
22813                        if (it.isOutputDouble()) {
22814                                while (it.hasNext()) {
22815                                        final double ix = it.aDouble;
22816                                        double ox;
22817                                        ox = (Math.tanh(ix));
22818                                        of64data[it.oIndex] = ox;
22819                                }
22820                        } else {
22821                                while (it.hasNext()) {
22822                                        final long ix = it.aLong;
22823                                        double ox;
22824                                        ox = (Math.tanh(ix));
22825                                        of64data[it.oIndex] = ox;
22826                                }
22827                        }
22828                        break;
22829                case Dataset.ARRAYFLOAT32:
22830                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
22831                        if (is == 1) {
22832                                if (it.isOutputDouble()) {
22833                                        while (it.hasNext()) {
22834                                                final double ix = it.aDouble;
22835                                                float ox;
22836                                                ox = (float) (Math.tanh(ix));
22837                                                oaf32data[it.oIndex] = ox;
22838                                        }
22839                                } else {
22840                                        while (it.hasNext()) {
22841                                                final long ix = it.aLong;
22842                                                float ox;
22843                                                ox = (float) (Math.tanh(ix));
22844                                                oaf32data[it.oIndex] = ox;
22845                                        }
22846                                }
22847                        } else if (as == 1) {
22848                                if (it.isOutputDouble()) {
22849                                        while (it.hasNext()) {
22850                                                final double ix = it.aDouble;
22851                                                float ox;
22852                                                ox = (float) (Math.tanh(ix));
22853                                                for (int j = 0; j < is; j++) {
22854                                                        oaf32data[it.oIndex + j] = ox;
22855                                                }
22856                                        }
22857                                } else {
22858                                        while (it.hasNext()) {
22859                                                final long ix = it.aLong;
22860                                                float ox;
22861                                                ox = (float) (Math.tanh(ix));
22862                                                for (int j = 0; j < is; j++) {
22863                                                        oaf32data[it.oIndex + j] = ox;
22864                                                }
22865                                        }
22866                                }
22867                        } else {
22868                                if (it.isOutputDouble()) {
22869                                        while (it.hasNext()) {
22870                                                for (int j = 0; j < is; j++) {
22871                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22872                                                        float ox;
22873                                                        ox = (float) (Math.tanh(ix));
22874                                                        oaf32data[it.oIndex + j] = ox;
22875                                                }
22876                                        }
22877                                } else {
22878                                        while (it.hasNext()) {
22879                                                for (int j = 0; j < is; j++) {
22880                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22881                                                        float ox;
22882                                                        ox = (float) (Math.tanh(ix));
22883                                                        oaf32data[it.oIndex + j] = ox;
22884                                                }
22885                                        }
22886                                }
22887                        }
22888                        break;
22889                case Dataset.ARRAYFLOAT64:
22890                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
22891                        if (is == 1) {
22892                                if (it.isOutputDouble()) {
22893                                        while (it.hasNext()) {
22894                                                final double ix = it.aDouble;
22895                                                double ox;
22896                                                ox = (Math.tanh(ix));
22897                                                oaf64data[it.oIndex] = ox;
22898                                        }
22899                                } else {
22900                                        while (it.hasNext()) {
22901                                                final long ix = it.aLong;
22902                                                double ox;
22903                                                ox = (Math.tanh(ix));
22904                                                oaf64data[it.oIndex] = ox;
22905                                        }
22906                                }
22907                        } else if (as == 1) {
22908                                if (it.isOutputDouble()) {
22909                                        while (it.hasNext()) {
22910                                                final double ix = it.aDouble;
22911                                                double ox;
22912                                                ox = (Math.tanh(ix));
22913                                                for (int j = 0; j < is; j++) {
22914                                                        oaf64data[it.oIndex + j] = ox;
22915                                                }
22916                                        }
22917                                } else {
22918                                        while (it.hasNext()) {
22919                                                final long ix = it.aLong;
22920                                                double ox;
22921                                                ox = (Math.tanh(ix));
22922                                                for (int j = 0; j < is; j++) {
22923                                                        oaf64data[it.oIndex + j] = ox;
22924                                                }
22925                                        }
22926                                }
22927                        } else {
22928                                if (it.isOutputDouble()) {
22929                                        while (it.hasNext()) {
22930                                                for (int j = 0; j < is; j++) {
22931                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22932                                                        double ox;
22933                                                        ox = (Math.tanh(ix));
22934                                                        oaf64data[it.oIndex + j] = ox;
22935                                                }
22936                                        }
22937                                } else {
22938                                        while (it.hasNext()) {
22939                                                for (int j = 0; j < is; j++) {
22940                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22941                                                        double ox;
22942                                                        ox = (Math.tanh(ix));
22943                                                        oaf64data[it.oIndex + j] = ox;
22944                                                }
22945                                        }
22946                                }
22947                        }
22948                        break;
22949                case Dataset.COMPLEX64:
22950                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
22951                        if (!da.isComplex()) {
22952                                if (it.isOutputDouble()) {
22953                                        final double iy = 0;
22954                                        while (it.hasNext()) {
22955                                                final double ix = it.aDouble;
22956                                                float tx;
22957                                                float ty;
22958                                                float tf;
22959                                                float ox;
22960                                                float oy;
22961                                                tx = (float) (2.*ix);
22962                                                ty = (float) (2.*iy);
22963                                                tf = (float) (1./(Math.cos(tx)+Math.cosh(ty)));
22964                                                ox = (float) (tf*Math.sinh(tx));
22965                                                oy = (float) (tf*Math.sin(ty));
22966                                                oc64data[it.oIndex] = ox;
22967                                                oc64data[it.oIndex + 1] = oy;
22968                                        }
22969                                } else {
22970                                        final long iy = 0;
22971                                        while (it.hasNext()) {
22972                                                final long ix = it.aLong;
22973                                                float tx;
22974                                                float ty;
22975                                                float tf;
22976                                                float ox;
22977                                                float oy;
22978                                                tx = (float) toLong(2.*ix);
22979                                                ty = (float) toLong(2.*iy);
22980                                                tf = (float) toLong(1./(Math.cos(tx)+Math.cosh(ty)));
22981                                                ox = (float) toLong(tf*Math.sinh(tx));
22982                                                oy = (float) toLong(tf*Math.sin(ty));
22983                                                oc64data[it.oIndex] = ox;
22984                                                oc64data[it.oIndex + 1] = oy;
22985                                        }
22986                                }
22987                        } else {
22988                                while (it.hasNext()) {
22989                                        final double ix = it.aDouble;
22990                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
22991                                        float tx;
22992                                        float ty;
22993                                        float tf;
22994                                        float ox;
22995                                        float oy;
22996                                        tx = (float) (2.*ix);
22997                                        ty = (float) (2.*iy);
22998                                        tf = (float) (1./(Math.cos(tx)+Math.cosh(ty)));
22999                                        ox = (float) (tf*Math.sinh(tx));
23000                                        oy = (float) (tf*Math.sin(ty));
23001                                        oc64data[it.oIndex] = ox;
23002                                        oc64data[it.oIndex + 1] = oy;
23003                                }
23004                        }
23005                        break;
23006                case Dataset.COMPLEX128:
23007                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
23008                        if (!da.isComplex()) {
23009                                if (it.isOutputDouble()) {
23010                                        final double iy = 0;
23011                                        while (it.hasNext()) {
23012                                                final double ix = it.aDouble;
23013                                                double tx;
23014                                                double ty;
23015                                                double tf;
23016                                                double ox;
23017                                                double oy;
23018                                                tx = (2.*ix);
23019                                                ty = (2.*iy);
23020                                                tf = (1./(Math.cos(tx)+Math.cosh(ty)));
23021                                                ox = (tf*Math.sinh(tx));
23022                                                oy = (tf*Math.sin(ty));
23023                                                oc128data[it.oIndex] = ox;
23024                                                oc128data[it.oIndex + 1] = oy;
23025                                        }
23026                                } else {
23027                                        final long iy = 0;
23028                                        while (it.hasNext()) {
23029                                                final long ix = it.aLong;
23030                                                double tx;
23031                                                double ty;
23032                                                double tf;
23033                                                double ox;
23034                                                double oy;
23035                                                tx = (2.*ix);
23036                                                ty = (2.*iy);
23037                                                tf = (double) (1./(Math.cos(tx)+Math.cosh(ty)));
23038                                                ox = (double) (tf*Math.sinh(tx));
23039                                                oy = (double) (tf*Math.sin(ty));
23040                                                oc128data[it.oIndex] = ox;
23041                                                oc128data[it.oIndex + 1] = oy;
23042                                        }
23043                                }
23044                        } else {
23045                                while (it.hasNext()) {
23046                                        final double ix = it.aDouble;
23047                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
23048                                        double tx;
23049                                        double ty;
23050                                        double tf;
23051                                        double ox;
23052                                        double oy;
23053                                        tx = (2.*ix);
23054                                        ty = (2.*iy);
23055                                        tf = (1./(Math.cos(tx)+Math.cosh(ty)));
23056                                        ox = (tf*Math.sinh(tx));
23057                                        oy = (tf*Math.sin(ty));
23058                                        oc128data[it.oIndex] = ox;
23059                                        oc128data[it.oIndex + 1] = oy;
23060                                }
23061                        }
23062                        break;
23063                default:
23064                        throw new IllegalArgumentException("tanh supports integer, compound integer, real, compound real, complex datasets only");
23065                }
23066
23067                addFunctionName(result, "tanh");
23068                return result;
23069        }
23070
23071        /**
23072         * arcsinh - evaluate the inverse hyperbolic sine function on each element of the dataset
23073         * @param a
23074         * @return dataset
23075         */
23076        public static Dataset arcsinh(final Object a) {
23077                return arcsinh(a, null);
23078        }
23079
23080        /**
23081         * arcsinh - evaluate the inverse hyperbolic sine function on each element of the dataset
23082         * @param a
23083         * @param o output can be null - in which case, a new dataset is created
23084         * @return dataset
23085         */
23086        public static Dataset arcsinh(final Object a, final Dataset o) {
23087                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
23088                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
23089                final Dataset result = it.getOutput();
23090                if (!result.isComplex()) {
23091                        if (da.isComplex()) {
23092                                da = da.getRealView();
23093                                it = new SingleInputBroadcastIterator(da, result, true);
23094                        }
23095                }
23096                final int is = result.getElementsPerItem();
23097                final int as = da.getElementsPerItem();
23098                final int dt = result.getDType();
23099
23100                switch(dt) {
23101                case Dataset.INT8:
23102                        final byte[] oi8data = ((ByteDataset) result).getData();
23103                        if (it.isOutputDouble()) {
23104                                while (it.hasNext()) {
23105                                        final double ix = it.aDouble;
23106                                        byte ox;
23107                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23108                                        oi8data[it.oIndex] = ox;
23109                                }
23110                        } else {
23111                                while (it.hasNext()) {
23112                                        final long ix = it.aLong;
23113                                        byte ox;
23114                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23115                                        oi8data[it.oIndex] = ox;
23116                                }
23117                        }
23118                        break;
23119                case Dataset.INT16:
23120                        final short[] oi16data = ((ShortDataset) result).getData();
23121                        if (it.isOutputDouble()) {
23122                                while (it.hasNext()) {
23123                                        final double ix = it.aDouble;
23124                                        short ox;
23125                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23126                                        oi16data[it.oIndex] = ox;
23127                                }
23128                        } else {
23129                                while (it.hasNext()) {
23130                                        final long ix = it.aLong;
23131                                        short ox;
23132                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23133                                        oi16data[it.oIndex] = ox;
23134                                }
23135                        }
23136                        break;
23137                case Dataset.INT64:
23138                        final long[] oi64data = ((LongDataset) result).getData();
23139                        if (it.isOutputDouble()) {
23140                                while (it.hasNext()) {
23141                                        final double ix = it.aDouble;
23142                                        long ox;
23143                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23144                                        oi64data[it.oIndex] = ox;
23145                                }
23146                        } else {
23147                                while (it.hasNext()) {
23148                                        final long ix = it.aLong;
23149                                        long ox;
23150                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23151                                        oi64data[it.oIndex] = ox;
23152                                }
23153                        }
23154                        break;
23155                case Dataset.INT32:
23156                        final int[] oi32data = ((IntegerDataset) result).getData();
23157                        if (it.isOutputDouble()) {
23158                                while (it.hasNext()) {
23159                                        final double ix = it.aDouble;
23160                                        int ox;
23161                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23162                                        oi32data[it.oIndex] = ox;
23163                                }
23164                        } else {
23165                                while (it.hasNext()) {
23166                                        final long ix = it.aLong;
23167                                        int ox;
23168                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23169                                        oi32data[it.oIndex] = ox;
23170                                }
23171                        }
23172                        break;
23173                case Dataset.ARRAYINT8:
23174                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
23175                        if (is == 1) {
23176                                if (it.isOutputDouble()) {
23177                                        while (it.hasNext()) {
23178                                                final double ix = it.aDouble;
23179                                                byte ox;
23180                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23181                                                oai8data[it.oIndex] = ox;
23182                                        }
23183                                } else {
23184                                        while (it.hasNext()) {
23185                                                final long ix = it.aLong;
23186                                                byte ox;
23187                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23188                                                oai8data[it.oIndex] = ox;
23189                                        }
23190                                }
23191                        } else if (as == 1) {
23192                                if (it.isOutputDouble()) {
23193                                        while (it.hasNext()) {
23194                                                final double ix = it.aDouble;
23195                                                byte ox;
23196                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23197                                                for (int j = 0; j < is; j++) {
23198                                                        oai8data[it.oIndex + j] = ox;
23199                                                }
23200                                        }
23201                                } else {
23202                                        while (it.hasNext()) {
23203                                                final long ix = it.aLong;
23204                                                byte ox;
23205                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23206                                                for (int j = 0; j < is; j++) {
23207                                                        oai8data[it.oIndex + j] = ox;
23208                                                }
23209                                        }
23210                                }
23211                        } else {
23212                                if (it.isOutputDouble()) {
23213                                        while (it.hasNext()) {
23214                                                for (int j = 0; j < is; j++) {
23215                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23216                                                        byte ox;
23217                                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23218                                                        oai8data[it.oIndex + j] = ox;
23219                                                }
23220                                        }
23221                                } else {
23222                                        while (it.hasNext()) {
23223                                                for (int j = 0; j < is; j++) {
23224                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23225                                                        byte ox;
23226                                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23227                                                        oai8data[it.oIndex + j] = ox;
23228                                                }
23229                                        }
23230                                }
23231                        }
23232                        break;
23233                case Dataset.ARRAYINT16:
23234                        final short[] oai16data = ((CompoundShortDataset) result).getData();
23235                        if (is == 1) {
23236                                if (it.isOutputDouble()) {
23237                                        while (it.hasNext()) {
23238                                                final double ix = it.aDouble;
23239                                                short ox;
23240                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23241                                                oai16data[it.oIndex] = ox;
23242                                        }
23243                                } else {
23244                                        while (it.hasNext()) {
23245                                                final long ix = it.aLong;
23246                                                short ox;
23247                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23248                                                oai16data[it.oIndex] = ox;
23249                                        }
23250                                }
23251                        } else if (as == 1) {
23252                                if (it.isOutputDouble()) {
23253                                        while (it.hasNext()) {
23254                                                final double ix = it.aDouble;
23255                                                short ox;
23256                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23257                                                for (int j = 0; j < is; j++) {
23258                                                        oai16data[it.oIndex + j] = ox;
23259                                                }
23260                                        }
23261                                } else {
23262                                        while (it.hasNext()) {
23263                                                final long ix = it.aLong;
23264                                                short ox;
23265                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23266                                                for (int j = 0; j < is; j++) {
23267                                                        oai16data[it.oIndex + j] = ox;
23268                                                }
23269                                        }
23270                                }
23271                        } else {
23272                                if (it.isOutputDouble()) {
23273                                        while (it.hasNext()) {
23274                                                for (int j = 0; j < is; j++) {
23275                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23276                                                        short ox;
23277                                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23278                                                        oai16data[it.oIndex + j] = ox;
23279                                                }
23280                                        }
23281                                } else {
23282                                        while (it.hasNext()) {
23283                                                for (int j = 0; j < is; j++) {
23284                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23285                                                        short ox;
23286                                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23287                                                        oai16data[it.oIndex + j] = ox;
23288                                                }
23289                                        }
23290                                }
23291                        }
23292                        break;
23293                case Dataset.ARRAYINT64:
23294                        final long[] oai64data = ((CompoundLongDataset) result).getData();
23295                        if (is == 1) {
23296                                if (it.isOutputDouble()) {
23297                                        while (it.hasNext()) {
23298                                                final double ix = it.aDouble;
23299                                                long ox;
23300                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23301                                                oai64data[it.oIndex] = ox;
23302                                        }
23303                                } else {
23304                                        while (it.hasNext()) {
23305                                                final long ix = it.aLong;
23306                                                long ox;
23307                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23308                                                oai64data[it.oIndex] = ox;
23309                                        }
23310                                }
23311                        } else if (as == 1) {
23312                                if (it.isOutputDouble()) {
23313                                        while (it.hasNext()) {
23314                                                final double ix = it.aDouble;
23315                                                long ox;
23316                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23317                                                for (int j = 0; j < is; j++) {
23318                                                        oai64data[it.oIndex + j] = ox;
23319                                                }
23320                                        }
23321                                } else {
23322                                        while (it.hasNext()) {
23323                                                final long ix = it.aLong;
23324                                                long ox;
23325                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23326                                                for (int j = 0; j < is; j++) {
23327                                                        oai64data[it.oIndex + j] = ox;
23328                                                }
23329                                        }
23330                                }
23331                        } else {
23332                                if (it.isOutputDouble()) {
23333                                        while (it.hasNext()) {
23334                                                for (int j = 0; j < is; j++) {
23335                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23336                                                        long ox;
23337                                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23338                                                        oai64data[it.oIndex + j] = ox;
23339                                                }
23340                                        }
23341                                } else {
23342                                        while (it.hasNext()) {
23343                                                for (int j = 0; j < is; j++) {
23344                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23345                                                        long ox;
23346                                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23347                                                        oai64data[it.oIndex + j] = ox;
23348                                                }
23349                                        }
23350                                }
23351                        }
23352                        break;
23353                case Dataset.ARRAYINT32:
23354                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
23355                        if (is == 1) {
23356                                if (it.isOutputDouble()) {
23357                                        while (it.hasNext()) {
23358                                                final double ix = it.aDouble;
23359                                                int ox;
23360                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23361                                                oai32data[it.oIndex] = ox;
23362                                        }
23363                                } else {
23364                                        while (it.hasNext()) {
23365                                                final long ix = it.aLong;
23366                                                int ox;
23367                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23368                                                oai32data[it.oIndex] = ox;
23369                                        }
23370                                }
23371                        } else if (as == 1) {
23372                                if (it.isOutputDouble()) {
23373                                        while (it.hasNext()) {
23374                                                final double ix = it.aDouble;
23375                                                int ox;
23376                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23377                                                for (int j = 0; j < is; j++) {
23378                                                        oai32data[it.oIndex + j] = ox;
23379                                                }
23380                                        }
23381                                } else {
23382                                        while (it.hasNext()) {
23383                                                final long ix = it.aLong;
23384                                                int ox;
23385                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23386                                                for (int j = 0; j < is; j++) {
23387                                                        oai32data[it.oIndex + j] = ox;
23388                                                }
23389                                        }
23390                                }
23391                        } else {
23392                                if (it.isOutputDouble()) {
23393                                        while (it.hasNext()) {
23394                                                for (int j = 0; j < is; j++) {
23395                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23396                                                        int ox;
23397                                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23398                                                        oai32data[it.oIndex + j] = ox;
23399                                                }
23400                                        }
23401                                } else {
23402                                        while (it.hasNext()) {
23403                                                for (int j = 0; j < is; j++) {
23404                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23405                                                        int ox;
23406                                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23407                                                        oai32data[it.oIndex + j] = ox;
23408                                                }
23409                                        }
23410                                }
23411                        }
23412                        break;
23413                case Dataset.FLOAT32:
23414                        final float[] of32data = ((FloatDataset) result).getData();
23415                        if (it.isOutputDouble()) {
23416                                while (it.hasNext()) {
23417                                        final double ix = it.aDouble;
23418                                        float ox;
23419                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23420                                        of32data[it.oIndex] = ox;
23421                                }
23422                        } else {
23423                                while (it.hasNext()) {
23424                                        final long ix = it.aLong;
23425                                        float ox;
23426                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23427                                        of32data[it.oIndex] = ox;
23428                                }
23429                        }
23430                        break;
23431                case Dataset.FLOAT64:
23432                        final double[] of64data = ((DoubleDataset) result).getData();
23433                        if (it.isOutputDouble()) {
23434                                while (it.hasNext()) {
23435                                        final double ix = it.aDouble;
23436                                        double ox;
23437                                        ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23438                                        of64data[it.oIndex] = ox;
23439                                }
23440                        } else {
23441                                while (it.hasNext()) {
23442                                        final long ix = it.aLong;
23443                                        double ox;
23444                                        ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23445                                        of64data[it.oIndex] = ox;
23446                                }
23447                        }
23448                        break;
23449                case Dataset.ARRAYFLOAT32:
23450                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
23451                        if (is == 1) {
23452                                if (it.isOutputDouble()) {
23453                                        while (it.hasNext()) {
23454                                                final double ix = it.aDouble;
23455                                                float ox;
23456                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23457                                                oaf32data[it.oIndex] = ox;
23458                                        }
23459                                } else {
23460                                        while (it.hasNext()) {
23461                                                final long ix = it.aLong;
23462                                                float ox;
23463                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23464                                                oaf32data[it.oIndex] = ox;
23465                                        }
23466                                }
23467                        } else if (as == 1) {
23468                                if (it.isOutputDouble()) {
23469                                        while (it.hasNext()) {
23470                                                final double ix = it.aDouble;
23471                                                float ox;
23472                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23473                                                for (int j = 0; j < is; j++) {
23474                                                        oaf32data[it.oIndex + j] = ox;
23475                                                }
23476                                        }
23477                                } else {
23478                                        while (it.hasNext()) {
23479                                                final long ix = it.aLong;
23480                                                float ox;
23481                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23482                                                for (int j = 0; j < is; j++) {
23483                                                        oaf32data[it.oIndex + j] = ox;
23484                                                }
23485                                        }
23486                                }
23487                        } else {
23488                                if (it.isOutputDouble()) {
23489                                        while (it.hasNext()) {
23490                                                for (int j = 0; j < is; j++) {
23491                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23492                                                        float ox;
23493                                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23494                                                        oaf32data[it.oIndex + j] = ox;
23495                                                }
23496                                        }
23497                                } else {
23498                                        while (it.hasNext()) {
23499                                                for (int j = 0; j < is; j++) {
23500                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23501                                                        float ox;
23502                                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23503                                                        oaf32data[it.oIndex + j] = ox;
23504                                                }
23505                                        }
23506                                }
23507                        }
23508                        break;
23509                case Dataset.ARRAYFLOAT64:
23510                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
23511                        if (is == 1) {
23512                                if (it.isOutputDouble()) {
23513                                        while (it.hasNext()) {
23514                                                final double ix = it.aDouble;
23515                                                double ox;
23516                                                ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23517                                                oaf64data[it.oIndex] = ox;
23518                                        }
23519                                } else {
23520                                        while (it.hasNext()) {
23521                                                final long ix = it.aLong;
23522                                                double ox;
23523                                                ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23524                                                oaf64data[it.oIndex] = ox;
23525                                        }
23526                                }
23527                        } else if (as == 1) {
23528                                if (it.isOutputDouble()) {
23529                                        while (it.hasNext()) {
23530                                                final double ix = it.aDouble;
23531                                                double ox;
23532                                                ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23533                                                for (int j = 0; j < is; j++) {
23534                                                        oaf64data[it.oIndex + j] = ox;
23535                                                }
23536                                        }
23537                                } else {
23538                                        while (it.hasNext()) {
23539                                                final long ix = it.aLong;
23540                                                double ox;
23541                                                ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23542                                                for (int j = 0; j < is; j++) {
23543                                                        oaf64data[it.oIndex + j] = ox;
23544                                                }
23545                                        }
23546                                }
23547                        } else {
23548                                if (it.isOutputDouble()) {
23549                                        while (it.hasNext()) {
23550                                                for (int j = 0; j < is; j++) {
23551                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23552                                                        double ox;
23553                                                        ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23554                                                        oaf64data[it.oIndex + j] = ox;
23555                                                }
23556                                        }
23557                                } else {
23558                                        while (it.hasNext()) {
23559                                                for (int j = 0; j < is; j++) {
23560                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23561                                                        double ox;
23562                                                        ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23563                                                        oaf64data[it.oIndex + j] = ox;
23564                                                }
23565                                        }
23566                                }
23567                        }
23568                        break;
23569                case Dataset.COMPLEX64:
23570                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
23571                        if (!da.isComplex()) {
23572                                if (it.isOutputDouble()) {
23573                                        final double iy = 0;
23574                                        while (it.hasNext()) {
23575                                                final double ix = it.aDouble;
23576                                                Complex tz;
23577                                                float ox;
23578                                                float oy;
23579                                                tz = new Complex(-iy, ix).asin();
23580                                                ox = (float) (tz.getImaginary());
23581                                                oy = (float) (-tz.getReal());
23582                                                oc64data[it.oIndex] = ox;
23583                                                oc64data[it.oIndex + 1] = oy;
23584                                        }
23585                                } else {
23586                                        final long iy = 0;
23587                                        while (it.hasNext()) {
23588                                                final long ix = it.aLong;
23589                                                Complex tz;
23590                                                float ox;
23591                                                float oy;
23592                                                tz = new Complex(-iy, ix).asin();
23593                                                ox = (float) toLong(tz.getImaginary());
23594                                                oy = (float) toLong(-tz.getReal());
23595                                                oc64data[it.oIndex] = ox;
23596                                                oc64data[it.oIndex + 1] = oy;
23597                                        }
23598                                }
23599                        } else {
23600                                while (it.hasNext()) {
23601                                        final double ix = it.aDouble;
23602                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
23603                                        Complex tz;
23604                                        float ox;
23605                                        float oy;
23606                                        tz = new Complex(-iy, ix).asin();
23607                                        ox = (float) (tz.getImaginary());
23608                                        oy = (float) (-tz.getReal());
23609                                        oc64data[it.oIndex] = ox;
23610                                        oc64data[it.oIndex + 1] = oy;
23611                                }
23612                        }
23613                        break;
23614                case Dataset.COMPLEX128:
23615                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
23616                        if (!da.isComplex()) {
23617                                if (it.isOutputDouble()) {
23618                                        final double iy = 0;
23619                                        while (it.hasNext()) {
23620                                                final double ix = it.aDouble;
23621                                                Complex tz;
23622                                                double ox;
23623                                                double oy;
23624                                                tz = new Complex(-iy, ix).asin();
23625                                                ox = (tz.getImaginary());
23626                                                oy = (-tz.getReal());
23627                                                oc128data[it.oIndex] = ox;
23628                                                oc128data[it.oIndex + 1] = oy;
23629                                        }
23630                                } else {
23631                                        final long iy = 0;
23632                                        while (it.hasNext()) {
23633                                                final long ix = it.aLong;
23634                                                Complex tz;
23635                                                double ox;
23636                                                double oy;
23637                                                tz = new Complex(-iy, ix).asin();
23638                                                ox = (tz.getImaginary());
23639                                                oy = (-tz.getReal());
23640                                                oc128data[it.oIndex] = ox;
23641                                                oc128data[it.oIndex + 1] = oy;
23642                                        }
23643                                }
23644                        } else {
23645                                while (it.hasNext()) {
23646                                        final double ix = it.aDouble;
23647                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
23648                                        Complex tz;
23649                                        double ox;
23650                                        double oy;
23651                                        tz = new Complex(-iy, ix).asin();
23652                                        ox = (tz.getImaginary());
23653                                        oy = (-tz.getReal());
23654                                        oc128data[it.oIndex] = ox;
23655                                        oc128data[it.oIndex + 1] = oy;
23656                                }
23657                        }
23658                        break;
23659                default:
23660                        throw new IllegalArgumentException("arcsinh supports integer, compound integer, real, compound real, complex datasets only");
23661                }
23662
23663                addFunctionName(result, "arcsinh");
23664                return result;
23665        }
23666
23667        /**
23668         * arccosh - evaluate the inverse hyperbolic cosine function on each element of the dataset
23669         * @param a
23670         * @return dataset
23671         */
23672        public static Dataset arccosh(final Object a) {
23673                return arccosh(a, null);
23674        }
23675
23676        /**
23677         * arccosh - evaluate the inverse hyperbolic cosine function on each element of the dataset
23678         * @param a
23679         * @param o output can be null - in which case, a new dataset is created
23680         * @return dataset
23681         */
23682        public static Dataset arccosh(final Object a, final Dataset o) {
23683                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
23684                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
23685                final Dataset result = it.getOutput();
23686                if (!result.isComplex()) {
23687                        if (da.isComplex()) {
23688                                da = da.getRealView();
23689                                it = new SingleInputBroadcastIterator(da, result, true);
23690                        }
23691                }
23692                final int is = result.getElementsPerItem();
23693                final int as = da.getElementsPerItem();
23694                final int dt = result.getDType();
23695
23696                switch(dt) {
23697                case Dataset.INT8:
23698                        final byte[] oi8data = ((ByteDataset) result).getData();
23699                        if (it.isOutputDouble()) {
23700                                while (it.hasNext()) {
23701                                        final double ix = it.aDouble;
23702                                        byte ox;
23703                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23704                                        oi8data[it.oIndex] = ox;
23705                                }
23706                        } else {
23707                                while (it.hasNext()) {
23708                                        final long ix = it.aLong;
23709                                        byte ox;
23710                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23711                                        oi8data[it.oIndex] = ox;
23712                                }
23713                        }
23714                        break;
23715                case Dataset.INT16:
23716                        final short[] oi16data = ((ShortDataset) result).getData();
23717                        if (it.isOutputDouble()) {
23718                                while (it.hasNext()) {
23719                                        final double ix = it.aDouble;
23720                                        short ox;
23721                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23722                                        oi16data[it.oIndex] = ox;
23723                                }
23724                        } else {
23725                                while (it.hasNext()) {
23726                                        final long ix = it.aLong;
23727                                        short ox;
23728                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23729                                        oi16data[it.oIndex] = ox;
23730                                }
23731                        }
23732                        break;
23733                case Dataset.INT64:
23734                        final long[] oi64data = ((LongDataset) result).getData();
23735                        if (it.isOutputDouble()) {
23736                                while (it.hasNext()) {
23737                                        final double ix = it.aDouble;
23738                                        long ox;
23739                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23740                                        oi64data[it.oIndex] = ox;
23741                                }
23742                        } else {
23743                                while (it.hasNext()) {
23744                                        final long ix = it.aLong;
23745                                        long ox;
23746                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23747                                        oi64data[it.oIndex] = ox;
23748                                }
23749                        }
23750                        break;
23751                case Dataset.INT32:
23752                        final int[] oi32data = ((IntegerDataset) result).getData();
23753                        if (it.isOutputDouble()) {
23754                                while (it.hasNext()) {
23755                                        final double ix = it.aDouble;
23756                                        int ox;
23757                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23758                                        oi32data[it.oIndex] = ox;
23759                                }
23760                        } else {
23761                                while (it.hasNext()) {
23762                                        final long ix = it.aLong;
23763                                        int ox;
23764                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23765                                        oi32data[it.oIndex] = ox;
23766                                }
23767                        }
23768                        break;
23769                case Dataset.ARRAYINT8:
23770                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
23771                        if (is == 1) {
23772                                if (it.isOutputDouble()) {
23773                                        while (it.hasNext()) {
23774                                                final double ix = it.aDouble;
23775                                                byte ox;
23776                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23777                                                oai8data[it.oIndex] = ox;
23778                                        }
23779                                } else {
23780                                        while (it.hasNext()) {
23781                                                final long ix = it.aLong;
23782                                                byte ox;
23783                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23784                                                oai8data[it.oIndex] = ox;
23785                                        }
23786                                }
23787                        } else if (as == 1) {
23788                                if (it.isOutputDouble()) {
23789                                        while (it.hasNext()) {
23790                                                final double ix = it.aDouble;
23791                                                byte ox;
23792                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23793                                                for (int j = 0; j < is; j++) {
23794                                                        oai8data[it.oIndex + j] = ox;
23795                                                }
23796                                        }
23797                                } else {
23798                                        while (it.hasNext()) {
23799                                                final long ix = it.aLong;
23800                                                byte ox;
23801                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23802                                                for (int j = 0; j < is; j++) {
23803                                                        oai8data[it.oIndex + j] = ox;
23804                                                }
23805                                        }
23806                                }
23807                        } else {
23808                                if (it.isOutputDouble()) {
23809                                        while (it.hasNext()) {
23810                                                for (int j = 0; j < is; j++) {
23811                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23812                                                        byte ox;
23813                                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23814                                                        oai8data[it.oIndex + j] = ox;
23815                                                }
23816                                        }
23817                                } else {
23818                                        while (it.hasNext()) {
23819                                                for (int j = 0; j < is; j++) {
23820                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23821                                                        byte ox;
23822                                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23823                                                        oai8data[it.oIndex + j] = ox;
23824                                                }
23825                                        }
23826                                }
23827                        }
23828                        break;
23829                case Dataset.ARRAYINT16:
23830                        final short[] oai16data = ((CompoundShortDataset) result).getData();
23831                        if (is == 1) {
23832                                if (it.isOutputDouble()) {
23833                                        while (it.hasNext()) {
23834                                                final double ix = it.aDouble;
23835                                                short ox;
23836                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23837                                                oai16data[it.oIndex] = ox;
23838                                        }
23839                                } else {
23840                                        while (it.hasNext()) {
23841                                                final long ix = it.aLong;
23842                                                short ox;
23843                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23844                                                oai16data[it.oIndex] = ox;
23845                                        }
23846                                }
23847                        } else if (as == 1) {
23848                                if (it.isOutputDouble()) {
23849                                        while (it.hasNext()) {
23850                                                final double ix = it.aDouble;
23851                                                short ox;
23852                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23853                                                for (int j = 0; j < is; j++) {
23854                                                        oai16data[it.oIndex + j] = ox;
23855                                                }
23856                                        }
23857                                } else {
23858                                        while (it.hasNext()) {
23859                                                final long ix = it.aLong;
23860                                                short ox;
23861                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23862                                                for (int j = 0; j < is; j++) {
23863                                                        oai16data[it.oIndex + j] = ox;
23864                                                }
23865                                        }
23866                                }
23867                        } else {
23868                                if (it.isOutputDouble()) {
23869                                        while (it.hasNext()) {
23870                                                for (int j = 0; j < is; j++) {
23871                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23872                                                        short ox;
23873                                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23874                                                        oai16data[it.oIndex + j] = ox;
23875                                                }
23876                                        }
23877                                } else {
23878                                        while (it.hasNext()) {
23879                                                for (int j = 0; j < is; j++) {
23880                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23881                                                        short ox;
23882                                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23883                                                        oai16data[it.oIndex + j] = ox;
23884                                                }
23885                                        }
23886                                }
23887                        }
23888                        break;
23889                case Dataset.ARRAYINT64:
23890                        final long[] oai64data = ((CompoundLongDataset) result).getData();
23891                        if (is == 1) {
23892                                if (it.isOutputDouble()) {
23893                                        while (it.hasNext()) {
23894                                                final double ix = it.aDouble;
23895                                                long ox;
23896                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23897                                                oai64data[it.oIndex] = ox;
23898                                        }
23899                                } else {
23900                                        while (it.hasNext()) {
23901                                                final long ix = it.aLong;
23902                                                long ox;
23903                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23904                                                oai64data[it.oIndex] = ox;
23905                                        }
23906                                }
23907                        } else if (as == 1) {
23908                                if (it.isOutputDouble()) {
23909                                        while (it.hasNext()) {
23910                                                final double ix = it.aDouble;
23911                                                long ox;
23912                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23913                                                for (int j = 0; j < is; j++) {
23914                                                        oai64data[it.oIndex + j] = ox;
23915                                                }
23916                                        }
23917                                } else {
23918                                        while (it.hasNext()) {
23919                                                final long ix = it.aLong;
23920                                                long ox;
23921                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23922                                                for (int j = 0; j < is; j++) {
23923                                                        oai64data[it.oIndex + j] = ox;
23924                                                }
23925                                        }
23926                                }
23927                        } else {
23928                                if (it.isOutputDouble()) {
23929                                        while (it.hasNext()) {
23930                                                for (int j = 0; j < is; j++) {
23931                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23932                                                        long ox;
23933                                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23934                                                        oai64data[it.oIndex + j] = ox;
23935                                                }
23936                                        }
23937                                } else {
23938                                        while (it.hasNext()) {
23939                                                for (int j = 0; j < is; j++) {
23940                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23941                                                        long ox;
23942                                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23943                                                        oai64data[it.oIndex + j] = ox;
23944                                                }
23945                                        }
23946                                }
23947                        }
23948                        break;
23949                case Dataset.ARRAYINT32:
23950                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
23951                        if (is == 1) {
23952                                if (it.isOutputDouble()) {
23953                                        while (it.hasNext()) {
23954                                                final double ix = it.aDouble;
23955                                                int ox;
23956                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23957                                                oai32data[it.oIndex] = ox;
23958                                        }
23959                                } else {
23960                                        while (it.hasNext()) {
23961                                                final long ix = it.aLong;
23962                                                int ox;
23963                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23964                                                oai32data[it.oIndex] = ox;
23965                                        }
23966                                }
23967                        } else if (as == 1) {
23968                                if (it.isOutputDouble()) {
23969                                        while (it.hasNext()) {
23970                                                final double ix = it.aDouble;
23971                                                int ox;
23972                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23973                                                for (int j = 0; j < is; j++) {
23974                                                        oai32data[it.oIndex + j] = ox;
23975                                                }
23976                                        }
23977                                } else {
23978                                        while (it.hasNext()) {
23979                                                final long ix = it.aLong;
23980                                                int ox;
23981                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23982                                                for (int j = 0; j < is; j++) {
23983                                                        oai32data[it.oIndex + j] = ox;
23984                                                }
23985                                        }
23986                                }
23987                        } else {
23988                                if (it.isOutputDouble()) {
23989                                        while (it.hasNext()) {
23990                                                for (int j = 0; j < is; j++) {
23991                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23992                                                        int ox;
23993                                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23994                                                        oai32data[it.oIndex + j] = ox;
23995                                                }
23996                                        }
23997                                } else {
23998                                        while (it.hasNext()) {
23999                                                for (int j = 0; j < is; j++) {
24000                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24001                                                        int ox;
24002                                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
24003                                                        oai32data[it.oIndex + j] = ox;
24004                                                }
24005                                        }
24006                                }
24007                        }
24008                        break;
24009                case Dataset.FLOAT32:
24010                        final float[] of32data = ((FloatDataset) result).getData();
24011                        if (it.isOutputDouble()) {
24012                                while (it.hasNext()) {
24013                                        final double ix = it.aDouble;
24014                                        float ox;
24015                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
24016                                        of32data[it.oIndex] = ox;
24017                                }
24018                        } else {
24019                                while (it.hasNext()) {
24020                                        final long ix = it.aLong;
24021                                        float ox;
24022                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
24023                                        of32data[it.oIndex] = ox;
24024                                }
24025                        }
24026                        break;
24027                case Dataset.FLOAT64:
24028                        final double[] of64data = ((DoubleDataset) result).getData();
24029                        if (it.isOutputDouble()) {
24030                                while (it.hasNext()) {
24031                                        final double ix = it.aDouble;
24032                                        double ox;
24033                                        ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
24034                                        of64data[it.oIndex] = ox;
24035                                }
24036                        } else {
24037                                while (it.hasNext()) {
24038                                        final long ix = it.aLong;
24039                                        double ox;
24040                                        ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
24041                                        of64data[it.oIndex] = ox;
24042                                }
24043                        }
24044                        break;
24045                case Dataset.ARRAYFLOAT32:
24046                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
24047                        if (is == 1) {
24048                                if (it.isOutputDouble()) {
24049                                        while (it.hasNext()) {
24050                                                final double ix = it.aDouble;
24051                                                float ox;
24052                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
24053                                                oaf32data[it.oIndex] = ox;
24054                                        }
24055                                } else {
24056                                        while (it.hasNext()) {
24057                                                final long ix = it.aLong;
24058                                                float ox;
24059                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
24060                                                oaf32data[it.oIndex] = ox;
24061                                        }
24062                                }
24063                        } else if (as == 1) {
24064                                if (it.isOutputDouble()) {
24065                                        while (it.hasNext()) {
24066                                                final double ix = it.aDouble;
24067                                                float ox;
24068                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
24069                                                for (int j = 0; j < is; j++) {
24070                                                        oaf32data[it.oIndex + j] = ox;
24071                                                }
24072                                        }
24073                                } else {
24074                                        while (it.hasNext()) {
24075                                                final long ix = it.aLong;
24076                                                float ox;
24077                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
24078                                                for (int j = 0; j < is; j++) {
24079                                                        oaf32data[it.oIndex + j] = ox;
24080                                                }
24081                                        }
24082                                }
24083                        } else {
24084                                if (it.isOutputDouble()) {
24085                                        while (it.hasNext()) {
24086                                                for (int j = 0; j < is; j++) {
24087                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24088                                                        float ox;
24089                                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
24090                                                        oaf32data[it.oIndex + j] = ox;
24091                                                }
24092                                        }
24093                                } else {
24094                                        while (it.hasNext()) {
24095                                                for (int j = 0; j < is; j++) {
24096                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24097                                                        float ox;
24098                                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
24099                                                        oaf32data[it.oIndex + j] = ox;
24100                                                }
24101                                        }
24102                                }
24103                        }
24104                        break;
24105                case Dataset.ARRAYFLOAT64:
24106                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
24107                        if (is == 1) {
24108                                if (it.isOutputDouble()) {
24109                                        while (it.hasNext()) {
24110                                                final double ix = it.aDouble;
24111                                                double ox;
24112                                                ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
24113                                                oaf64data[it.oIndex] = ox;
24114                                        }
24115                                } else {
24116                                        while (it.hasNext()) {
24117                                                final long ix = it.aLong;
24118                                                double ox;
24119                                                ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
24120                                                oaf64data[it.oIndex] = ox;
24121                                        }
24122                                }
24123                        } else if (as == 1) {
24124                                if (it.isOutputDouble()) {
24125                                        while (it.hasNext()) {
24126                                                final double ix = it.aDouble;
24127                                                double ox;
24128                                                ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
24129                                                for (int j = 0; j < is; j++) {
24130                                                        oaf64data[it.oIndex + j] = ox;
24131                                                }
24132                                        }
24133                                } else {
24134                                        while (it.hasNext()) {
24135                                                final long ix = it.aLong;
24136                                                double ox;
24137                                                ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
24138                                                for (int j = 0; j < is; j++) {
24139                                                        oaf64data[it.oIndex + j] = ox;
24140                                                }
24141                                        }
24142                                }
24143                        } else {
24144                                if (it.isOutputDouble()) {
24145                                        while (it.hasNext()) {
24146                                                for (int j = 0; j < is; j++) {
24147                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24148                                                        double ox;
24149                                                        ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
24150                                                        oaf64data[it.oIndex + j] = ox;
24151                                                }
24152                                        }
24153                                } else {
24154                                        while (it.hasNext()) {
24155                                                for (int j = 0; j < is; j++) {
24156                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24157                                                        double ox;
24158                                                        ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
24159                                                        oaf64data[it.oIndex + j] = ox;
24160                                                }
24161                                        }
24162                                }
24163                        }
24164                        break;
24165                case Dataset.COMPLEX64:
24166                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
24167                        if (!da.isComplex()) {
24168                                if (it.isOutputDouble()) {
24169                                        final double iy = 0;
24170                                        while (it.hasNext()) {
24171                                                final double ix = it.aDouble;
24172                                                Complex tz;
24173                                                float ox;
24174                                                float oy;
24175                                                tz = new Complex(-iy, ix).acos();
24176                                                ox = (float) (tz.getImaginary());
24177                                                oy = (float) (-tz.getReal());
24178                                                oc64data[it.oIndex] = ox;
24179                                                oc64data[it.oIndex + 1] = oy;
24180                                        }
24181                                } else {
24182                                        final long iy = 0;
24183                                        while (it.hasNext()) {
24184                                                final long ix = it.aLong;
24185                                                Complex tz;
24186                                                float ox;
24187                                                float oy;
24188                                                tz = new Complex(-iy, ix).acos();
24189                                                ox = (float) toLong(tz.getImaginary());
24190                                                oy = (float) toLong(-tz.getReal());
24191                                                oc64data[it.oIndex] = ox;
24192                                                oc64data[it.oIndex + 1] = oy;
24193                                        }
24194                                }
24195                        } else {
24196                                while (it.hasNext()) {
24197                                        final double ix = it.aDouble;
24198                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
24199                                        Complex tz;
24200                                        float ox;
24201                                        float oy;
24202                                        tz = new Complex(-iy, ix).acos();
24203                                        ox = (float) (tz.getImaginary());
24204                                        oy = (float) (-tz.getReal());
24205                                        oc64data[it.oIndex] = ox;
24206                                        oc64data[it.oIndex + 1] = oy;
24207                                }
24208                        }
24209                        break;
24210                case Dataset.COMPLEX128:
24211                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
24212                        if (!da.isComplex()) {
24213                                if (it.isOutputDouble()) {
24214                                        final double iy = 0;
24215                                        while (it.hasNext()) {
24216                                                final double ix = it.aDouble;
24217                                                Complex tz;
24218                                                double ox;
24219                                                double oy;
24220                                                tz = new Complex(-iy, ix).acos();
24221                                                ox = (tz.getImaginary());
24222                                                oy = (-tz.getReal());
24223                                                oc128data[it.oIndex] = ox;
24224                                                oc128data[it.oIndex + 1] = oy;
24225                                        }
24226                                } else {
24227                                        final long iy = 0;
24228                                        while (it.hasNext()) {
24229                                                final long ix = it.aLong;
24230                                                Complex tz;
24231                                                double ox;
24232                                                double oy;
24233                                                tz = new Complex(-iy, ix).acos();
24234                                                ox = (tz.getImaginary());
24235                                                oy = (-tz.getReal());
24236                                                oc128data[it.oIndex] = ox;
24237                                                oc128data[it.oIndex + 1] = oy;
24238                                        }
24239                                }
24240                        } else {
24241                                while (it.hasNext()) {
24242                                        final double ix = it.aDouble;
24243                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
24244                                        Complex tz;
24245                                        double ox;
24246                                        double oy;
24247                                        tz = new Complex(-iy, ix).acos();
24248                                        ox = (tz.getImaginary());
24249                                        oy = (-tz.getReal());
24250                                        oc128data[it.oIndex] = ox;
24251                                        oc128data[it.oIndex + 1] = oy;
24252                                }
24253                        }
24254                        break;
24255                default:
24256                        throw new IllegalArgumentException("arccosh supports integer, compound integer, real, compound real, complex datasets only");
24257                }
24258
24259                addFunctionName(result, "arccosh");
24260                return result;
24261        }
24262
24263        /**
24264         * arctanh - evaluate the inverse hyperbolic tangent function on each element of the dataset
24265         * @param a
24266         * @return dataset
24267         */
24268        public static Dataset arctanh(final Object a) {
24269                return arctanh(a, null);
24270        }
24271
24272        /**
24273         * arctanh - evaluate the inverse hyperbolic tangent function on each element of the dataset
24274         * @param a
24275         * @param o output can be null - in which case, a new dataset is created
24276         * @return dataset
24277         */
24278        public static Dataset arctanh(final Object a, final Dataset o) {
24279                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
24280                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
24281                final Dataset result = it.getOutput();
24282                if (!result.isComplex()) {
24283                        if (da.isComplex()) {
24284                                da = da.getRealView();
24285                                it = new SingleInputBroadcastIterator(da, result, true);
24286                        }
24287                }
24288                final int is = result.getElementsPerItem();
24289                final int as = da.getElementsPerItem();
24290                final int dt = result.getDType();
24291
24292                switch(dt) {
24293                case Dataset.INT8:
24294                        final byte[] oi8data = ((ByteDataset) result).getData();
24295                        if (it.isOutputDouble()) {
24296                                while (it.hasNext()) {
24297                                        final double ix = it.aDouble;
24298                                        byte ox;
24299                                        ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24300                                        oi8data[it.oIndex] = ox;
24301                                }
24302                        } else {
24303                                while (it.hasNext()) {
24304                                        final long ix = it.aLong;
24305                                        byte ox;
24306                                        ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24307                                        oi8data[it.oIndex] = ox;
24308                                }
24309                        }
24310                        break;
24311                case Dataset.INT16:
24312                        final short[] oi16data = ((ShortDataset) result).getData();
24313                        if (it.isOutputDouble()) {
24314                                while (it.hasNext()) {
24315                                        final double ix = it.aDouble;
24316                                        short ox;
24317                                        ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24318                                        oi16data[it.oIndex] = ox;
24319                                }
24320                        } else {
24321                                while (it.hasNext()) {
24322                                        final long ix = it.aLong;
24323                                        short ox;
24324                                        ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24325                                        oi16data[it.oIndex] = ox;
24326                                }
24327                        }
24328                        break;
24329                case Dataset.INT64:
24330                        final long[] oi64data = ((LongDataset) result).getData();
24331                        if (it.isOutputDouble()) {
24332                                while (it.hasNext()) {
24333                                        final double ix = it.aDouble;
24334                                        long ox;
24335                                        ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24336                                        oi64data[it.oIndex] = ox;
24337                                }
24338                        } else {
24339                                while (it.hasNext()) {
24340                                        final long ix = it.aLong;
24341                                        long ox;
24342                                        ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24343                                        oi64data[it.oIndex] = ox;
24344                                }
24345                        }
24346                        break;
24347                case Dataset.INT32:
24348                        final int[] oi32data = ((IntegerDataset) result).getData();
24349                        if (it.isOutputDouble()) {
24350                                while (it.hasNext()) {
24351                                        final double ix = it.aDouble;
24352                                        int ox;
24353                                        ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24354                                        oi32data[it.oIndex] = ox;
24355                                }
24356                        } else {
24357                                while (it.hasNext()) {
24358                                        final long ix = it.aLong;
24359                                        int ox;
24360                                        ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24361                                        oi32data[it.oIndex] = ox;
24362                                }
24363                        }
24364                        break;
24365                case Dataset.ARRAYINT8:
24366                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
24367                        if (is == 1) {
24368                                if (it.isOutputDouble()) {
24369                                        while (it.hasNext()) {
24370                                                final double ix = it.aDouble;
24371                                                byte ox;
24372                                                ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24373                                                oai8data[it.oIndex] = ox;
24374                                        }
24375                                } else {
24376                                        while (it.hasNext()) {
24377                                                final long ix = it.aLong;
24378                                                byte ox;
24379                                                ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24380                                                oai8data[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                                                byte ox;
24388                                                ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24389                                                for (int j = 0; j < is; j++) {
24390                                                        oai8data[it.oIndex + j] = ox;
24391                                                }
24392                                        }
24393                                } else {
24394                                        while (it.hasNext()) {
24395                                                final long ix = it.aLong;
24396                                                byte ox;
24397                                                ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24398                                                for (int j = 0; j < is; j++) {
24399                                                        oai8data[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                                                        byte ox;
24409                                                        ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24410                                                        oai8data[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                                                        byte ox;
24418                                                        ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24419                                                        oai8data[it.oIndex + j] = ox;
24420                                                }
24421                                        }
24422                                }
24423                        }
24424                        break;
24425                case Dataset.ARRAYINT16:
24426                        final short[] oai16data = ((CompoundShortDataset) result).getData();
24427                        if (is == 1) {
24428                                if (it.isOutputDouble()) {
24429                                        while (it.hasNext()) {
24430                                                final double ix = it.aDouble;
24431                                                short ox;
24432                                                ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24433                                                oai16data[it.oIndex] = ox;
24434                                        }
24435                                } else {
24436                                        while (it.hasNext()) {
24437                                                final long ix = it.aLong;
24438                                                short ox;
24439                                                ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24440                                                oai16data[it.oIndex] = ox;
24441                                        }
24442                                }
24443                        } else if (as == 1) {
24444                                if (it.isOutputDouble()) {
24445                                        while (it.hasNext()) {
24446                                                final double ix = it.aDouble;
24447                                                short ox;
24448                                                ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24449                                                for (int j = 0; j < is; j++) {
24450                                                        oai16data[it.oIndex + j] = ox;
24451                                                }
24452                                        }
24453                                } else {
24454                                        while (it.hasNext()) {
24455                                                final long ix = it.aLong;
24456                                                short ox;
24457                                                ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24458                                                for (int j = 0; j < is; j++) {
24459                                                        oai16data[it.oIndex + j] = ox;
24460                                                }
24461                                        }
24462                                }
24463                        } else {
24464                                if (it.isOutputDouble()) {
24465                                        while (it.hasNext()) {
24466                                                for (int j = 0; j < is; j++) {
24467                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24468                                                        short ox;
24469                                                        ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24470                                                        oai16data[it.oIndex + j] = ox;
24471                                                }
24472                                        }
24473                                } else {
24474                                        while (it.hasNext()) {
24475                                                for (int j = 0; j < is; j++) {
24476                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24477                                                        short ox;
24478                                                        ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24479                                                        oai16data[it.oIndex + j] = ox;
24480                                                }
24481                                        }
24482                                }
24483                        }
24484                        break;
24485                case Dataset.ARRAYINT64:
24486                        final long[] oai64data = ((CompoundLongDataset) result).getData();
24487                        if (is == 1) {
24488                                if (it.isOutputDouble()) {
24489                                        while (it.hasNext()) {
24490                                                final double ix = it.aDouble;
24491                                                long ox;
24492                                                ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24493                                                oai64data[it.oIndex] = ox;
24494                                        }
24495                                } else {
24496                                        while (it.hasNext()) {
24497                                                final long ix = it.aLong;
24498                                                long ox;
24499                                                ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24500                                                oai64data[it.oIndex] = ox;
24501                                        }
24502                                }
24503                        } else if (as == 1) {
24504                                if (it.isOutputDouble()) {
24505                                        while (it.hasNext()) {
24506                                                final double ix = it.aDouble;
24507                                                long ox;
24508                                                ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24509                                                for (int j = 0; j < is; j++) {
24510                                                        oai64data[it.oIndex + j] = ox;
24511                                                }
24512                                        }
24513                                } else {
24514                                        while (it.hasNext()) {
24515                                                final long ix = it.aLong;
24516                                                long ox;
24517                                                ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24518                                                for (int j = 0; j < is; j++) {
24519                                                        oai64data[it.oIndex + j] = ox;
24520                                                }
24521                                        }
24522                                }
24523                        } else {
24524                                if (it.isOutputDouble()) {
24525                                        while (it.hasNext()) {
24526                                                for (int j = 0; j < is; j++) {
24527                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24528                                                        long ox;
24529                                                        ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24530                                                        oai64data[it.oIndex + j] = ox;
24531                                                }
24532                                        }
24533                                } else {
24534                                        while (it.hasNext()) {
24535                                                for (int j = 0; j < is; j++) {
24536                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24537                                                        long ox;
24538                                                        ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24539                                                        oai64data[it.oIndex + j] = ox;
24540                                                }
24541                                        }
24542                                }
24543                        }
24544                        break;
24545                case Dataset.ARRAYINT32:
24546                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
24547                        if (is == 1) {
24548                                if (it.isOutputDouble()) {
24549                                        while (it.hasNext()) {
24550                                                final double ix = it.aDouble;
24551                                                int ox;
24552                                                ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24553                                                oai32data[it.oIndex] = ox;
24554                                        }
24555                                } else {
24556                                        while (it.hasNext()) {
24557                                                final long ix = it.aLong;
24558                                                int ox;
24559                                                ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24560                                                oai32data[it.oIndex] = ox;
24561                                        }
24562                                }
24563                        } else if (as == 1) {
24564                                if (it.isOutputDouble()) {
24565                                        while (it.hasNext()) {
24566                                                final double ix = it.aDouble;
24567                                                int ox;
24568                                                ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24569                                                for (int j = 0; j < is; j++) {
24570                                                        oai32data[it.oIndex + j] = ox;
24571                                                }
24572                                        }
24573                                } else {
24574                                        while (it.hasNext()) {
24575                                                final long ix = it.aLong;
24576                                                int ox;
24577                                                ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24578                                                for (int j = 0; j < is; j++) {
24579                                                        oai32data[it.oIndex + j] = ox;
24580                                                }
24581                                        }
24582                                }
24583                        } else {
24584                                if (it.isOutputDouble()) {
24585                                        while (it.hasNext()) {
24586                                                for (int j = 0; j < is; j++) {
24587                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24588                                                        int ox;
24589                                                        ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24590                                                        oai32data[it.oIndex + j] = ox;
24591                                                }
24592                                        }
24593                                } else {
24594                                        while (it.hasNext()) {
24595                                                for (int j = 0; j < is; j++) {
24596                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24597                                                        int ox;
24598                                                        ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24599                                                        oai32data[it.oIndex + j] = ox;
24600                                                }
24601                                        }
24602                                }
24603                        }
24604                        break;
24605                case Dataset.FLOAT32:
24606                        final float[] of32data = ((FloatDataset) result).getData();
24607                        if (it.isOutputDouble()) {
24608                                while (it.hasNext()) {
24609                                        final double ix = it.aDouble;
24610                                        float ox;
24611                                        ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24612                                        of32data[it.oIndex] = ox;
24613                                }
24614                        } else {
24615                                while (it.hasNext()) {
24616                                        final long ix = it.aLong;
24617                                        float ox;
24618                                        ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24619                                        of32data[it.oIndex] = ox;
24620                                }
24621                        }
24622                        break;
24623                case Dataset.FLOAT64:
24624                        final double[] of64data = ((DoubleDataset) result).getData();
24625                        if (it.isOutputDouble()) {
24626                                while (it.hasNext()) {
24627                                        final double ix = it.aDouble;
24628                                        double ox;
24629                                        ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24630                                        of64data[it.oIndex] = ox;
24631                                }
24632                        } else {
24633                                while (it.hasNext()) {
24634                                        final long ix = it.aLong;
24635                                        double ox;
24636                                        ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24637                                        of64data[it.oIndex] = ox;
24638                                }
24639                        }
24640                        break;
24641                case Dataset.ARRAYFLOAT32:
24642                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
24643                        if (is == 1) {
24644                                if (it.isOutputDouble()) {
24645                                        while (it.hasNext()) {
24646                                                final double ix = it.aDouble;
24647                                                float ox;
24648                                                ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24649                                                oaf32data[it.oIndex] = ox;
24650                                        }
24651                                } else {
24652                                        while (it.hasNext()) {
24653                                                final long ix = it.aLong;
24654                                                float ox;
24655                                                ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24656                                                oaf32data[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                                                float ox;
24664                                                ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24665                                                for (int j = 0; j < is; j++) {
24666                                                        oaf32data[it.oIndex + j] = ox;
24667                                                }
24668                                        }
24669                                } else {
24670                                        while (it.hasNext()) {
24671                                                final long ix = it.aLong;
24672                                                float ox;
24673                                                ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24674                                                for (int j = 0; j < is; j++) {
24675                                                        oaf32data[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                                                        float ox;
24685                                                        ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24686                                                        oaf32data[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                                                        float ox;
24694                                                        ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24695                                                        oaf32data[it.oIndex + j] = ox;
24696                                                }
24697                                        }
24698                                }
24699                        }
24700                        break;
24701                case Dataset.ARRAYFLOAT64:
24702                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
24703                        if (is == 1) {
24704                                if (it.isOutputDouble()) {
24705                                        while (it.hasNext()) {
24706                                                final double ix = it.aDouble;
24707                                                double ox;
24708                                                ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24709                                                oaf64data[it.oIndex] = ox;
24710                                        }
24711                                } else {
24712                                        while (it.hasNext()) {
24713                                                final long ix = it.aLong;
24714                                                double ox;
24715                                                ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24716                                                oaf64data[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                                                double ox;
24724                                                ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24725                                                for (int j = 0; j < is; j++) {
24726                                                        oaf64data[it.oIndex + j] = ox;
24727                                                }
24728                                        }
24729                                } else {
24730                                        while (it.hasNext()) {
24731                                                final long ix = it.aLong;
24732                                                double ox;
24733                                                ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24734                                                for (int j = 0; j < is; j++) {
24735                                                        oaf64data[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                                                        double ox;
24745                                                        ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24746                                                        oaf64data[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                                                        double ox;
24754                                                        ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24755                                                        oaf64data[it.oIndex + j] = ox;
24756                                                }
24757                                        }
24758                                }
24759                        }
24760                        break;
24761                case Dataset.COMPLEX64:
24762                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
24763                        if (!da.isComplex()) {
24764                                if (it.isOutputDouble()) {
24765                                        final double iy = 0;
24766                                        while (it.hasNext()) {
24767                                                final double ix = it.aDouble;
24768                                                Complex tz;
24769                                                float ox;
24770                                                float oy;
24771                                                tz = new Complex(-iy, ix).atan();
24772                                                ox = (float) (tz.getImaginary());
24773                                                oy = (float) (-tz.getReal());
24774                                                oc64data[it.oIndex] = ox;
24775                                                oc64data[it.oIndex + 1] = oy;
24776                                        }
24777                                } else {
24778                                        final long iy = 0;
24779                                        while (it.hasNext()) {
24780                                                final long ix = it.aLong;
24781                                                Complex tz;
24782                                                float ox;
24783                                                float oy;
24784                                                tz = new Complex(-iy, ix).atan();
24785                                                ox = (float) toLong(tz.getImaginary());
24786                                                oy = (float) toLong(-tz.getReal());
24787                                                oc64data[it.oIndex] = ox;
24788                                                oc64data[it.oIndex + 1] = oy;
24789                                        }
24790                                }
24791                        } else {
24792                                while (it.hasNext()) {
24793                                        final double ix = it.aDouble;
24794                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
24795                                        Complex tz;
24796                                        float ox;
24797                                        float oy;
24798                                        tz = new Complex(-iy, ix).atan();
24799                                        ox = (float) (tz.getImaginary());
24800                                        oy = (float) (-tz.getReal());
24801                                        oc64data[it.oIndex] = ox;
24802                                        oc64data[it.oIndex + 1] = oy;
24803                                }
24804                        }
24805                        break;
24806                case Dataset.COMPLEX128:
24807                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
24808                        if (!da.isComplex()) {
24809                                if (it.isOutputDouble()) {
24810                                        final double iy = 0;
24811                                        while (it.hasNext()) {
24812                                                final double ix = it.aDouble;
24813                                                Complex tz;
24814                                                double ox;
24815                                                double oy;
24816                                                tz = new Complex(-iy, ix).atan();
24817                                                ox = (tz.getImaginary());
24818                                                oy = (-tz.getReal());
24819                                                oc128data[it.oIndex] = ox;
24820                                                oc128data[it.oIndex + 1] = oy;
24821                                        }
24822                                } else {
24823                                        final long iy = 0;
24824                                        while (it.hasNext()) {
24825                                                final long ix = it.aLong;
24826                                                Complex tz;
24827                                                double ox;
24828                                                double oy;
24829                                                tz = new Complex(-iy, ix).atan();
24830                                                ox = (tz.getImaginary());
24831                                                oy = (-tz.getReal());
24832                                                oc128data[it.oIndex] = ox;
24833                                                oc128data[it.oIndex + 1] = oy;
24834                                        }
24835                                }
24836                        } else {
24837                                while (it.hasNext()) {
24838                                        final double ix = it.aDouble;
24839                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
24840                                        Complex tz;
24841                                        double ox;
24842                                        double oy;
24843                                        tz = new Complex(-iy, ix).atan();
24844                                        ox = (tz.getImaginary());
24845                                        oy = (-tz.getReal());
24846                                        oc128data[it.oIndex] = ox;
24847                                        oc128data[it.oIndex + 1] = oy;
24848                                }
24849                        }
24850                        break;
24851                default:
24852                        throw new IllegalArgumentException("arctanh supports integer, compound integer, real, compound real, complex datasets only");
24853                }
24854
24855                addFunctionName(result, "arctanh");
24856                return result;
24857        }
24858
24859        /**
24860         * log - evaluate the logarithm function on each element of the dataset
24861         * @param a
24862         * @return dataset
24863         */
24864        public static Dataset log(final Object a) {
24865                return log(a, null);
24866        }
24867
24868        /**
24869         * log - evaluate the logarithm function on each element of the dataset
24870         * @param a
24871         * @param o output can be null - in which case, a new dataset is created
24872         * @return dataset
24873         */
24874        public static Dataset log(final Object a, final Dataset o) {
24875                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
24876                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
24877                final Dataset result = it.getOutput();
24878                if (!result.isComplex()) {
24879                        if (da.isComplex()) {
24880                                da = da.getRealView();
24881                                it = new SingleInputBroadcastIterator(da, result, true);
24882                        }
24883                }
24884                final int is = result.getElementsPerItem();
24885                final int as = da.getElementsPerItem();
24886                final int dt = result.getDType();
24887
24888                switch(dt) {
24889                case Dataset.INT8:
24890                        final byte[] oi8data = ((ByteDataset) result).getData();
24891                        if (it.isOutputDouble()) {
24892                                while (it.hasNext()) {
24893                                        final double ix = it.aDouble;
24894                                        byte ox;
24895                                        ox = (byte) toLong(Math.log(ix));
24896                                        oi8data[it.oIndex] = ox;
24897                                }
24898                        } else {
24899                                while (it.hasNext()) {
24900                                        final long ix = it.aLong;
24901                                        byte ox;
24902                                        ox = (byte) toLong(Math.log(ix));
24903                                        oi8data[it.oIndex] = ox;
24904                                }
24905                        }
24906                        break;
24907                case Dataset.INT16:
24908                        final short[] oi16data = ((ShortDataset) result).getData();
24909                        if (it.isOutputDouble()) {
24910                                while (it.hasNext()) {
24911                                        final double ix = it.aDouble;
24912                                        short ox;
24913                                        ox = (short) toLong(Math.log(ix));
24914                                        oi16data[it.oIndex] = ox;
24915                                }
24916                        } else {
24917                                while (it.hasNext()) {
24918                                        final long ix = it.aLong;
24919                                        short ox;
24920                                        ox = (short) toLong(Math.log(ix));
24921                                        oi16data[it.oIndex] = ox;
24922                                }
24923                        }
24924                        break;
24925                case Dataset.INT64:
24926                        final long[] oi64data = ((LongDataset) result).getData();
24927                        if (it.isOutputDouble()) {
24928                                while (it.hasNext()) {
24929                                        final double ix = it.aDouble;
24930                                        long ox;
24931                                        ox = toLong(Math.log(ix));
24932                                        oi64data[it.oIndex] = ox;
24933                                }
24934                        } else {
24935                                while (it.hasNext()) {
24936                                        final long ix = it.aLong;
24937                                        long ox;
24938                                        ox = toLong(Math.log(ix));
24939                                        oi64data[it.oIndex] = ox;
24940                                }
24941                        }
24942                        break;
24943                case Dataset.INT32:
24944                        final int[] oi32data = ((IntegerDataset) result).getData();
24945                        if (it.isOutputDouble()) {
24946                                while (it.hasNext()) {
24947                                        final double ix = it.aDouble;
24948                                        int ox;
24949                                        ox = (int) toLong(Math.log(ix));
24950                                        oi32data[it.oIndex] = ox;
24951                                }
24952                        } else {
24953                                while (it.hasNext()) {
24954                                        final long ix = it.aLong;
24955                                        int ox;
24956                                        ox = (int) toLong(Math.log(ix));
24957                                        oi32data[it.oIndex] = ox;
24958                                }
24959                        }
24960                        break;
24961                case Dataset.ARRAYINT8:
24962                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
24963                        if (is == 1) {
24964                                if (it.isOutputDouble()) {
24965                                        while (it.hasNext()) {
24966                                                final double ix = it.aDouble;
24967                                                byte ox;
24968                                                ox = (byte) toLong(Math.log(ix));
24969                                                oai8data[it.oIndex] = ox;
24970                                        }
24971                                } else {
24972                                        while (it.hasNext()) {
24973                                                final long ix = it.aLong;
24974                                                byte ox;
24975                                                ox = (byte) toLong(Math.log(ix));
24976                                                oai8data[it.oIndex] = ox;
24977                                        }
24978                                }
24979                        } else if (as == 1) {
24980                                if (it.isOutputDouble()) {
24981                                        while (it.hasNext()) {
24982                                                final double ix = it.aDouble;
24983                                                byte ox;
24984                                                ox = (byte) toLong(Math.log(ix));
24985                                                for (int j = 0; j < is; j++) {
24986                                                        oai8data[it.oIndex + j] = ox;
24987                                                }
24988                                        }
24989                                } else {
24990                                        while (it.hasNext()) {
24991                                                final long ix = it.aLong;
24992                                                byte ox;
24993                                                ox = (byte) toLong(Math.log(ix));
24994                                                for (int j = 0; j < is; j++) {
24995                                                        oai8data[it.oIndex + j] = ox;
24996                                                }
24997                                        }
24998                                }
24999                        } else {
25000                                if (it.isOutputDouble()) {
25001                                        while (it.hasNext()) {
25002                                                for (int j = 0; j < is; j++) {
25003                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25004                                                        byte ox;
25005                                                        ox = (byte) toLong(Math.log(ix));
25006                                                        oai8data[it.oIndex + j] = ox;
25007                                                }
25008                                        }
25009                                } else {
25010                                        while (it.hasNext()) {
25011                                                for (int j = 0; j < is; j++) {
25012                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25013                                                        byte ox;
25014                                                        ox = (byte) toLong(Math.log(ix));
25015                                                        oai8data[it.oIndex + j] = ox;
25016                                                }
25017                                        }
25018                                }
25019                        }
25020                        break;
25021                case Dataset.ARRAYINT16:
25022                        final short[] oai16data = ((CompoundShortDataset) result).getData();
25023                        if (is == 1) {
25024                                if (it.isOutputDouble()) {
25025                                        while (it.hasNext()) {
25026                                                final double ix = it.aDouble;
25027                                                short ox;
25028                                                ox = (short) toLong(Math.log(ix));
25029                                                oai16data[it.oIndex] = ox;
25030                                        }
25031                                } else {
25032                                        while (it.hasNext()) {
25033                                                final long ix = it.aLong;
25034                                                short ox;
25035                                                ox = (short) toLong(Math.log(ix));
25036                                                oai16data[it.oIndex] = ox;
25037                                        }
25038                                }
25039                        } else if (as == 1) {
25040                                if (it.isOutputDouble()) {
25041                                        while (it.hasNext()) {
25042                                                final double ix = it.aDouble;
25043                                                short ox;
25044                                                ox = (short) toLong(Math.log(ix));
25045                                                for (int j = 0; j < is; j++) {
25046                                                        oai16data[it.oIndex + j] = ox;
25047                                                }
25048                                        }
25049                                } else {
25050                                        while (it.hasNext()) {
25051                                                final long ix = it.aLong;
25052                                                short ox;
25053                                                ox = (short) toLong(Math.log(ix));
25054                                                for (int j = 0; j < is; j++) {
25055                                                        oai16data[it.oIndex + j] = ox;
25056                                                }
25057                                        }
25058                                }
25059                        } else {
25060                                if (it.isOutputDouble()) {
25061                                        while (it.hasNext()) {
25062                                                for (int j = 0; j < is; j++) {
25063                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25064                                                        short ox;
25065                                                        ox = (short) toLong(Math.log(ix));
25066                                                        oai16data[it.oIndex + j] = ox;
25067                                                }
25068                                        }
25069                                } else {
25070                                        while (it.hasNext()) {
25071                                                for (int j = 0; j < is; j++) {
25072                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25073                                                        short ox;
25074                                                        ox = (short) toLong(Math.log(ix));
25075                                                        oai16data[it.oIndex + j] = ox;
25076                                                }
25077                                        }
25078                                }
25079                        }
25080                        break;
25081                case Dataset.ARRAYINT64:
25082                        final long[] oai64data = ((CompoundLongDataset) result).getData();
25083                        if (is == 1) {
25084                                if (it.isOutputDouble()) {
25085                                        while (it.hasNext()) {
25086                                                final double ix = it.aDouble;
25087                                                long ox;
25088                                                ox = toLong(Math.log(ix));
25089                                                oai64data[it.oIndex] = ox;
25090                                        }
25091                                } else {
25092                                        while (it.hasNext()) {
25093                                                final long ix = it.aLong;
25094                                                long ox;
25095                                                ox = toLong(Math.log(ix));
25096                                                oai64data[it.oIndex] = ox;
25097                                        }
25098                                }
25099                        } else if (as == 1) {
25100                                if (it.isOutputDouble()) {
25101                                        while (it.hasNext()) {
25102                                                final double ix = it.aDouble;
25103                                                long ox;
25104                                                ox = toLong(Math.log(ix));
25105                                                for (int j = 0; j < is; j++) {
25106                                                        oai64data[it.oIndex + j] = ox;
25107                                                }
25108                                        }
25109                                } else {
25110                                        while (it.hasNext()) {
25111                                                final long ix = it.aLong;
25112                                                long ox;
25113                                                ox = toLong(Math.log(ix));
25114                                                for (int j = 0; j < is; j++) {
25115                                                        oai64data[it.oIndex + j] = ox;
25116                                                }
25117                                        }
25118                                }
25119                        } else {
25120                                if (it.isOutputDouble()) {
25121                                        while (it.hasNext()) {
25122                                                for (int j = 0; j < is; j++) {
25123                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25124                                                        long ox;
25125                                                        ox = toLong(Math.log(ix));
25126                                                        oai64data[it.oIndex + j] = ox;
25127                                                }
25128                                        }
25129                                } else {
25130                                        while (it.hasNext()) {
25131                                                for (int j = 0; j < is; j++) {
25132                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25133                                                        long ox;
25134                                                        ox = toLong(Math.log(ix));
25135                                                        oai64data[it.oIndex + j] = ox;
25136                                                }
25137                                        }
25138                                }
25139                        }
25140                        break;
25141                case Dataset.ARRAYINT32:
25142                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
25143                        if (is == 1) {
25144                                if (it.isOutputDouble()) {
25145                                        while (it.hasNext()) {
25146                                                final double ix = it.aDouble;
25147                                                int ox;
25148                                                ox = (int) toLong(Math.log(ix));
25149                                                oai32data[it.oIndex] = ox;
25150                                        }
25151                                } else {
25152                                        while (it.hasNext()) {
25153                                                final long ix = it.aLong;
25154                                                int ox;
25155                                                ox = (int) toLong(Math.log(ix));
25156                                                oai32data[it.oIndex] = ox;
25157                                        }
25158                                }
25159                        } else if (as == 1) {
25160                                if (it.isOutputDouble()) {
25161                                        while (it.hasNext()) {
25162                                                final double ix = it.aDouble;
25163                                                int ox;
25164                                                ox = (int) toLong(Math.log(ix));
25165                                                for (int j = 0; j < is; j++) {
25166                                                        oai32data[it.oIndex + j] = ox;
25167                                                }
25168                                        }
25169                                } else {
25170                                        while (it.hasNext()) {
25171                                                final long ix = it.aLong;
25172                                                int ox;
25173                                                ox = (int) toLong(Math.log(ix));
25174                                                for (int j = 0; j < is; j++) {
25175                                                        oai32data[it.oIndex + j] = ox;
25176                                                }
25177                                        }
25178                                }
25179                        } else {
25180                                if (it.isOutputDouble()) {
25181                                        while (it.hasNext()) {
25182                                                for (int j = 0; j < is; j++) {
25183                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25184                                                        int ox;
25185                                                        ox = (int) toLong(Math.log(ix));
25186                                                        oai32data[it.oIndex + j] = ox;
25187                                                }
25188                                        }
25189                                } else {
25190                                        while (it.hasNext()) {
25191                                                for (int j = 0; j < is; j++) {
25192                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25193                                                        int ox;
25194                                                        ox = (int) toLong(Math.log(ix));
25195                                                        oai32data[it.oIndex + j] = ox;
25196                                                }
25197                                        }
25198                                }
25199                        }
25200                        break;
25201                case Dataset.FLOAT32:
25202                        final float[] of32data = ((FloatDataset) result).getData();
25203                        if (it.isOutputDouble()) {
25204                                while (it.hasNext()) {
25205                                        final double ix = it.aDouble;
25206                                        float ox;
25207                                        ox = (float) (Math.log(ix));
25208                                        of32data[it.oIndex] = ox;
25209                                }
25210                        } else {
25211                                while (it.hasNext()) {
25212                                        final long ix = it.aLong;
25213                                        float ox;
25214                                        ox = (float) (Math.log(ix));
25215                                        of32data[it.oIndex] = ox;
25216                                }
25217                        }
25218                        break;
25219                case Dataset.FLOAT64:
25220                        final double[] of64data = ((DoubleDataset) result).getData();
25221                        if (it.isOutputDouble()) {
25222                                while (it.hasNext()) {
25223                                        final double ix = it.aDouble;
25224                                        double ox;
25225                                        ox = (Math.log(ix));
25226                                        of64data[it.oIndex] = ox;
25227                                }
25228                        } else {
25229                                while (it.hasNext()) {
25230                                        final long ix = it.aLong;
25231                                        double ox;
25232                                        ox = (Math.log(ix));
25233                                        of64data[it.oIndex] = ox;
25234                                }
25235                        }
25236                        break;
25237                case Dataset.ARRAYFLOAT32:
25238                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
25239                        if (is == 1) {
25240                                if (it.isOutputDouble()) {
25241                                        while (it.hasNext()) {
25242                                                final double ix = it.aDouble;
25243                                                float ox;
25244                                                ox = (float) (Math.log(ix));
25245                                                oaf32data[it.oIndex] = ox;
25246                                        }
25247                                } else {
25248                                        while (it.hasNext()) {
25249                                                final long ix = it.aLong;
25250                                                float ox;
25251                                                ox = (float) (Math.log(ix));
25252                                                oaf32data[it.oIndex] = ox;
25253                                        }
25254                                }
25255                        } else if (as == 1) {
25256                                if (it.isOutputDouble()) {
25257                                        while (it.hasNext()) {
25258                                                final double ix = it.aDouble;
25259                                                float ox;
25260                                                ox = (float) (Math.log(ix));
25261                                                for (int j = 0; j < is; j++) {
25262                                                        oaf32data[it.oIndex + j] = ox;
25263                                                }
25264                                        }
25265                                } else {
25266                                        while (it.hasNext()) {
25267                                                final long ix = it.aLong;
25268                                                float ox;
25269                                                ox = (float) (Math.log(ix));
25270                                                for (int j = 0; j < is; j++) {
25271                                                        oaf32data[it.oIndex + j] = ox;
25272                                                }
25273                                        }
25274                                }
25275                        } else {
25276                                if (it.isOutputDouble()) {
25277                                        while (it.hasNext()) {
25278                                                for (int j = 0; j < is; j++) {
25279                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25280                                                        float ox;
25281                                                        ox = (float) (Math.log(ix));
25282                                                        oaf32data[it.oIndex + j] = ox;
25283                                                }
25284                                        }
25285                                } else {
25286                                        while (it.hasNext()) {
25287                                                for (int j = 0; j < is; j++) {
25288                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25289                                                        float ox;
25290                                                        ox = (float) (Math.log(ix));
25291                                                        oaf32data[it.oIndex + j] = ox;
25292                                                }
25293                                        }
25294                                }
25295                        }
25296                        break;
25297                case Dataset.ARRAYFLOAT64:
25298                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
25299                        if (is == 1) {
25300                                if (it.isOutputDouble()) {
25301                                        while (it.hasNext()) {
25302                                                final double ix = it.aDouble;
25303                                                double ox;
25304                                                ox = (Math.log(ix));
25305                                                oaf64data[it.oIndex] = ox;
25306                                        }
25307                                } else {
25308                                        while (it.hasNext()) {
25309                                                final long ix = it.aLong;
25310                                                double ox;
25311                                                ox = (Math.log(ix));
25312                                                oaf64data[it.oIndex] = ox;
25313                                        }
25314                                }
25315                        } else if (as == 1) {
25316                                if (it.isOutputDouble()) {
25317                                        while (it.hasNext()) {
25318                                                final double ix = it.aDouble;
25319                                                double ox;
25320                                                ox = (Math.log(ix));
25321                                                for (int j = 0; j < is; j++) {
25322                                                        oaf64data[it.oIndex + j] = ox;
25323                                                }
25324                                        }
25325                                } else {
25326                                        while (it.hasNext()) {
25327                                                final long ix = it.aLong;
25328                                                double ox;
25329                                                ox = (Math.log(ix));
25330                                                for (int j = 0; j < is; j++) {
25331                                                        oaf64data[it.oIndex + j] = ox;
25332                                                }
25333                                        }
25334                                }
25335                        } else {
25336                                if (it.isOutputDouble()) {
25337                                        while (it.hasNext()) {
25338                                                for (int j = 0; j < is; j++) {
25339                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25340                                                        double ox;
25341                                                        ox = (Math.log(ix));
25342                                                        oaf64data[it.oIndex + j] = ox;
25343                                                }
25344                                        }
25345                                } else {
25346                                        while (it.hasNext()) {
25347                                                for (int j = 0; j < is; j++) {
25348                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25349                                                        double ox;
25350                                                        ox = (Math.log(ix));
25351                                                        oaf64data[it.oIndex + j] = ox;
25352                                                }
25353                                        }
25354                                }
25355                        }
25356                        break;
25357                case Dataset.COMPLEX64:
25358                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
25359                        if (!da.isComplex()) {
25360                                if (it.isOutputDouble()) {
25361                                        final double iy = 0;
25362                                        while (it.hasNext()) {
25363                                                final double ix = it.aDouble;
25364                                                float ox;
25365                                                float oy;
25366                                                ox = (float) (Math.log(Math.hypot(ix, iy)));
25367                                                oy = (float) (Math.atan2(iy, ix));
25368                                                oc64data[it.oIndex] = ox;
25369                                                oc64data[it.oIndex + 1] = oy;
25370                                        }
25371                                } else {
25372                                        final long iy = 0;
25373                                        while (it.hasNext()) {
25374                                                final long ix = it.aLong;
25375                                                float ox;
25376                                                float oy;
25377                                                ox = (float) toLong(Math.log(Math.hypot(ix, iy)));
25378                                                oy = (float) toLong(Math.atan2(iy, ix));
25379                                                oc64data[it.oIndex] = ox;
25380                                                oc64data[it.oIndex + 1] = oy;
25381                                        }
25382                                }
25383                        } else {
25384                                while (it.hasNext()) {
25385                                        final double ix = it.aDouble;
25386                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
25387                                        float ox;
25388                                        float oy;
25389                                        ox = (float) (Math.log(Math.hypot(ix, iy)));
25390                                        oy = (float) (Math.atan2(iy, ix));
25391                                        oc64data[it.oIndex] = ox;
25392                                        oc64data[it.oIndex + 1] = oy;
25393                                }
25394                        }
25395                        break;
25396                case Dataset.COMPLEX128:
25397                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
25398                        if (!da.isComplex()) {
25399                                if (it.isOutputDouble()) {
25400                                        final double iy = 0;
25401                                        while (it.hasNext()) {
25402                                                final double ix = it.aDouble;
25403                                                double ox;
25404                                                double oy;
25405                                                ox = (Math.log(Math.hypot(ix, iy)));
25406                                                oy = (Math.atan2(iy, ix));
25407                                                oc128data[it.oIndex] = ox;
25408                                                oc128data[it.oIndex + 1] = oy;
25409                                        }
25410                                } else {
25411                                        final long iy = 0;
25412                                        while (it.hasNext()) {
25413                                                final long ix = it.aLong;
25414                                                double ox;
25415                                                double oy;
25416                                                ox = (double) (Math.log(Math.hypot(ix, iy)));
25417                                                oy = (double) (Math.atan2(iy, ix));
25418                                                oc128data[it.oIndex] = ox;
25419                                                oc128data[it.oIndex + 1] = oy;
25420                                        }
25421                                }
25422                        } else {
25423                                while (it.hasNext()) {
25424                                        final double ix = it.aDouble;
25425                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
25426                                        double ox;
25427                                        double oy;
25428                                        ox = (Math.log(Math.hypot(ix, iy)));
25429                                        oy = (Math.atan2(iy, ix));
25430                                        oc128data[it.oIndex] = ox;
25431                                        oc128data[it.oIndex + 1] = oy;
25432                                }
25433                        }
25434                        break;
25435                default:
25436                        throw new IllegalArgumentException("log supports integer, compound integer, real, compound real, complex datasets only");
25437                }
25438
25439                addFunctionName(result, "log");
25440                return result;
25441        }
25442
25443        /**
25444         * log2 - evaluate the logarithm function on each element of the dataset
25445         * @param a
25446         * @return dataset
25447         */
25448        public static Dataset log2(final Object a) {
25449                return log2(a, null);
25450        }
25451
25452        /**
25453         * log2 - evaluate the logarithm function on each element of the dataset
25454         * @param a
25455         * @param o output can be null - in which case, a new dataset is created
25456         * @return dataset
25457         */
25458        public static Dataset log2(final Object a, final Dataset o) {
25459                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
25460                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
25461                final Dataset result = it.getOutput();
25462                if (!result.isComplex()) {
25463                        if (da.isComplex()) {
25464                                da = da.getRealView();
25465                                it = new SingleInputBroadcastIterator(da, result, true);
25466                        }
25467                }
25468                final int is = result.getElementsPerItem();
25469                final int as = da.getElementsPerItem();
25470                final int dt = result.getDType();
25471
25472                switch(dt) {
25473                case Dataset.INT8:
25474                        final byte[] oi8data = ((ByteDataset) result).getData();
25475                        if (it.isOutputDouble()) {
25476                                while (it.hasNext()) {
25477                                        final double ix = it.aDouble;
25478                                        byte ox;
25479                                        ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25480                                        oi8data[it.oIndex] = ox;
25481                                }
25482                        } else {
25483                                while (it.hasNext()) {
25484                                        final long ix = it.aLong;
25485                                        byte ox;
25486                                        ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25487                                        oi8data[it.oIndex] = ox;
25488                                }
25489                        }
25490                        break;
25491                case Dataset.INT16:
25492                        final short[] oi16data = ((ShortDataset) result).getData();
25493                        if (it.isOutputDouble()) {
25494                                while (it.hasNext()) {
25495                                        final double ix = it.aDouble;
25496                                        short ox;
25497                                        ox = (short) toLong(Math.log(ix)/Math.log(2.));
25498                                        oi16data[it.oIndex] = ox;
25499                                }
25500                        } else {
25501                                while (it.hasNext()) {
25502                                        final long ix = it.aLong;
25503                                        short ox;
25504                                        ox = (short) toLong(Math.log(ix)/Math.log(2.));
25505                                        oi16data[it.oIndex] = ox;
25506                                }
25507                        }
25508                        break;
25509                case Dataset.INT64:
25510                        final long[] oi64data = ((LongDataset) result).getData();
25511                        if (it.isOutputDouble()) {
25512                                while (it.hasNext()) {
25513                                        final double ix = it.aDouble;
25514                                        long ox;
25515                                        ox = toLong(Math.log(ix)/Math.log(2.));
25516                                        oi64data[it.oIndex] = ox;
25517                                }
25518                        } else {
25519                                while (it.hasNext()) {
25520                                        final long ix = it.aLong;
25521                                        long ox;
25522                                        ox = toLong(Math.log(ix)/Math.log(2.));
25523                                        oi64data[it.oIndex] = ox;
25524                                }
25525                        }
25526                        break;
25527                case Dataset.INT32:
25528                        final int[] oi32data = ((IntegerDataset) result).getData();
25529                        if (it.isOutputDouble()) {
25530                                while (it.hasNext()) {
25531                                        final double ix = it.aDouble;
25532                                        int ox;
25533                                        ox = (int) toLong(Math.log(ix)/Math.log(2.));
25534                                        oi32data[it.oIndex] = ox;
25535                                }
25536                        } else {
25537                                while (it.hasNext()) {
25538                                        final long ix = it.aLong;
25539                                        int ox;
25540                                        ox = (int) toLong(Math.log(ix)/Math.log(2.));
25541                                        oi32data[it.oIndex] = ox;
25542                                }
25543                        }
25544                        break;
25545                case Dataset.ARRAYINT8:
25546                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
25547                        if (is == 1) {
25548                                if (it.isOutputDouble()) {
25549                                        while (it.hasNext()) {
25550                                                final double ix = it.aDouble;
25551                                                byte ox;
25552                                                ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25553                                                oai8data[it.oIndex] = ox;
25554                                        }
25555                                } else {
25556                                        while (it.hasNext()) {
25557                                                final long ix = it.aLong;
25558                                                byte ox;
25559                                                ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25560                                                oai8data[it.oIndex] = ox;
25561                                        }
25562                                }
25563                        } else if (as == 1) {
25564                                if (it.isOutputDouble()) {
25565                                        while (it.hasNext()) {
25566                                                final double ix = it.aDouble;
25567                                                byte ox;
25568                                                ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25569                                                for (int j = 0; j < is; j++) {
25570                                                        oai8data[it.oIndex + j] = ox;
25571                                                }
25572                                        }
25573                                } else {
25574                                        while (it.hasNext()) {
25575                                                final long ix = it.aLong;
25576                                                byte ox;
25577                                                ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25578                                                for (int j = 0; j < is; j++) {
25579                                                        oai8data[it.oIndex + j] = ox;
25580                                                }
25581                                        }
25582                                }
25583                        } else {
25584                                if (it.isOutputDouble()) {
25585                                        while (it.hasNext()) {
25586                                                for (int j = 0; j < is; j++) {
25587                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25588                                                        byte ox;
25589                                                        ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25590                                                        oai8data[it.oIndex + j] = ox;
25591                                                }
25592                                        }
25593                                } else {
25594                                        while (it.hasNext()) {
25595                                                for (int j = 0; j < is; j++) {
25596                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25597                                                        byte ox;
25598                                                        ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25599                                                        oai8data[it.oIndex + j] = ox;
25600                                                }
25601                                        }
25602                                }
25603                        }
25604                        break;
25605                case Dataset.ARRAYINT16:
25606                        final short[] oai16data = ((CompoundShortDataset) result).getData();
25607                        if (is == 1) {
25608                                if (it.isOutputDouble()) {
25609                                        while (it.hasNext()) {
25610                                                final double ix = it.aDouble;
25611                                                short ox;
25612                                                ox = (short) toLong(Math.log(ix)/Math.log(2.));
25613                                                oai16data[it.oIndex] = ox;
25614                                        }
25615                                } else {
25616                                        while (it.hasNext()) {
25617                                                final long ix = it.aLong;
25618                                                short ox;
25619                                                ox = (short) toLong(Math.log(ix)/Math.log(2.));
25620                                                oai16data[it.oIndex] = ox;
25621                                        }
25622                                }
25623                        } else if (as == 1) {
25624                                if (it.isOutputDouble()) {
25625                                        while (it.hasNext()) {
25626                                                final double ix = it.aDouble;
25627                                                short ox;
25628                                                ox = (short) toLong(Math.log(ix)/Math.log(2.));
25629                                                for (int j = 0; j < is; j++) {
25630                                                        oai16data[it.oIndex + j] = ox;
25631                                                }
25632                                        }
25633                                } else {
25634                                        while (it.hasNext()) {
25635                                                final long ix = it.aLong;
25636                                                short ox;
25637                                                ox = (short) toLong(Math.log(ix)/Math.log(2.));
25638                                                for (int j = 0; j < is; j++) {
25639                                                        oai16data[it.oIndex + j] = ox;
25640                                                }
25641                                        }
25642                                }
25643                        } else {
25644                                if (it.isOutputDouble()) {
25645                                        while (it.hasNext()) {
25646                                                for (int j = 0; j < is; j++) {
25647                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25648                                                        short ox;
25649                                                        ox = (short) toLong(Math.log(ix)/Math.log(2.));
25650                                                        oai16data[it.oIndex + j] = ox;
25651                                                }
25652                                        }
25653                                } else {
25654                                        while (it.hasNext()) {
25655                                                for (int j = 0; j < is; j++) {
25656                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25657                                                        short ox;
25658                                                        ox = (short) toLong(Math.log(ix)/Math.log(2.));
25659                                                        oai16data[it.oIndex + j] = ox;
25660                                                }
25661                                        }
25662                                }
25663                        }
25664                        break;
25665                case Dataset.ARRAYINT64:
25666                        final long[] oai64data = ((CompoundLongDataset) result).getData();
25667                        if (is == 1) {
25668                                if (it.isOutputDouble()) {
25669                                        while (it.hasNext()) {
25670                                                final double ix = it.aDouble;
25671                                                long ox;
25672                                                ox = toLong(Math.log(ix)/Math.log(2.));
25673                                                oai64data[it.oIndex] = ox;
25674                                        }
25675                                } else {
25676                                        while (it.hasNext()) {
25677                                                final long ix = it.aLong;
25678                                                long ox;
25679                                                ox = toLong(Math.log(ix)/Math.log(2.));
25680                                                oai64data[it.oIndex] = ox;
25681                                        }
25682                                }
25683                        } else if (as == 1) {
25684                                if (it.isOutputDouble()) {
25685                                        while (it.hasNext()) {
25686                                                final double ix = it.aDouble;
25687                                                long ox;
25688                                                ox = toLong(Math.log(ix)/Math.log(2.));
25689                                                for (int j = 0; j < is; j++) {
25690                                                        oai64data[it.oIndex + j] = ox;
25691                                                }
25692                                        }
25693                                } else {
25694                                        while (it.hasNext()) {
25695                                                final long ix = it.aLong;
25696                                                long ox;
25697                                                ox = toLong(Math.log(ix)/Math.log(2.));
25698                                                for (int j = 0; j < is; j++) {
25699                                                        oai64data[it.oIndex + j] = ox;
25700                                                }
25701                                        }
25702                                }
25703                        } else {
25704                                if (it.isOutputDouble()) {
25705                                        while (it.hasNext()) {
25706                                                for (int j = 0; j < is; j++) {
25707                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25708                                                        long ox;
25709                                                        ox = toLong(Math.log(ix)/Math.log(2.));
25710                                                        oai64data[it.oIndex + j] = ox;
25711                                                }
25712                                        }
25713                                } else {
25714                                        while (it.hasNext()) {
25715                                                for (int j = 0; j < is; j++) {
25716                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25717                                                        long ox;
25718                                                        ox = toLong(Math.log(ix)/Math.log(2.));
25719                                                        oai64data[it.oIndex + j] = ox;
25720                                                }
25721                                        }
25722                                }
25723                        }
25724                        break;
25725                case Dataset.ARRAYINT32:
25726                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
25727                        if (is == 1) {
25728                                if (it.isOutputDouble()) {
25729                                        while (it.hasNext()) {
25730                                                final double ix = it.aDouble;
25731                                                int ox;
25732                                                ox = (int) toLong(Math.log(ix)/Math.log(2.));
25733                                                oai32data[it.oIndex] = ox;
25734                                        }
25735                                } else {
25736                                        while (it.hasNext()) {
25737                                                final long ix = it.aLong;
25738                                                int ox;
25739                                                ox = (int) toLong(Math.log(ix)/Math.log(2.));
25740                                                oai32data[it.oIndex] = ox;
25741                                        }
25742                                }
25743                        } else if (as == 1) {
25744                                if (it.isOutputDouble()) {
25745                                        while (it.hasNext()) {
25746                                                final double ix = it.aDouble;
25747                                                int ox;
25748                                                ox = (int) toLong(Math.log(ix)/Math.log(2.));
25749                                                for (int j = 0; j < is; j++) {
25750                                                        oai32data[it.oIndex + j] = ox;
25751                                                }
25752                                        }
25753                                } else {
25754                                        while (it.hasNext()) {
25755                                                final long ix = it.aLong;
25756                                                int ox;
25757                                                ox = (int) toLong(Math.log(ix)/Math.log(2.));
25758                                                for (int j = 0; j < is; j++) {
25759                                                        oai32data[it.oIndex + j] = ox;
25760                                                }
25761                                        }
25762                                }
25763                        } else {
25764                                if (it.isOutputDouble()) {
25765                                        while (it.hasNext()) {
25766                                                for (int j = 0; j < is; j++) {
25767                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25768                                                        int ox;
25769                                                        ox = (int) toLong(Math.log(ix)/Math.log(2.));
25770                                                        oai32data[it.oIndex + j] = ox;
25771                                                }
25772                                        }
25773                                } else {
25774                                        while (it.hasNext()) {
25775                                                for (int j = 0; j < is; j++) {
25776                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25777                                                        int ox;
25778                                                        ox = (int) toLong(Math.log(ix)/Math.log(2.));
25779                                                        oai32data[it.oIndex + j] = ox;
25780                                                }
25781                                        }
25782                                }
25783                        }
25784                        break;
25785                case Dataset.FLOAT32:
25786                        final float[] of32data = ((FloatDataset) result).getData();
25787                        if (it.isOutputDouble()) {
25788                                while (it.hasNext()) {
25789                                        final double ix = it.aDouble;
25790                                        float ox;
25791                                        ox = (float) (Math.log(ix)/Math.log(2.));
25792                                        of32data[it.oIndex] = ox;
25793                                }
25794                        } else {
25795                                while (it.hasNext()) {
25796                                        final long ix = it.aLong;
25797                                        float ox;
25798                                        ox = (float) (Math.log(ix)/Math.log(2.));
25799                                        of32data[it.oIndex] = ox;
25800                                }
25801                        }
25802                        break;
25803                case Dataset.FLOAT64:
25804                        final double[] of64data = ((DoubleDataset) result).getData();
25805                        if (it.isOutputDouble()) {
25806                                while (it.hasNext()) {
25807                                        final double ix = it.aDouble;
25808                                        double ox;
25809                                        ox = (Math.log(ix)/Math.log(2.));
25810                                        of64data[it.oIndex] = ox;
25811                                }
25812                        } else {
25813                                while (it.hasNext()) {
25814                                        final long ix = it.aLong;
25815                                        double ox;
25816                                        ox = (Math.log(ix)/Math.log(2.));
25817                                        of64data[it.oIndex] = ox;
25818                                }
25819                        }
25820                        break;
25821                case Dataset.ARRAYFLOAT32:
25822                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
25823                        if (is == 1) {
25824                                if (it.isOutputDouble()) {
25825                                        while (it.hasNext()) {
25826                                                final double ix = it.aDouble;
25827                                                float ox;
25828                                                ox = (float) (Math.log(ix)/Math.log(2.));
25829                                                oaf32data[it.oIndex] = ox;
25830                                        }
25831                                } else {
25832                                        while (it.hasNext()) {
25833                                                final long ix = it.aLong;
25834                                                float ox;
25835                                                ox = (float) (Math.log(ix)/Math.log(2.));
25836                                                oaf32data[it.oIndex] = ox;
25837                                        }
25838                                }
25839                        } else if (as == 1) {
25840                                if (it.isOutputDouble()) {
25841                                        while (it.hasNext()) {
25842                                                final double ix = it.aDouble;
25843                                                float ox;
25844                                                ox = (float) (Math.log(ix)/Math.log(2.));
25845                                                for (int j = 0; j < is; j++) {
25846                                                        oaf32data[it.oIndex + j] = ox;
25847                                                }
25848                                        }
25849                                } else {
25850                                        while (it.hasNext()) {
25851                                                final long ix = it.aLong;
25852                                                float ox;
25853                                                ox = (float) (Math.log(ix)/Math.log(2.));
25854                                                for (int j = 0; j < is; j++) {
25855                                                        oaf32data[it.oIndex + j] = ox;
25856                                                }
25857                                        }
25858                                }
25859                        } else {
25860                                if (it.isOutputDouble()) {
25861                                        while (it.hasNext()) {
25862                                                for (int j = 0; j < is; j++) {
25863                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25864                                                        float ox;
25865                                                        ox = (float) (Math.log(ix)/Math.log(2.));
25866                                                        oaf32data[it.oIndex + j] = ox;
25867                                                }
25868                                        }
25869                                } else {
25870                                        while (it.hasNext()) {
25871                                                for (int j = 0; j < is; j++) {
25872                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25873                                                        float ox;
25874                                                        ox = (float) (Math.log(ix)/Math.log(2.));
25875                                                        oaf32data[it.oIndex + j] = ox;
25876                                                }
25877                                        }
25878                                }
25879                        }
25880                        break;
25881                case Dataset.ARRAYFLOAT64:
25882                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
25883                        if (is == 1) {
25884                                if (it.isOutputDouble()) {
25885                                        while (it.hasNext()) {
25886                                                final double ix = it.aDouble;
25887                                                double ox;
25888                                                ox = (Math.log(ix)/Math.log(2.));
25889                                                oaf64data[it.oIndex] = ox;
25890                                        }
25891                                } else {
25892                                        while (it.hasNext()) {
25893                                                final long ix = it.aLong;
25894                                                double ox;
25895                                                ox = (Math.log(ix)/Math.log(2.));
25896                                                oaf64data[it.oIndex] = ox;
25897                                        }
25898                                }
25899                        } else if (as == 1) {
25900                                if (it.isOutputDouble()) {
25901                                        while (it.hasNext()) {
25902                                                final double ix = it.aDouble;
25903                                                double ox;
25904                                                ox = (Math.log(ix)/Math.log(2.));
25905                                                for (int j = 0; j < is; j++) {
25906                                                        oaf64data[it.oIndex + j] = ox;
25907                                                }
25908                                        }
25909                                } else {
25910                                        while (it.hasNext()) {
25911                                                final long ix = it.aLong;
25912                                                double ox;
25913                                                ox = (Math.log(ix)/Math.log(2.));
25914                                                for (int j = 0; j < is; j++) {
25915                                                        oaf64data[it.oIndex + j] = ox;
25916                                                }
25917                                        }
25918                                }
25919                        } else {
25920                                if (it.isOutputDouble()) {
25921                                        while (it.hasNext()) {
25922                                                for (int j = 0; j < is; j++) {
25923                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25924                                                        double ox;
25925                                                        ox = (Math.log(ix)/Math.log(2.));
25926                                                        oaf64data[it.oIndex + j] = ox;
25927                                                }
25928                                        }
25929                                } else {
25930                                        while (it.hasNext()) {
25931                                                for (int j = 0; j < is; j++) {
25932                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25933                                                        double ox;
25934                                                        ox = (Math.log(ix)/Math.log(2.));
25935                                                        oaf64data[it.oIndex + j] = ox;
25936                                                }
25937                                        }
25938                                }
25939                        }
25940                        break;
25941                case Dataset.COMPLEX64:
25942                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
25943                        if (!da.isComplex()) {
25944                                if (it.isOutputDouble()) {
25945                                        final double iy = 0;
25946                                        while (it.hasNext()) {
25947                                                final double ix = it.aDouble;
25948                                                float ox;
25949                                                float oy;
25950                                                ox = (float) (Math.log(Math.hypot(ix, iy))/Math.log(2.));
25951                                                oy = (float) (Math.atan2(iy, ix));
25952                                                oc64data[it.oIndex] = ox;
25953                                                oc64data[it.oIndex + 1] = oy;
25954                                        }
25955                                } else {
25956                                        final long iy = 0;
25957                                        while (it.hasNext()) {
25958                                                final long ix = it.aLong;
25959                                                float ox;
25960                                                float oy;
25961                                                ox = (float) toLong(Math.log(Math.hypot(ix, iy))/Math.log(2.));
25962                                                oy = (float) toLong(Math.atan2(iy, ix));
25963                                                oc64data[it.oIndex] = ox;
25964                                                oc64data[it.oIndex + 1] = oy;
25965                                        }
25966                                }
25967                        } else {
25968                                while (it.hasNext()) {
25969                                        final double ix = it.aDouble;
25970                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
25971                                        float ox;
25972                                        float oy;
25973                                        ox = (float) (Math.log(Math.hypot(ix, iy))/Math.log(2.));
25974                                        oy = (float) (Math.atan2(iy, ix));
25975                                        oc64data[it.oIndex] = ox;
25976                                        oc64data[it.oIndex + 1] = oy;
25977                                }
25978                        }
25979                        break;
25980                case Dataset.COMPLEX128:
25981                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
25982                        if (!da.isComplex()) {
25983                                if (it.isOutputDouble()) {
25984                                        final double iy = 0;
25985                                        while (it.hasNext()) {
25986                                                final double ix = it.aDouble;
25987                                                double ox;
25988                                                double oy;
25989                                                ox = (Math.log(Math.hypot(ix, iy))/Math.log(2.));
25990                                                oy = (Math.atan2(iy, ix));
25991                                                oc128data[it.oIndex] = ox;
25992                                                oc128data[it.oIndex + 1] = oy;
25993                                        }
25994                                } else {
25995                                        final long iy = 0;
25996                                        while (it.hasNext()) {
25997                                                final long ix = it.aLong;
25998                                                double ox;
25999                                                double oy;
26000                                                ox = (double) (Math.log(Math.hypot(ix, iy))/Math.log(2.));
26001                                                oy = (double) (Math.atan2(iy, ix));
26002                                                oc128data[it.oIndex] = ox;
26003                                                oc128data[it.oIndex + 1] = oy;
26004                                        }
26005                                }
26006                        } else {
26007                                while (it.hasNext()) {
26008                                        final double ix = it.aDouble;
26009                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
26010                                        double ox;
26011                                        double oy;
26012                                        ox = (Math.log(Math.hypot(ix, iy))/Math.log(2.));
26013                                        oy = (Math.atan2(iy, ix));
26014                                        oc128data[it.oIndex] = ox;
26015                                        oc128data[it.oIndex + 1] = oy;
26016                                }
26017                        }
26018                        break;
26019                default:
26020                        throw new IllegalArgumentException("log2 supports integer, compound integer, real, compound real, complex datasets only");
26021                }
26022
26023                addFunctionName(result, "log2");
26024                return result;
26025        }
26026
26027        /**
26028         * log10 - evaluate the logarithm function on each element of the dataset
26029         * @param a
26030         * @return dataset
26031         */
26032        public static Dataset log10(final Object a) {
26033                return log10(a, null);
26034        }
26035
26036        /**
26037         * log10 - evaluate the logarithm function on each element of the dataset
26038         * @param a
26039         * @param o output can be null - in which case, a new dataset is created
26040         * @return dataset
26041         */
26042        public static Dataset log10(final Object a, final Dataset o) {
26043                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
26044                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
26045                final Dataset result = it.getOutput();
26046                if (!result.isComplex()) {
26047                        if (da.isComplex()) {
26048                                da = da.getRealView();
26049                                it = new SingleInputBroadcastIterator(da, result, true);
26050                        }
26051                }
26052                final int is = result.getElementsPerItem();
26053                final int as = da.getElementsPerItem();
26054                final int dt = result.getDType();
26055
26056                switch(dt) {
26057                case Dataset.INT8:
26058                        final byte[] oi8data = ((ByteDataset) result).getData();
26059                        if (it.isOutputDouble()) {
26060                                while (it.hasNext()) {
26061                                        final double ix = it.aDouble;
26062                                        byte ox;
26063                                        ox = (byte) toLong(Math.log10(ix));
26064                                        oi8data[it.oIndex] = ox;
26065                                }
26066                        } else {
26067                                while (it.hasNext()) {
26068                                        final long ix = it.aLong;
26069                                        byte ox;
26070                                        ox = (byte) toLong(Math.log10(ix));
26071                                        oi8data[it.oIndex] = ox;
26072                                }
26073                        }
26074                        break;
26075                case Dataset.INT16:
26076                        final short[] oi16data = ((ShortDataset) result).getData();
26077                        if (it.isOutputDouble()) {
26078                                while (it.hasNext()) {
26079                                        final double ix = it.aDouble;
26080                                        short ox;
26081                                        ox = (short) toLong(Math.log10(ix));
26082                                        oi16data[it.oIndex] = ox;
26083                                }
26084                        } else {
26085                                while (it.hasNext()) {
26086                                        final long ix = it.aLong;
26087                                        short ox;
26088                                        ox = (short) toLong(Math.log10(ix));
26089                                        oi16data[it.oIndex] = ox;
26090                                }
26091                        }
26092                        break;
26093                case Dataset.INT64:
26094                        final long[] oi64data = ((LongDataset) result).getData();
26095                        if (it.isOutputDouble()) {
26096                                while (it.hasNext()) {
26097                                        final double ix = it.aDouble;
26098                                        long ox;
26099                                        ox = toLong(Math.log10(ix));
26100                                        oi64data[it.oIndex] = ox;
26101                                }
26102                        } else {
26103                                while (it.hasNext()) {
26104                                        final long ix = it.aLong;
26105                                        long ox;
26106                                        ox = toLong(Math.log10(ix));
26107                                        oi64data[it.oIndex] = ox;
26108                                }
26109                        }
26110                        break;
26111                case Dataset.INT32:
26112                        final int[] oi32data = ((IntegerDataset) result).getData();
26113                        if (it.isOutputDouble()) {
26114                                while (it.hasNext()) {
26115                                        final double ix = it.aDouble;
26116                                        int ox;
26117                                        ox = (int) toLong(Math.log10(ix));
26118                                        oi32data[it.oIndex] = ox;
26119                                }
26120                        } else {
26121                                while (it.hasNext()) {
26122                                        final long ix = it.aLong;
26123                                        int ox;
26124                                        ox = (int) toLong(Math.log10(ix));
26125                                        oi32data[it.oIndex] = ox;
26126                                }
26127                        }
26128                        break;
26129                case Dataset.ARRAYINT8:
26130                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
26131                        if (is == 1) {
26132                                if (it.isOutputDouble()) {
26133                                        while (it.hasNext()) {
26134                                                final double ix = it.aDouble;
26135                                                byte ox;
26136                                                ox = (byte) toLong(Math.log10(ix));
26137                                                oai8data[it.oIndex] = ox;
26138                                        }
26139                                } else {
26140                                        while (it.hasNext()) {
26141                                                final long ix = it.aLong;
26142                                                byte ox;
26143                                                ox = (byte) toLong(Math.log10(ix));
26144                                                oai8data[it.oIndex] = ox;
26145                                        }
26146                                }
26147                        } else if (as == 1) {
26148                                if (it.isOutputDouble()) {
26149                                        while (it.hasNext()) {
26150                                                final double ix = it.aDouble;
26151                                                byte ox;
26152                                                ox = (byte) toLong(Math.log10(ix));
26153                                                for (int j = 0; j < is; j++) {
26154                                                        oai8data[it.oIndex + j] = ox;
26155                                                }
26156                                        }
26157                                } else {
26158                                        while (it.hasNext()) {
26159                                                final long ix = it.aLong;
26160                                                byte ox;
26161                                                ox = (byte) toLong(Math.log10(ix));
26162                                                for (int j = 0; j < is; j++) {
26163                                                        oai8data[it.oIndex + j] = ox;
26164                                                }
26165                                        }
26166                                }
26167                        } else {
26168                                if (it.isOutputDouble()) {
26169                                        while (it.hasNext()) {
26170                                                for (int j = 0; j < is; j++) {
26171                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26172                                                        byte ox;
26173                                                        ox = (byte) toLong(Math.log10(ix));
26174                                                        oai8data[it.oIndex + j] = ox;
26175                                                }
26176                                        }
26177                                } else {
26178                                        while (it.hasNext()) {
26179                                                for (int j = 0; j < is; j++) {
26180                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26181                                                        byte ox;
26182                                                        ox = (byte) toLong(Math.log10(ix));
26183                                                        oai8data[it.oIndex + j] = ox;
26184                                                }
26185                                        }
26186                                }
26187                        }
26188                        break;
26189                case Dataset.ARRAYINT16:
26190                        final short[] oai16data = ((CompoundShortDataset) result).getData();
26191                        if (is == 1) {
26192                                if (it.isOutputDouble()) {
26193                                        while (it.hasNext()) {
26194                                                final double ix = it.aDouble;
26195                                                short ox;
26196                                                ox = (short) toLong(Math.log10(ix));
26197                                                oai16data[it.oIndex] = ox;
26198                                        }
26199                                } else {
26200                                        while (it.hasNext()) {
26201                                                final long ix = it.aLong;
26202                                                short ox;
26203                                                ox = (short) toLong(Math.log10(ix));
26204                                                oai16data[it.oIndex] = ox;
26205                                        }
26206                                }
26207                        } else if (as == 1) {
26208                                if (it.isOutputDouble()) {
26209                                        while (it.hasNext()) {
26210                                                final double ix = it.aDouble;
26211                                                short ox;
26212                                                ox = (short) toLong(Math.log10(ix));
26213                                                for (int j = 0; j < is; j++) {
26214                                                        oai16data[it.oIndex + j] = ox;
26215                                                }
26216                                        }
26217                                } else {
26218                                        while (it.hasNext()) {
26219                                                final long ix = it.aLong;
26220                                                short ox;
26221                                                ox = (short) toLong(Math.log10(ix));
26222                                                for (int j = 0; j < is; j++) {
26223                                                        oai16data[it.oIndex + j] = ox;
26224                                                }
26225                                        }
26226                                }
26227                        } else {
26228                                if (it.isOutputDouble()) {
26229                                        while (it.hasNext()) {
26230                                                for (int j = 0; j < is; j++) {
26231                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26232                                                        short ox;
26233                                                        ox = (short) toLong(Math.log10(ix));
26234                                                        oai16data[it.oIndex + j] = ox;
26235                                                }
26236                                        }
26237                                } else {
26238                                        while (it.hasNext()) {
26239                                                for (int j = 0; j < is; j++) {
26240                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26241                                                        short ox;
26242                                                        ox = (short) toLong(Math.log10(ix));
26243                                                        oai16data[it.oIndex + j] = ox;
26244                                                }
26245                                        }
26246                                }
26247                        }
26248                        break;
26249                case Dataset.ARRAYINT64:
26250                        final long[] oai64data = ((CompoundLongDataset) result).getData();
26251                        if (is == 1) {
26252                                if (it.isOutputDouble()) {
26253                                        while (it.hasNext()) {
26254                                                final double ix = it.aDouble;
26255                                                long ox;
26256                                                ox = toLong(Math.log10(ix));
26257                                                oai64data[it.oIndex] = ox;
26258                                        }
26259                                } else {
26260                                        while (it.hasNext()) {
26261                                                final long ix = it.aLong;
26262                                                long ox;
26263                                                ox = toLong(Math.log10(ix));
26264                                                oai64data[it.oIndex] = ox;
26265                                        }
26266                                }
26267                        } else if (as == 1) {
26268                                if (it.isOutputDouble()) {
26269                                        while (it.hasNext()) {
26270                                                final double ix = it.aDouble;
26271                                                long ox;
26272                                                ox = toLong(Math.log10(ix));
26273                                                for (int j = 0; j < is; j++) {
26274                                                        oai64data[it.oIndex + j] = ox;
26275                                                }
26276                                        }
26277                                } else {
26278                                        while (it.hasNext()) {
26279                                                final long ix = it.aLong;
26280                                                long ox;
26281                                                ox = toLong(Math.log10(ix));
26282                                                for (int j = 0; j < is; j++) {
26283                                                        oai64data[it.oIndex + j] = ox;
26284                                                }
26285                                        }
26286                                }
26287                        } else {
26288                                if (it.isOutputDouble()) {
26289                                        while (it.hasNext()) {
26290                                                for (int j = 0; j < is; j++) {
26291                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26292                                                        long ox;
26293                                                        ox = toLong(Math.log10(ix));
26294                                                        oai64data[it.oIndex + j] = ox;
26295                                                }
26296                                        }
26297                                } else {
26298                                        while (it.hasNext()) {
26299                                                for (int j = 0; j < is; j++) {
26300                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26301                                                        long ox;
26302                                                        ox = toLong(Math.log10(ix));
26303                                                        oai64data[it.oIndex + j] = ox;
26304                                                }
26305                                        }
26306                                }
26307                        }
26308                        break;
26309                case Dataset.ARRAYINT32:
26310                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
26311                        if (is == 1) {
26312                                if (it.isOutputDouble()) {
26313                                        while (it.hasNext()) {
26314                                                final double ix = it.aDouble;
26315                                                int ox;
26316                                                ox = (int) toLong(Math.log10(ix));
26317                                                oai32data[it.oIndex] = ox;
26318                                        }
26319                                } else {
26320                                        while (it.hasNext()) {
26321                                                final long ix = it.aLong;
26322                                                int ox;
26323                                                ox = (int) toLong(Math.log10(ix));
26324                                                oai32data[it.oIndex] = ox;
26325                                        }
26326                                }
26327                        } else if (as == 1) {
26328                                if (it.isOutputDouble()) {
26329                                        while (it.hasNext()) {
26330                                                final double ix = it.aDouble;
26331                                                int ox;
26332                                                ox = (int) toLong(Math.log10(ix));
26333                                                for (int j = 0; j < is; j++) {
26334                                                        oai32data[it.oIndex + j] = ox;
26335                                                }
26336                                        }
26337                                } else {
26338                                        while (it.hasNext()) {
26339                                                final long ix = it.aLong;
26340                                                int ox;
26341                                                ox = (int) toLong(Math.log10(ix));
26342                                                for (int j = 0; j < is; j++) {
26343                                                        oai32data[it.oIndex + j] = ox;
26344                                                }
26345                                        }
26346                                }
26347                        } else {
26348                                if (it.isOutputDouble()) {
26349                                        while (it.hasNext()) {
26350                                                for (int j = 0; j < is; j++) {
26351                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26352                                                        int ox;
26353                                                        ox = (int) toLong(Math.log10(ix));
26354                                                        oai32data[it.oIndex + j] = ox;
26355                                                }
26356                                        }
26357                                } else {
26358                                        while (it.hasNext()) {
26359                                                for (int j = 0; j < is; j++) {
26360                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26361                                                        int ox;
26362                                                        ox = (int) toLong(Math.log10(ix));
26363                                                        oai32data[it.oIndex + j] = ox;
26364                                                }
26365                                        }
26366                                }
26367                        }
26368                        break;
26369                case Dataset.FLOAT32:
26370                        final float[] of32data = ((FloatDataset) result).getData();
26371                        if (it.isOutputDouble()) {
26372                                while (it.hasNext()) {
26373                                        final double ix = it.aDouble;
26374                                        float ox;
26375                                        ox = (float) (Math.log10(ix));
26376                                        of32data[it.oIndex] = ox;
26377                                }
26378                        } else {
26379                                while (it.hasNext()) {
26380                                        final long ix = it.aLong;
26381                                        float ox;
26382                                        ox = (float) (Math.log10(ix));
26383                                        of32data[it.oIndex] = ox;
26384                                }
26385                        }
26386                        break;
26387                case Dataset.FLOAT64:
26388                        final double[] of64data = ((DoubleDataset) result).getData();
26389                        if (it.isOutputDouble()) {
26390                                while (it.hasNext()) {
26391                                        final double ix = it.aDouble;
26392                                        double ox;
26393                                        ox = (Math.log10(ix));
26394                                        of64data[it.oIndex] = ox;
26395                                }
26396                        } else {
26397                                while (it.hasNext()) {
26398                                        final long ix = it.aLong;
26399                                        double ox;
26400                                        ox = (Math.log10(ix));
26401                                        of64data[it.oIndex] = ox;
26402                                }
26403                        }
26404                        break;
26405                case Dataset.ARRAYFLOAT32:
26406                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
26407                        if (is == 1) {
26408                                if (it.isOutputDouble()) {
26409                                        while (it.hasNext()) {
26410                                                final double ix = it.aDouble;
26411                                                float ox;
26412                                                ox = (float) (Math.log10(ix));
26413                                                oaf32data[it.oIndex] = ox;
26414                                        }
26415                                } else {
26416                                        while (it.hasNext()) {
26417                                                final long ix = it.aLong;
26418                                                float ox;
26419                                                ox = (float) (Math.log10(ix));
26420                                                oaf32data[it.oIndex] = ox;
26421                                        }
26422                                }
26423                        } else if (as == 1) {
26424                                if (it.isOutputDouble()) {
26425                                        while (it.hasNext()) {
26426                                                final double ix = it.aDouble;
26427                                                float ox;
26428                                                ox = (float) (Math.log10(ix));
26429                                                for (int j = 0; j < is; j++) {
26430                                                        oaf32data[it.oIndex + j] = ox;
26431                                                }
26432                                        }
26433                                } else {
26434                                        while (it.hasNext()) {
26435                                                final long ix = it.aLong;
26436                                                float ox;
26437                                                ox = (float) (Math.log10(ix));
26438                                                for (int j = 0; j < is; j++) {
26439                                                        oaf32data[it.oIndex + j] = ox;
26440                                                }
26441                                        }
26442                                }
26443                        } else {
26444                                if (it.isOutputDouble()) {
26445                                        while (it.hasNext()) {
26446                                                for (int j = 0; j < is; j++) {
26447                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26448                                                        float ox;
26449                                                        ox = (float) (Math.log10(ix));
26450                                                        oaf32data[it.oIndex + j] = ox;
26451                                                }
26452                                        }
26453                                } else {
26454                                        while (it.hasNext()) {
26455                                                for (int j = 0; j < is; j++) {
26456                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26457                                                        float ox;
26458                                                        ox = (float) (Math.log10(ix));
26459                                                        oaf32data[it.oIndex + j] = ox;
26460                                                }
26461                                        }
26462                                }
26463                        }
26464                        break;
26465                case Dataset.ARRAYFLOAT64:
26466                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
26467                        if (is == 1) {
26468                                if (it.isOutputDouble()) {
26469                                        while (it.hasNext()) {
26470                                                final double ix = it.aDouble;
26471                                                double ox;
26472                                                ox = (Math.log10(ix));
26473                                                oaf64data[it.oIndex] = ox;
26474                                        }
26475                                } else {
26476                                        while (it.hasNext()) {
26477                                                final long ix = it.aLong;
26478                                                double ox;
26479                                                ox = (Math.log10(ix));
26480                                                oaf64data[it.oIndex] = ox;
26481                                        }
26482                                }
26483                        } else if (as == 1) {
26484                                if (it.isOutputDouble()) {
26485                                        while (it.hasNext()) {
26486                                                final double ix = it.aDouble;
26487                                                double ox;
26488                                                ox = (Math.log10(ix));
26489                                                for (int j = 0; j < is; j++) {
26490                                                        oaf64data[it.oIndex + j] = ox;
26491                                                }
26492                                        }
26493                                } else {
26494                                        while (it.hasNext()) {
26495                                                final long ix = it.aLong;
26496                                                double ox;
26497                                                ox = (Math.log10(ix));
26498                                                for (int j = 0; j < is; j++) {
26499                                                        oaf64data[it.oIndex + j] = ox;
26500                                                }
26501                                        }
26502                                }
26503                        } else {
26504                                if (it.isOutputDouble()) {
26505                                        while (it.hasNext()) {
26506                                                for (int j = 0; j < is; j++) {
26507                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26508                                                        double ox;
26509                                                        ox = (Math.log10(ix));
26510                                                        oaf64data[it.oIndex + j] = ox;
26511                                                }
26512                                        }
26513                                } else {
26514                                        while (it.hasNext()) {
26515                                                for (int j = 0; j < is; j++) {
26516                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26517                                                        double ox;
26518                                                        ox = (Math.log10(ix));
26519                                                        oaf64data[it.oIndex + j] = ox;
26520                                                }
26521                                        }
26522                                }
26523                        }
26524                        break;
26525                case Dataset.COMPLEX64:
26526                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
26527                        if (!da.isComplex()) {
26528                                if (it.isOutputDouble()) {
26529                                        final double iy = 0;
26530                                        while (it.hasNext()) {
26531                                                final double ix = it.aDouble;
26532                                                float ox;
26533                                                float oy;
26534                                                ox = (float) (Math.log10(Math.hypot(ix, iy)));
26535                                                oy = (float) (Math.atan2(iy, ix));
26536                                                oc64data[it.oIndex] = ox;
26537                                                oc64data[it.oIndex + 1] = oy;
26538                                        }
26539                                } else {
26540                                        final long iy = 0;
26541                                        while (it.hasNext()) {
26542                                                final long ix = it.aLong;
26543                                                float ox;
26544                                                float oy;
26545                                                ox = (float) toLong(Math.log10(Math.hypot(ix, iy)));
26546                                                oy = (float) toLong(Math.atan2(iy, ix));
26547                                                oc64data[it.oIndex] = ox;
26548                                                oc64data[it.oIndex + 1] = oy;
26549                                        }
26550                                }
26551                        } else {
26552                                while (it.hasNext()) {
26553                                        final double ix = it.aDouble;
26554                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
26555                                        float ox;
26556                                        float oy;
26557                                        ox = (float) (Math.log10(Math.hypot(ix, iy)));
26558                                        oy = (float) (Math.atan2(iy, ix));
26559                                        oc64data[it.oIndex] = ox;
26560                                        oc64data[it.oIndex + 1] = oy;
26561                                }
26562                        }
26563                        break;
26564                case Dataset.COMPLEX128:
26565                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
26566                        if (!da.isComplex()) {
26567                                if (it.isOutputDouble()) {
26568                                        final double iy = 0;
26569                                        while (it.hasNext()) {
26570                                                final double ix = it.aDouble;
26571                                                double ox;
26572                                                double oy;
26573                                                ox = (Math.log10(Math.hypot(ix, iy)));
26574                                                oy = (Math.atan2(iy, ix));
26575                                                oc128data[it.oIndex] = ox;
26576                                                oc128data[it.oIndex + 1] = oy;
26577                                        }
26578                                } else {
26579                                        final long iy = 0;
26580                                        while (it.hasNext()) {
26581                                                final long ix = it.aLong;
26582                                                double ox;
26583                                                double oy;
26584                                                ox = (double) (Math.log10(Math.hypot(ix, iy)));
26585                                                oy = (double) (Math.atan2(iy, ix));
26586                                                oc128data[it.oIndex] = ox;
26587                                                oc128data[it.oIndex + 1] = oy;
26588                                        }
26589                                }
26590                        } else {
26591                                while (it.hasNext()) {
26592                                        final double ix = it.aDouble;
26593                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
26594                                        double ox;
26595                                        double oy;
26596                                        ox = (Math.log10(Math.hypot(ix, iy)));
26597                                        oy = (Math.atan2(iy, ix));
26598                                        oc128data[it.oIndex] = ox;
26599                                        oc128data[it.oIndex + 1] = oy;
26600                                }
26601                        }
26602                        break;
26603                default:
26604                        throw new IllegalArgumentException("log10 supports integer, compound integer, real, compound real, complex datasets only");
26605                }
26606
26607                addFunctionName(result, "log10");
26608                return result;
26609        }
26610
26611        /**
26612         * log1p - evaluate the logarithm function of 1 plus on each element of the dataset
26613         * @param a
26614         * @return dataset
26615         */
26616        public static Dataset log1p(final Object a) {
26617                return log1p(a, null);
26618        }
26619
26620        /**
26621         * log1p - evaluate the logarithm function of 1 plus on each element of the dataset
26622         * @param a
26623         * @param o output can be null - in which case, a new dataset is created
26624         * @return dataset
26625         */
26626        public static Dataset log1p(final Object a, final Dataset o) {
26627                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
26628                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
26629                final Dataset result = it.getOutput();
26630                if (!result.isComplex()) {
26631                        if (da.isComplex()) {
26632                                da = da.getRealView();
26633                                it = new SingleInputBroadcastIterator(da, result, true);
26634                        }
26635                }
26636                final int is = result.getElementsPerItem();
26637                final int as = da.getElementsPerItem();
26638                final int dt = result.getDType();
26639
26640                switch(dt) {
26641                case Dataset.INT8:
26642                        final byte[] oi8data = ((ByteDataset) result).getData();
26643                        if (it.isOutputDouble()) {
26644                                while (it.hasNext()) {
26645                                        final double ix = it.aDouble;
26646                                        byte ox;
26647                                        ox = (byte) toLong(Math.log1p(ix));
26648                                        oi8data[it.oIndex] = ox;
26649                                }
26650                        } else {
26651                                while (it.hasNext()) {
26652                                        final long ix = it.aLong;
26653                                        byte ox;
26654                                        ox = (byte) toLong(Math.log1p(ix));
26655                                        oi8data[it.oIndex] = ox;
26656                                }
26657                        }
26658                        break;
26659                case Dataset.INT16:
26660                        final short[] oi16data = ((ShortDataset) result).getData();
26661                        if (it.isOutputDouble()) {
26662                                while (it.hasNext()) {
26663                                        final double ix = it.aDouble;
26664                                        short ox;
26665                                        ox = (short) toLong(Math.log1p(ix));
26666                                        oi16data[it.oIndex] = ox;
26667                                }
26668                        } else {
26669                                while (it.hasNext()) {
26670                                        final long ix = it.aLong;
26671                                        short ox;
26672                                        ox = (short) toLong(Math.log1p(ix));
26673                                        oi16data[it.oIndex] = ox;
26674                                }
26675                        }
26676                        break;
26677                case Dataset.INT64:
26678                        final long[] oi64data = ((LongDataset) result).getData();
26679                        if (it.isOutputDouble()) {
26680                                while (it.hasNext()) {
26681                                        final double ix = it.aDouble;
26682                                        long ox;
26683                                        ox = toLong(Math.log1p(ix));
26684                                        oi64data[it.oIndex] = ox;
26685                                }
26686                        } else {
26687                                while (it.hasNext()) {
26688                                        final long ix = it.aLong;
26689                                        long ox;
26690                                        ox = toLong(Math.log1p(ix));
26691                                        oi64data[it.oIndex] = ox;
26692                                }
26693                        }
26694                        break;
26695                case Dataset.INT32:
26696                        final int[] oi32data = ((IntegerDataset) result).getData();
26697                        if (it.isOutputDouble()) {
26698                                while (it.hasNext()) {
26699                                        final double ix = it.aDouble;
26700                                        int ox;
26701                                        ox = (int) toLong(Math.log1p(ix));
26702                                        oi32data[it.oIndex] = ox;
26703                                }
26704                        } else {
26705                                while (it.hasNext()) {
26706                                        final long ix = it.aLong;
26707                                        int ox;
26708                                        ox = (int) toLong(Math.log1p(ix));
26709                                        oi32data[it.oIndex] = ox;
26710                                }
26711                        }
26712                        break;
26713                case Dataset.ARRAYINT8:
26714                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
26715                        if (is == 1) {
26716                                if (it.isOutputDouble()) {
26717                                        while (it.hasNext()) {
26718                                                final double ix = it.aDouble;
26719                                                byte ox;
26720                                                ox = (byte) toLong(Math.log1p(ix));
26721                                                oai8data[it.oIndex] = ox;
26722                                        }
26723                                } else {
26724                                        while (it.hasNext()) {
26725                                                final long ix = it.aLong;
26726                                                byte ox;
26727                                                ox = (byte) toLong(Math.log1p(ix));
26728                                                oai8data[it.oIndex] = ox;
26729                                        }
26730                                }
26731                        } else if (as == 1) {
26732                                if (it.isOutputDouble()) {
26733                                        while (it.hasNext()) {
26734                                                final double ix = it.aDouble;
26735                                                byte ox;
26736                                                ox = (byte) toLong(Math.log1p(ix));
26737                                                for (int j = 0; j < is; j++) {
26738                                                        oai8data[it.oIndex + j] = ox;
26739                                                }
26740                                        }
26741                                } else {
26742                                        while (it.hasNext()) {
26743                                                final long ix = it.aLong;
26744                                                byte ox;
26745                                                ox = (byte) toLong(Math.log1p(ix));
26746                                                for (int j = 0; j < is; j++) {
26747                                                        oai8data[it.oIndex + j] = ox;
26748                                                }
26749                                        }
26750                                }
26751                        } else {
26752                                if (it.isOutputDouble()) {
26753                                        while (it.hasNext()) {
26754                                                for (int j = 0; j < is; j++) {
26755                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26756                                                        byte ox;
26757                                                        ox = (byte) toLong(Math.log1p(ix));
26758                                                        oai8data[it.oIndex + j] = ox;
26759                                                }
26760                                        }
26761                                } else {
26762                                        while (it.hasNext()) {
26763                                                for (int j = 0; j < is; j++) {
26764                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26765                                                        byte ox;
26766                                                        ox = (byte) toLong(Math.log1p(ix));
26767                                                        oai8data[it.oIndex + j] = ox;
26768                                                }
26769                                        }
26770                                }
26771                        }
26772                        break;
26773                case Dataset.ARRAYINT16:
26774                        final short[] oai16data = ((CompoundShortDataset) result).getData();
26775                        if (is == 1) {
26776                                if (it.isOutputDouble()) {
26777                                        while (it.hasNext()) {
26778                                                final double ix = it.aDouble;
26779                                                short ox;
26780                                                ox = (short) toLong(Math.log1p(ix));
26781                                                oai16data[it.oIndex] = ox;
26782                                        }
26783                                } else {
26784                                        while (it.hasNext()) {
26785                                                final long ix = it.aLong;
26786                                                short ox;
26787                                                ox = (short) toLong(Math.log1p(ix));
26788                                                oai16data[it.oIndex] = ox;
26789                                        }
26790                                }
26791                        } else if (as == 1) {
26792                                if (it.isOutputDouble()) {
26793                                        while (it.hasNext()) {
26794                                                final double ix = it.aDouble;
26795                                                short ox;
26796                                                ox = (short) toLong(Math.log1p(ix));
26797                                                for (int j = 0; j < is; j++) {
26798                                                        oai16data[it.oIndex + j] = ox;
26799                                                }
26800                                        }
26801                                } else {
26802                                        while (it.hasNext()) {
26803                                                final long ix = it.aLong;
26804                                                short ox;
26805                                                ox = (short) toLong(Math.log1p(ix));
26806                                                for (int j = 0; j < is; j++) {
26807                                                        oai16data[it.oIndex + j] = ox;
26808                                                }
26809                                        }
26810                                }
26811                        } else {
26812                                if (it.isOutputDouble()) {
26813                                        while (it.hasNext()) {
26814                                                for (int j = 0; j < is; j++) {
26815                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26816                                                        short ox;
26817                                                        ox = (short) toLong(Math.log1p(ix));
26818                                                        oai16data[it.oIndex + j] = ox;
26819                                                }
26820                                        }
26821                                } else {
26822                                        while (it.hasNext()) {
26823                                                for (int j = 0; j < is; j++) {
26824                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26825                                                        short ox;
26826                                                        ox = (short) toLong(Math.log1p(ix));
26827                                                        oai16data[it.oIndex + j] = ox;
26828                                                }
26829                                        }
26830                                }
26831                        }
26832                        break;
26833                case Dataset.ARRAYINT64:
26834                        final long[] oai64data = ((CompoundLongDataset) result).getData();
26835                        if (is == 1) {
26836                                if (it.isOutputDouble()) {
26837                                        while (it.hasNext()) {
26838                                                final double ix = it.aDouble;
26839                                                long ox;
26840                                                ox = toLong(Math.log1p(ix));
26841                                                oai64data[it.oIndex] = ox;
26842                                        }
26843                                } else {
26844                                        while (it.hasNext()) {
26845                                                final long ix = it.aLong;
26846                                                long ox;
26847                                                ox = toLong(Math.log1p(ix));
26848                                                oai64data[it.oIndex] = ox;
26849                                        }
26850                                }
26851                        } else if (as == 1) {
26852                                if (it.isOutputDouble()) {
26853                                        while (it.hasNext()) {
26854                                                final double ix = it.aDouble;
26855                                                long ox;
26856                                                ox = toLong(Math.log1p(ix));
26857                                                for (int j = 0; j < is; j++) {
26858                                                        oai64data[it.oIndex + j] = ox;
26859                                                }
26860                                        }
26861                                } else {
26862                                        while (it.hasNext()) {
26863                                                final long ix = it.aLong;
26864                                                long ox;
26865                                                ox = toLong(Math.log1p(ix));
26866                                                for (int j = 0; j < is; j++) {
26867                                                        oai64data[it.oIndex + j] = ox;
26868                                                }
26869                                        }
26870                                }
26871                        } else {
26872                                if (it.isOutputDouble()) {
26873                                        while (it.hasNext()) {
26874                                                for (int j = 0; j < is; j++) {
26875                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26876                                                        long ox;
26877                                                        ox = toLong(Math.log1p(ix));
26878                                                        oai64data[it.oIndex + j] = ox;
26879                                                }
26880                                        }
26881                                } else {
26882                                        while (it.hasNext()) {
26883                                                for (int j = 0; j < is; j++) {
26884                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26885                                                        long ox;
26886                                                        ox = toLong(Math.log1p(ix));
26887                                                        oai64data[it.oIndex + j] = ox;
26888                                                }
26889                                        }
26890                                }
26891                        }
26892                        break;
26893                case Dataset.ARRAYINT32:
26894                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
26895                        if (is == 1) {
26896                                if (it.isOutputDouble()) {
26897                                        while (it.hasNext()) {
26898                                                final double ix = it.aDouble;
26899                                                int ox;
26900                                                ox = (int) toLong(Math.log1p(ix));
26901                                                oai32data[it.oIndex] = ox;
26902                                        }
26903                                } else {
26904                                        while (it.hasNext()) {
26905                                                final long ix = it.aLong;
26906                                                int ox;
26907                                                ox = (int) toLong(Math.log1p(ix));
26908                                                oai32data[it.oIndex] = ox;
26909                                        }
26910                                }
26911                        } else if (as == 1) {
26912                                if (it.isOutputDouble()) {
26913                                        while (it.hasNext()) {
26914                                                final double ix = it.aDouble;
26915                                                int ox;
26916                                                ox = (int) toLong(Math.log1p(ix));
26917                                                for (int j = 0; j < is; j++) {
26918                                                        oai32data[it.oIndex + j] = ox;
26919                                                }
26920                                        }
26921                                } else {
26922                                        while (it.hasNext()) {
26923                                                final long ix = it.aLong;
26924                                                int ox;
26925                                                ox = (int) toLong(Math.log1p(ix));
26926                                                for (int j = 0; j < is; j++) {
26927                                                        oai32data[it.oIndex + j] = ox;
26928                                                }
26929                                        }
26930                                }
26931                        } else {
26932                                if (it.isOutputDouble()) {
26933                                        while (it.hasNext()) {
26934                                                for (int j = 0; j < is; j++) {
26935                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26936                                                        int ox;
26937                                                        ox = (int) toLong(Math.log1p(ix));
26938                                                        oai32data[it.oIndex + j] = ox;
26939                                                }
26940                                        }
26941                                } else {
26942                                        while (it.hasNext()) {
26943                                                for (int j = 0; j < is; j++) {
26944                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26945                                                        int ox;
26946                                                        ox = (int) toLong(Math.log1p(ix));
26947                                                        oai32data[it.oIndex + j] = ox;
26948                                                }
26949                                        }
26950                                }
26951                        }
26952                        break;
26953                case Dataset.FLOAT32:
26954                        final float[] of32data = ((FloatDataset) result).getData();
26955                        if (it.isOutputDouble()) {
26956                                while (it.hasNext()) {
26957                                        final double ix = it.aDouble;
26958                                        float ox;
26959                                        ox = (float) (Math.log1p(ix));
26960                                        of32data[it.oIndex] = ox;
26961                                }
26962                        } else {
26963                                while (it.hasNext()) {
26964                                        final long ix = it.aLong;
26965                                        float ox;
26966                                        ox = (float) (Math.log1p(ix));
26967                                        of32data[it.oIndex] = ox;
26968                                }
26969                        }
26970                        break;
26971                case Dataset.FLOAT64:
26972                        final double[] of64data = ((DoubleDataset) result).getData();
26973                        if (it.isOutputDouble()) {
26974                                while (it.hasNext()) {
26975                                        final double ix = it.aDouble;
26976                                        double ox;
26977                                        ox = (Math.log1p(ix));
26978                                        of64data[it.oIndex] = ox;
26979                                }
26980                        } else {
26981                                while (it.hasNext()) {
26982                                        final long ix = it.aLong;
26983                                        double ox;
26984                                        ox = (Math.log1p(ix));
26985                                        of64data[it.oIndex] = ox;
26986                                }
26987                        }
26988                        break;
26989                case Dataset.ARRAYFLOAT32:
26990                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
26991                        if (is == 1) {
26992                                if (it.isOutputDouble()) {
26993                                        while (it.hasNext()) {
26994                                                final double ix = it.aDouble;
26995                                                float ox;
26996                                                ox = (float) (Math.log1p(ix));
26997                                                oaf32data[it.oIndex] = ox;
26998                                        }
26999                                } else {
27000                                        while (it.hasNext()) {
27001                                                final long ix = it.aLong;
27002                                                float ox;
27003                                                ox = (float) (Math.log1p(ix));
27004                                                oaf32data[it.oIndex] = ox;
27005                                        }
27006                                }
27007                        } else if (as == 1) {
27008                                if (it.isOutputDouble()) {
27009                                        while (it.hasNext()) {
27010                                                final double ix = it.aDouble;
27011                                                float ox;
27012                                                ox = (float) (Math.log1p(ix));
27013                                                for (int j = 0; j < is; j++) {
27014                                                        oaf32data[it.oIndex + j] = ox;
27015                                                }
27016                                        }
27017                                } else {
27018                                        while (it.hasNext()) {
27019                                                final long ix = it.aLong;
27020                                                float ox;
27021                                                ox = (float) (Math.log1p(ix));
27022                                                for (int j = 0; j < is; j++) {
27023                                                        oaf32data[it.oIndex + j] = ox;
27024                                                }
27025                                        }
27026                                }
27027                        } else {
27028                                if (it.isOutputDouble()) {
27029                                        while (it.hasNext()) {
27030                                                for (int j = 0; j < is; j++) {
27031                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27032                                                        float ox;
27033                                                        ox = (float) (Math.log1p(ix));
27034                                                        oaf32data[it.oIndex + j] = ox;
27035                                                }
27036                                        }
27037                                } else {
27038                                        while (it.hasNext()) {
27039                                                for (int j = 0; j < is; j++) {
27040                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27041                                                        float ox;
27042                                                        ox = (float) (Math.log1p(ix));
27043                                                        oaf32data[it.oIndex + j] = ox;
27044                                                }
27045                                        }
27046                                }
27047                        }
27048                        break;
27049                case Dataset.ARRAYFLOAT64:
27050                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
27051                        if (is == 1) {
27052                                if (it.isOutputDouble()) {
27053                                        while (it.hasNext()) {
27054                                                final double ix = it.aDouble;
27055                                                double ox;
27056                                                ox = (Math.log1p(ix));
27057                                                oaf64data[it.oIndex] = ox;
27058                                        }
27059                                } else {
27060                                        while (it.hasNext()) {
27061                                                final long ix = it.aLong;
27062                                                double ox;
27063                                                ox = (Math.log1p(ix));
27064                                                oaf64data[it.oIndex] = ox;
27065                                        }
27066                                }
27067                        } else if (as == 1) {
27068                                if (it.isOutputDouble()) {
27069                                        while (it.hasNext()) {
27070                                                final double ix = it.aDouble;
27071                                                double ox;
27072                                                ox = (Math.log1p(ix));
27073                                                for (int j = 0; j < is; j++) {
27074                                                        oaf64data[it.oIndex + j] = ox;
27075                                                }
27076                                        }
27077                                } else {
27078                                        while (it.hasNext()) {
27079                                                final long ix = it.aLong;
27080                                                double ox;
27081                                                ox = (Math.log1p(ix));
27082                                                for (int j = 0; j < is; j++) {
27083                                                        oaf64data[it.oIndex + j] = ox;
27084                                                }
27085                                        }
27086                                }
27087                        } else {
27088                                if (it.isOutputDouble()) {
27089                                        while (it.hasNext()) {
27090                                                for (int j = 0; j < is; j++) {
27091                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27092                                                        double ox;
27093                                                        ox = (Math.log1p(ix));
27094                                                        oaf64data[it.oIndex + j] = ox;
27095                                                }
27096                                        }
27097                                } else {
27098                                        while (it.hasNext()) {
27099                                                for (int j = 0; j < is; j++) {
27100                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27101                                                        double ox;
27102                                                        ox = (Math.log1p(ix));
27103                                                        oaf64data[it.oIndex + j] = ox;
27104                                                }
27105                                        }
27106                                }
27107                        }
27108                        break;
27109                case Dataset.COMPLEX64:
27110                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
27111                        if (!da.isComplex()) {
27112                                if (it.isOutputDouble()) {
27113                                        final double iy = 0;
27114                                        while (it.hasNext()) {
27115                                                final double ix = it.aDouble;
27116                                                float ox;
27117                                                float oy;
27118                                                ox = (float) (0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
27119                                                oy = (float) (Math.atan2(iy, ix+1));
27120                                                oc64data[it.oIndex] = ox;
27121                                                oc64data[it.oIndex + 1] = oy;
27122                                        }
27123                                } else {
27124                                        final long iy = 0;
27125                                        while (it.hasNext()) {
27126                                                final long ix = it.aLong;
27127                                                float ox;
27128                                                float oy;
27129                                                ox = (float) toLong(0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
27130                                                oy = (float) toLong(Math.atan2(iy, ix+1));
27131                                                oc64data[it.oIndex] = ox;
27132                                                oc64data[it.oIndex + 1] = oy;
27133                                        }
27134                                }
27135                        } else {
27136                                while (it.hasNext()) {
27137                                        final double ix = it.aDouble;
27138                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
27139                                        float ox;
27140                                        float oy;
27141                                        ox = (float) (0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
27142                                        oy = (float) (Math.atan2(iy, ix+1));
27143                                        oc64data[it.oIndex] = ox;
27144                                        oc64data[it.oIndex + 1] = oy;
27145                                }
27146                        }
27147                        break;
27148                case Dataset.COMPLEX128:
27149                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
27150                        if (!da.isComplex()) {
27151                                if (it.isOutputDouble()) {
27152                                        final double iy = 0;
27153                                        while (it.hasNext()) {
27154                                                final double ix = it.aDouble;
27155                                                double ox;
27156                                                double oy;
27157                                                ox = (0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
27158                                                oy = (Math.atan2(iy, ix+1));
27159                                                oc128data[it.oIndex] = ox;
27160                                                oc128data[it.oIndex + 1] = oy;
27161                                        }
27162                                } else {
27163                                        final long iy = 0;
27164                                        while (it.hasNext()) {
27165                                                final long ix = it.aLong;
27166                                                double ox;
27167                                                double oy;
27168                                                ox = (double) (0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
27169                                                oy = (double) (Math.atan2(iy, ix+1));
27170                                                oc128data[it.oIndex] = ox;
27171                                                oc128data[it.oIndex + 1] = oy;
27172                                        }
27173                                }
27174                        } else {
27175                                while (it.hasNext()) {
27176                                        final double ix = it.aDouble;
27177                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
27178                                        double ox;
27179                                        double oy;
27180                                        ox = (0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
27181                                        oy = (Math.atan2(iy, ix+1));
27182                                        oc128data[it.oIndex] = ox;
27183                                        oc128data[it.oIndex + 1] = oy;
27184                                }
27185                        }
27186                        break;
27187                default:
27188                        throw new IllegalArgumentException("log1p supports integer, compound integer, real, compound real, complex datasets only");
27189                }
27190
27191                addFunctionName(result, "log1p");
27192                return result;
27193        }
27194
27195        /**
27196         * exp - evaluate the exponential function on each element of the dataset
27197         * @param a
27198         * @return dataset
27199         */
27200        public static Dataset exp(final Object a) {
27201                return exp(a, null);
27202        }
27203
27204        /**
27205         * exp - evaluate the exponential function on each element of the dataset
27206         * @param a
27207         * @param o output can be null - in which case, a new dataset is created
27208         * @return dataset
27209         */
27210        public static Dataset exp(final Object a, final Dataset o) {
27211                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
27212                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
27213                final Dataset result = it.getOutput();
27214                if (!result.isComplex()) {
27215                        if (da.isComplex()) {
27216                                da = da.getRealView();
27217                                it = new SingleInputBroadcastIterator(da, result, true);
27218                        }
27219                }
27220                final int is = result.getElementsPerItem();
27221                final int as = da.getElementsPerItem();
27222                final int dt = result.getDType();
27223
27224                switch(dt) {
27225                case Dataset.INT8:
27226                        final byte[] oi8data = ((ByteDataset) result).getData();
27227                        if (it.isOutputDouble()) {
27228                                while (it.hasNext()) {
27229                                        final double ix = it.aDouble;
27230                                        byte ox;
27231                                        ox = (byte) toLong(Math.exp(ix));
27232                                        oi8data[it.oIndex] = ox;
27233                                }
27234                        } else {
27235                                while (it.hasNext()) {
27236                                        final long ix = it.aLong;
27237                                        byte ox;
27238                                        ox = (byte) toLong(Math.exp(ix));
27239                                        oi8data[it.oIndex] = ox;
27240                                }
27241                        }
27242                        break;
27243                case Dataset.INT16:
27244                        final short[] oi16data = ((ShortDataset) result).getData();
27245                        if (it.isOutputDouble()) {
27246                                while (it.hasNext()) {
27247                                        final double ix = it.aDouble;
27248                                        short ox;
27249                                        ox = (short) toLong(Math.exp(ix));
27250                                        oi16data[it.oIndex] = ox;
27251                                }
27252                        } else {
27253                                while (it.hasNext()) {
27254                                        final long ix = it.aLong;
27255                                        short ox;
27256                                        ox = (short) toLong(Math.exp(ix));
27257                                        oi16data[it.oIndex] = ox;
27258                                }
27259                        }
27260                        break;
27261                case Dataset.INT64:
27262                        final long[] oi64data = ((LongDataset) result).getData();
27263                        if (it.isOutputDouble()) {
27264                                while (it.hasNext()) {
27265                                        final double ix = it.aDouble;
27266                                        long ox;
27267                                        ox = toLong(Math.exp(ix));
27268                                        oi64data[it.oIndex] = ox;
27269                                }
27270                        } else {
27271                                while (it.hasNext()) {
27272                                        final long ix = it.aLong;
27273                                        long ox;
27274                                        ox = toLong(Math.exp(ix));
27275                                        oi64data[it.oIndex] = ox;
27276                                }
27277                        }
27278                        break;
27279                case Dataset.INT32:
27280                        final int[] oi32data = ((IntegerDataset) result).getData();
27281                        if (it.isOutputDouble()) {
27282                                while (it.hasNext()) {
27283                                        final double ix = it.aDouble;
27284                                        int ox;
27285                                        ox = (int) toLong(Math.exp(ix));
27286                                        oi32data[it.oIndex] = ox;
27287                                }
27288                        } else {
27289                                while (it.hasNext()) {
27290                                        final long ix = it.aLong;
27291                                        int ox;
27292                                        ox = (int) toLong(Math.exp(ix));
27293                                        oi32data[it.oIndex] = ox;
27294                                }
27295                        }
27296                        break;
27297                case Dataset.ARRAYINT8:
27298                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
27299                        if (is == 1) {
27300                                if (it.isOutputDouble()) {
27301                                        while (it.hasNext()) {
27302                                                final double ix = it.aDouble;
27303                                                byte ox;
27304                                                ox = (byte) toLong(Math.exp(ix));
27305                                                oai8data[it.oIndex] = ox;
27306                                        }
27307                                } else {
27308                                        while (it.hasNext()) {
27309                                                final long ix = it.aLong;
27310                                                byte ox;
27311                                                ox = (byte) toLong(Math.exp(ix));
27312                                                oai8data[it.oIndex] = ox;
27313                                        }
27314                                }
27315                        } else if (as == 1) {
27316                                if (it.isOutputDouble()) {
27317                                        while (it.hasNext()) {
27318                                                final double ix = it.aDouble;
27319                                                byte ox;
27320                                                ox = (byte) toLong(Math.exp(ix));
27321                                                for (int j = 0; j < is; j++) {
27322                                                        oai8data[it.oIndex + j] = ox;
27323                                                }
27324                                        }
27325                                } else {
27326                                        while (it.hasNext()) {
27327                                                final long ix = it.aLong;
27328                                                byte ox;
27329                                                ox = (byte) toLong(Math.exp(ix));
27330                                                for (int j = 0; j < is; j++) {
27331                                                        oai8data[it.oIndex + j] = ox;
27332                                                }
27333                                        }
27334                                }
27335                        } else {
27336                                if (it.isOutputDouble()) {
27337                                        while (it.hasNext()) {
27338                                                for (int j = 0; j < is; j++) {
27339                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27340                                                        byte ox;
27341                                                        ox = (byte) toLong(Math.exp(ix));
27342                                                        oai8data[it.oIndex + j] = ox;
27343                                                }
27344                                        }
27345                                } else {
27346                                        while (it.hasNext()) {
27347                                                for (int j = 0; j < is; j++) {
27348                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27349                                                        byte ox;
27350                                                        ox = (byte) toLong(Math.exp(ix));
27351                                                        oai8data[it.oIndex + j] = ox;
27352                                                }
27353                                        }
27354                                }
27355                        }
27356                        break;
27357                case Dataset.ARRAYINT16:
27358                        final short[] oai16data = ((CompoundShortDataset) result).getData();
27359                        if (is == 1) {
27360                                if (it.isOutputDouble()) {
27361                                        while (it.hasNext()) {
27362                                                final double ix = it.aDouble;
27363                                                short ox;
27364                                                ox = (short) toLong(Math.exp(ix));
27365                                                oai16data[it.oIndex] = ox;
27366                                        }
27367                                } else {
27368                                        while (it.hasNext()) {
27369                                                final long ix = it.aLong;
27370                                                short ox;
27371                                                ox = (short) toLong(Math.exp(ix));
27372                                                oai16data[it.oIndex] = ox;
27373                                        }
27374                                }
27375                        } else if (as == 1) {
27376                                if (it.isOutputDouble()) {
27377                                        while (it.hasNext()) {
27378                                                final double ix = it.aDouble;
27379                                                short ox;
27380                                                ox = (short) toLong(Math.exp(ix));
27381                                                for (int j = 0; j < is; j++) {
27382                                                        oai16data[it.oIndex + j] = ox;
27383                                                }
27384                                        }
27385                                } else {
27386                                        while (it.hasNext()) {
27387                                                final long ix = it.aLong;
27388                                                short ox;
27389                                                ox = (short) toLong(Math.exp(ix));
27390                                                for (int j = 0; j < is; j++) {
27391                                                        oai16data[it.oIndex + j] = ox;
27392                                                }
27393                                        }
27394                                }
27395                        } else {
27396                                if (it.isOutputDouble()) {
27397                                        while (it.hasNext()) {
27398                                                for (int j = 0; j < is; j++) {
27399                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27400                                                        short ox;
27401                                                        ox = (short) toLong(Math.exp(ix));
27402                                                        oai16data[it.oIndex + j] = ox;
27403                                                }
27404                                        }
27405                                } else {
27406                                        while (it.hasNext()) {
27407                                                for (int j = 0; j < is; j++) {
27408                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27409                                                        short ox;
27410                                                        ox = (short) toLong(Math.exp(ix));
27411                                                        oai16data[it.oIndex + j] = ox;
27412                                                }
27413                                        }
27414                                }
27415                        }
27416                        break;
27417                case Dataset.ARRAYINT64:
27418                        final long[] oai64data = ((CompoundLongDataset) result).getData();
27419                        if (is == 1) {
27420                                if (it.isOutputDouble()) {
27421                                        while (it.hasNext()) {
27422                                                final double ix = it.aDouble;
27423                                                long ox;
27424                                                ox = toLong(Math.exp(ix));
27425                                                oai64data[it.oIndex] = ox;
27426                                        }
27427                                } else {
27428                                        while (it.hasNext()) {
27429                                                final long ix = it.aLong;
27430                                                long ox;
27431                                                ox = toLong(Math.exp(ix));
27432                                                oai64data[it.oIndex] = ox;
27433                                        }
27434                                }
27435                        } else if (as == 1) {
27436                                if (it.isOutputDouble()) {
27437                                        while (it.hasNext()) {
27438                                                final double ix = it.aDouble;
27439                                                long ox;
27440                                                ox = toLong(Math.exp(ix));
27441                                                for (int j = 0; j < is; j++) {
27442                                                        oai64data[it.oIndex + j] = ox;
27443                                                }
27444                                        }
27445                                } else {
27446                                        while (it.hasNext()) {
27447                                                final long ix = it.aLong;
27448                                                long ox;
27449                                                ox = toLong(Math.exp(ix));
27450                                                for (int j = 0; j < is; j++) {
27451                                                        oai64data[it.oIndex + j] = ox;
27452                                                }
27453                                        }
27454                                }
27455                        } else {
27456                                if (it.isOutputDouble()) {
27457                                        while (it.hasNext()) {
27458                                                for (int j = 0; j < is; j++) {
27459                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27460                                                        long ox;
27461                                                        ox = toLong(Math.exp(ix));
27462                                                        oai64data[it.oIndex + j] = ox;
27463                                                }
27464                                        }
27465                                } else {
27466                                        while (it.hasNext()) {
27467                                                for (int j = 0; j < is; j++) {
27468                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27469                                                        long ox;
27470                                                        ox = toLong(Math.exp(ix));
27471                                                        oai64data[it.oIndex + j] = ox;
27472                                                }
27473                                        }
27474                                }
27475                        }
27476                        break;
27477                case Dataset.ARRAYINT32:
27478                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
27479                        if (is == 1) {
27480                                if (it.isOutputDouble()) {
27481                                        while (it.hasNext()) {
27482                                                final double ix = it.aDouble;
27483                                                int ox;
27484                                                ox = (int) toLong(Math.exp(ix));
27485                                                oai32data[it.oIndex] = ox;
27486                                        }
27487                                } else {
27488                                        while (it.hasNext()) {
27489                                                final long ix = it.aLong;
27490                                                int ox;
27491                                                ox = (int) toLong(Math.exp(ix));
27492                                                oai32data[it.oIndex] = ox;
27493                                        }
27494                                }
27495                        } else if (as == 1) {
27496                                if (it.isOutputDouble()) {
27497                                        while (it.hasNext()) {
27498                                                final double ix = it.aDouble;
27499                                                int ox;
27500                                                ox = (int) toLong(Math.exp(ix));
27501                                                for (int j = 0; j < is; j++) {
27502                                                        oai32data[it.oIndex + j] = ox;
27503                                                }
27504                                        }
27505                                } else {
27506                                        while (it.hasNext()) {
27507                                                final long ix = it.aLong;
27508                                                int ox;
27509                                                ox = (int) toLong(Math.exp(ix));
27510                                                for (int j = 0; j < is; j++) {
27511                                                        oai32data[it.oIndex + j] = ox;
27512                                                }
27513                                        }
27514                                }
27515                        } else {
27516                                if (it.isOutputDouble()) {
27517                                        while (it.hasNext()) {
27518                                                for (int j = 0; j < is; j++) {
27519                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27520                                                        int ox;
27521                                                        ox = (int) toLong(Math.exp(ix));
27522                                                        oai32data[it.oIndex + j] = ox;
27523                                                }
27524                                        }
27525                                } else {
27526                                        while (it.hasNext()) {
27527                                                for (int j = 0; j < is; j++) {
27528                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27529                                                        int ox;
27530                                                        ox = (int) toLong(Math.exp(ix));
27531                                                        oai32data[it.oIndex + j] = ox;
27532                                                }
27533                                        }
27534                                }
27535                        }
27536                        break;
27537                case Dataset.FLOAT32:
27538                        final float[] of32data = ((FloatDataset) result).getData();
27539                        if (it.isOutputDouble()) {
27540                                while (it.hasNext()) {
27541                                        final double ix = it.aDouble;
27542                                        float ox;
27543                                        ox = (float) (Math.exp(ix));
27544                                        of32data[it.oIndex] = ox;
27545                                }
27546                        } else {
27547                                while (it.hasNext()) {
27548                                        final long ix = it.aLong;
27549                                        float ox;
27550                                        ox = (float) (Math.exp(ix));
27551                                        of32data[it.oIndex] = ox;
27552                                }
27553                        }
27554                        break;
27555                case Dataset.FLOAT64:
27556                        final double[] of64data = ((DoubleDataset) result).getData();
27557                        if (it.isOutputDouble()) {
27558                                while (it.hasNext()) {
27559                                        final double ix = it.aDouble;
27560                                        double ox;
27561                                        ox = (Math.exp(ix));
27562                                        of64data[it.oIndex] = ox;
27563                                }
27564                        } else {
27565                                while (it.hasNext()) {
27566                                        final long ix = it.aLong;
27567                                        double ox;
27568                                        ox = (Math.exp(ix));
27569                                        of64data[it.oIndex] = ox;
27570                                }
27571                        }
27572                        break;
27573                case Dataset.ARRAYFLOAT32:
27574                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
27575                        if (is == 1) {
27576                                if (it.isOutputDouble()) {
27577                                        while (it.hasNext()) {
27578                                                final double ix = it.aDouble;
27579                                                float ox;
27580                                                ox = (float) (Math.exp(ix));
27581                                                oaf32data[it.oIndex] = ox;
27582                                        }
27583                                } else {
27584                                        while (it.hasNext()) {
27585                                                final long ix = it.aLong;
27586                                                float ox;
27587                                                ox = (float) (Math.exp(ix));
27588                                                oaf32data[it.oIndex] = ox;
27589                                        }
27590                                }
27591                        } else if (as == 1) {
27592                                if (it.isOutputDouble()) {
27593                                        while (it.hasNext()) {
27594                                                final double ix = it.aDouble;
27595                                                float ox;
27596                                                ox = (float) (Math.exp(ix));
27597                                                for (int j = 0; j < is; j++) {
27598                                                        oaf32data[it.oIndex + j] = ox;
27599                                                }
27600                                        }
27601                                } else {
27602                                        while (it.hasNext()) {
27603                                                final long ix = it.aLong;
27604                                                float ox;
27605                                                ox = (float) (Math.exp(ix));
27606                                                for (int j = 0; j < is; j++) {
27607                                                        oaf32data[it.oIndex + j] = ox;
27608                                                }
27609                                        }
27610                                }
27611                        } else {
27612                                if (it.isOutputDouble()) {
27613                                        while (it.hasNext()) {
27614                                                for (int j = 0; j < is; j++) {
27615                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27616                                                        float ox;
27617                                                        ox = (float) (Math.exp(ix));
27618                                                        oaf32data[it.oIndex + j] = ox;
27619                                                }
27620                                        }
27621                                } else {
27622                                        while (it.hasNext()) {
27623                                                for (int j = 0; j < is; j++) {
27624                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27625                                                        float ox;
27626                                                        ox = (float) (Math.exp(ix));
27627                                                        oaf32data[it.oIndex + j] = ox;
27628                                                }
27629                                        }
27630                                }
27631                        }
27632                        break;
27633                case Dataset.ARRAYFLOAT64:
27634                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
27635                        if (is == 1) {
27636                                if (it.isOutputDouble()) {
27637                                        while (it.hasNext()) {
27638                                                final double ix = it.aDouble;
27639                                                double ox;
27640                                                ox = (Math.exp(ix));
27641                                                oaf64data[it.oIndex] = ox;
27642                                        }
27643                                } else {
27644                                        while (it.hasNext()) {
27645                                                final long ix = it.aLong;
27646                                                double ox;
27647                                                ox = (Math.exp(ix));
27648                                                oaf64data[it.oIndex] = ox;
27649                                        }
27650                                }
27651                        } else if (as == 1) {
27652                                if (it.isOutputDouble()) {
27653                                        while (it.hasNext()) {
27654                                                final double ix = it.aDouble;
27655                                                double ox;
27656                                                ox = (Math.exp(ix));
27657                                                for (int j = 0; j < is; j++) {
27658                                                        oaf64data[it.oIndex + j] = ox;
27659                                                }
27660                                        }
27661                                } else {
27662                                        while (it.hasNext()) {
27663                                                final long ix = it.aLong;
27664                                                double ox;
27665                                                ox = (Math.exp(ix));
27666                                                for (int j = 0; j < is; j++) {
27667                                                        oaf64data[it.oIndex + j] = ox;
27668                                                }
27669                                        }
27670                                }
27671                        } else {
27672                                if (it.isOutputDouble()) {
27673                                        while (it.hasNext()) {
27674                                                for (int j = 0; j < is; j++) {
27675                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27676                                                        double ox;
27677                                                        ox = (Math.exp(ix));
27678                                                        oaf64data[it.oIndex + j] = ox;
27679                                                }
27680                                        }
27681                                } else {
27682                                        while (it.hasNext()) {
27683                                                for (int j = 0; j < is; j++) {
27684                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27685                                                        double ox;
27686                                                        ox = (Math.exp(ix));
27687                                                        oaf64data[it.oIndex + j] = ox;
27688                                                }
27689                                        }
27690                                }
27691                        }
27692                        break;
27693                case Dataset.COMPLEX64:
27694                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
27695                        if (!da.isComplex()) {
27696                                if (it.isOutputDouble()) {
27697                                        final double iy = 0;
27698                                        while (it.hasNext()) {
27699                                                final double ix = it.aDouble;
27700                                                float tf;
27701                                                float ox;
27702                                                float oy;
27703                                                tf = (float) (Math.exp(ix));
27704                                                ox = (float) (tf*Math.cos(iy));
27705                                                oy = (float) (tf*Math.sin(iy));
27706                                                oc64data[it.oIndex] = ox;
27707                                                oc64data[it.oIndex + 1] = oy;
27708                                        }
27709                                } else {
27710                                        final long iy = 0;
27711                                        while (it.hasNext()) {
27712                                                final long ix = it.aLong;
27713                                                float tf;
27714                                                float ox;
27715                                                float oy;
27716                                                tf = (float) toLong(Math.exp(ix));
27717                                                ox = (float) toLong(tf*Math.cos(iy));
27718                                                oy = (float) toLong(tf*Math.sin(iy));
27719                                                oc64data[it.oIndex] = ox;
27720                                                oc64data[it.oIndex + 1] = oy;
27721                                        }
27722                                }
27723                        } else {
27724                                while (it.hasNext()) {
27725                                        final double ix = it.aDouble;
27726                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
27727                                        float tf;
27728                                        float ox;
27729                                        float oy;
27730                                        tf = (float) (Math.exp(ix));
27731                                        ox = (float) (tf*Math.cos(iy));
27732                                        oy = (float) (tf*Math.sin(iy));
27733                                        oc64data[it.oIndex] = ox;
27734                                        oc64data[it.oIndex + 1] = oy;
27735                                }
27736                        }
27737                        break;
27738                case Dataset.COMPLEX128:
27739                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
27740                        if (!da.isComplex()) {
27741                                if (it.isOutputDouble()) {
27742                                        final double iy = 0;
27743                                        while (it.hasNext()) {
27744                                                final double ix = it.aDouble;
27745                                                double tf;
27746                                                double ox;
27747                                                double oy;
27748                                                tf = (Math.exp(ix));
27749                                                ox = (tf*Math.cos(iy));
27750                                                oy = (tf*Math.sin(iy));
27751                                                oc128data[it.oIndex] = ox;
27752                                                oc128data[it.oIndex + 1] = oy;
27753                                        }
27754                                } else {
27755                                        final long iy = 0;
27756                                        while (it.hasNext()) {
27757                                                final long ix = it.aLong;
27758                                                double tf;
27759                                                double ox;
27760                                                double oy;
27761                                                tf = (double) (Math.exp(ix));
27762                                                ox = (double) (tf*Math.cos(iy));
27763                                                oy = (double) (tf*Math.sin(iy));
27764                                                oc128data[it.oIndex] = ox;
27765                                                oc128data[it.oIndex + 1] = oy;
27766                                        }
27767                                }
27768                        } else {
27769                                while (it.hasNext()) {
27770                                        final double ix = it.aDouble;
27771                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
27772                                        double tf;
27773                                        double ox;
27774                                        double oy;
27775                                        tf = (Math.exp(ix));
27776                                        ox = (tf*Math.cos(iy));
27777                                        oy = (tf*Math.sin(iy));
27778                                        oc128data[it.oIndex] = ox;
27779                                        oc128data[it.oIndex + 1] = oy;
27780                                }
27781                        }
27782                        break;
27783                default:
27784                        throw new IllegalArgumentException("exp supports integer, compound integer, real, compound real, complex datasets only");
27785                }
27786
27787                addFunctionName(result, "exp");
27788                return result;
27789        }
27790
27791        /**
27792         * expm1 - evaluate the exponential function - 1 on each element of the dataset
27793         * @param a
27794         * @return dataset
27795         */
27796        public static Dataset expm1(final Object a) {
27797                return expm1(a, null);
27798        }
27799
27800        /**
27801         * expm1 - evaluate the exponential function - 1 on each element of the dataset
27802         * @param a
27803         * @param o output can be null - in which case, a new dataset is created
27804         * @return dataset
27805         */
27806        public static Dataset expm1(final Object a, final Dataset o) {
27807                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
27808                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
27809                final Dataset result = it.getOutput();
27810                if (!result.isComplex()) {
27811                        if (da.isComplex()) {
27812                                da = da.getRealView();
27813                                it = new SingleInputBroadcastIterator(da, result, true);
27814                        }
27815                }
27816                final int is = result.getElementsPerItem();
27817                final int as = da.getElementsPerItem();
27818                final int dt = result.getDType();
27819
27820                switch(dt) {
27821                case Dataset.INT8:
27822                        final byte[] oi8data = ((ByteDataset) result).getData();
27823                        if (it.isOutputDouble()) {
27824                                while (it.hasNext()) {
27825                                        final double ix = it.aDouble;
27826                                        byte ox;
27827                                        ox = (byte) toLong(Math.expm1(ix));
27828                                        oi8data[it.oIndex] = ox;
27829                                }
27830                        } else {
27831                                while (it.hasNext()) {
27832                                        final long ix = it.aLong;
27833                                        byte ox;
27834                                        ox = (byte) toLong(Math.expm1(ix));
27835                                        oi8data[it.oIndex] = ox;
27836                                }
27837                        }
27838                        break;
27839                case Dataset.INT16:
27840                        final short[] oi16data = ((ShortDataset) result).getData();
27841                        if (it.isOutputDouble()) {
27842                                while (it.hasNext()) {
27843                                        final double ix = it.aDouble;
27844                                        short ox;
27845                                        ox = (short) toLong(Math.expm1(ix));
27846                                        oi16data[it.oIndex] = ox;
27847                                }
27848                        } else {
27849                                while (it.hasNext()) {
27850                                        final long ix = it.aLong;
27851                                        short ox;
27852                                        ox = (short) toLong(Math.expm1(ix));
27853                                        oi16data[it.oIndex] = ox;
27854                                }
27855                        }
27856                        break;
27857                case Dataset.INT64:
27858                        final long[] oi64data = ((LongDataset) result).getData();
27859                        if (it.isOutputDouble()) {
27860                                while (it.hasNext()) {
27861                                        final double ix = it.aDouble;
27862                                        long ox;
27863                                        ox = toLong(Math.expm1(ix));
27864                                        oi64data[it.oIndex] = ox;
27865                                }
27866                        } else {
27867                                while (it.hasNext()) {
27868                                        final long ix = it.aLong;
27869                                        long ox;
27870                                        ox = toLong(Math.expm1(ix));
27871                                        oi64data[it.oIndex] = ox;
27872                                }
27873                        }
27874                        break;
27875                case Dataset.INT32:
27876                        final int[] oi32data = ((IntegerDataset) result).getData();
27877                        if (it.isOutputDouble()) {
27878                                while (it.hasNext()) {
27879                                        final double ix = it.aDouble;
27880                                        int ox;
27881                                        ox = (int) toLong(Math.expm1(ix));
27882                                        oi32data[it.oIndex] = ox;
27883                                }
27884                        } else {
27885                                while (it.hasNext()) {
27886                                        final long ix = it.aLong;
27887                                        int ox;
27888                                        ox = (int) toLong(Math.expm1(ix));
27889                                        oi32data[it.oIndex] = ox;
27890                                }
27891                        }
27892                        break;
27893                case Dataset.ARRAYINT8:
27894                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
27895                        if (is == 1) {
27896                                if (it.isOutputDouble()) {
27897                                        while (it.hasNext()) {
27898                                                final double ix = it.aDouble;
27899                                                byte ox;
27900                                                ox = (byte) toLong(Math.expm1(ix));
27901                                                oai8data[it.oIndex] = ox;
27902                                        }
27903                                } else {
27904                                        while (it.hasNext()) {
27905                                                final long ix = it.aLong;
27906                                                byte ox;
27907                                                ox = (byte) toLong(Math.expm1(ix));
27908                                                oai8data[it.oIndex] = ox;
27909                                        }
27910                                }
27911                        } else if (as == 1) {
27912                                if (it.isOutputDouble()) {
27913                                        while (it.hasNext()) {
27914                                                final double ix = it.aDouble;
27915                                                byte ox;
27916                                                ox = (byte) toLong(Math.expm1(ix));
27917                                                for (int j = 0; j < is; j++) {
27918                                                        oai8data[it.oIndex + j] = ox;
27919                                                }
27920                                        }
27921                                } else {
27922                                        while (it.hasNext()) {
27923                                                final long ix = it.aLong;
27924                                                byte ox;
27925                                                ox = (byte) toLong(Math.expm1(ix));
27926                                                for (int j = 0; j < is; j++) {
27927                                                        oai8data[it.oIndex + j] = ox;
27928                                                }
27929                                        }
27930                                }
27931                        } else {
27932                                if (it.isOutputDouble()) {
27933                                        while (it.hasNext()) {
27934                                                for (int j = 0; j < is; j++) {
27935                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27936                                                        byte ox;
27937                                                        ox = (byte) toLong(Math.expm1(ix));
27938                                                        oai8data[it.oIndex + j] = ox;
27939                                                }
27940                                        }
27941                                } else {
27942                                        while (it.hasNext()) {
27943                                                for (int j = 0; j < is; j++) {
27944                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27945                                                        byte ox;
27946                                                        ox = (byte) toLong(Math.expm1(ix));
27947                                                        oai8data[it.oIndex + j] = ox;
27948                                                }
27949                                        }
27950                                }
27951                        }
27952                        break;
27953                case Dataset.ARRAYINT16:
27954                        final short[] oai16data = ((CompoundShortDataset) result).getData();
27955                        if (is == 1) {
27956                                if (it.isOutputDouble()) {
27957                                        while (it.hasNext()) {
27958                                                final double ix = it.aDouble;
27959                                                short ox;
27960                                                ox = (short) toLong(Math.expm1(ix));
27961                                                oai16data[it.oIndex] = ox;
27962                                        }
27963                                } else {
27964                                        while (it.hasNext()) {
27965                                                final long ix = it.aLong;
27966                                                short ox;
27967                                                ox = (short) toLong(Math.expm1(ix));
27968                                                oai16data[it.oIndex] = ox;
27969                                        }
27970                                }
27971                        } else if (as == 1) {
27972                                if (it.isOutputDouble()) {
27973                                        while (it.hasNext()) {
27974                                                final double ix = it.aDouble;
27975                                                short ox;
27976                                                ox = (short) toLong(Math.expm1(ix));
27977                                                for (int j = 0; j < is; j++) {
27978                                                        oai16data[it.oIndex + j] = ox;
27979                                                }
27980                                        }
27981                                } else {
27982                                        while (it.hasNext()) {
27983                                                final long ix = it.aLong;
27984                                                short ox;
27985                                                ox = (short) toLong(Math.expm1(ix));
27986                                                for (int j = 0; j < is; j++) {
27987                                                        oai16data[it.oIndex + j] = ox;
27988                                                }
27989                                        }
27990                                }
27991                        } else {
27992                                if (it.isOutputDouble()) {
27993                                        while (it.hasNext()) {
27994                                                for (int j = 0; j < is; j++) {
27995                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27996                                                        short ox;
27997                                                        ox = (short) toLong(Math.expm1(ix));
27998                                                        oai16data[it.oIndex + j] = ox;
27999                                                }
28000                                        }
28001                                } else {
28002                                        while (it.hasNext()) {
28003                                                for (int j = 0; j < is; j++) {
28004                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28005                                                        short ox;
28006                                                        ox = (short) toLong(Math.expm1(ix));
28007                                                        oai16data[it.oIndex + j] = ox;
28008                                                }
28009                                        }
28010                                }
28011                        }
28012                        break;
28013                case Dataset.ARRAYINT64:
28014                        final long[] oai64data = ((CompoundLongDataset) result).getData();
28015                        if (is == 1) {
28016                                if (it.isOutputDouble()) {
28017                                        while (it.hasNext()) {
28018                                                final double ix = it.aDouble;
28019                                                long ox;
28020                                                ox = toLong(Math.expm1(ix));
28021                                                oai64data[it.oIndex] = ox;
28022                                        }
28023                                } else {
28024                                        while (it.hasNext()) {
28025                                                final long ix = it.aLong;
28026                                                long ox;
28027                                                ox = toLong(Math.expm1(ix));
28028                                                oai64data[it.oIndex] = ox;
28029                                        }
28030                                }
28031                        } else if (as == 1) {
28032                                if (it.isOutputDouble()) {
28033                                        while (it.hasNext()) {
28034                                                final double ix = it.aDouble;
28035                                                long ox;
28036                                                ox = toLong(Math.expm1(ix));
28037                                                for (int j = 0; j < is; j++) {
28038                                                        oai64data[it.oIndex + j] = ox;
28039                                                }
28040                                        }
28041                                } else {
28042                                        while (it.hasNext()) {
28043                                                final long ix = it.aLong;
28044                                                long ox;
28045                                                ox = toLong(Math.expm1(ix));
28046                                                for (int j = 0; j < is; j++) {
28047                                                        oai64data[it.oIndex + j] = ox;
28048                                                }
28049                                        }
28050                                }
28051                        } else {
28052                                if (it.isOutputDouble()) {
28053                                        while (it.hasNext()) {
28054                                                for (int j = 0; j < is; j++) {
28055                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28056                                                        long ox;
28057                                                        ox = toLong(Math.expm1(ix));
28058                                                        oai64data[it.oIndex + j] = ox;
28059                                                }
28060                                        }
28061                                } else {
28062                                        while (it.hasNext()) {
28063                                                for (int j = 0; j < is; j++) {
28064                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28065                                                        long ox;
28066                                                        ox = toLong(Math.expm1(ix));
28067                                                        oai64data[it.oIndex + j] = ox;
28068                                                }
28069                                        }
28070                                }
28071                        }
28072                        break;
28073                case Dataset.ARRAYINT32:
28074                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
28075                        if (is == 1) {
28076                                if (it.isOutputDouble()) {
28077                                        while (it.hasNext()) {
28078                                                final double ix = it.aDouble;
28079                                                int ox;
28080                                                ox = (int) toLong(Math.expm1(ix));
28081                                                oai32data[it.oIndex] = ox;
28082                                        }
28083                                } else {
28084                                        while (it.hasNext()) {
28085                                                final long ix = it.aLong;
28086                                                int ox;
28087                                                ox = (int) toLong(Math.expm1(ix));
28088                                                oai32data[it.oIndex] = ox;
28089                                        }
28090                                }
28091                        } else if (as == 1) {
28092                                if (it.isOutputDouble()) {
28093                                        while (it.hasNext()) {
28094                                                final double ix = it.aDouble;
28095                                                int ox;
28096                                                ox = (int) toLong(Math.expm1(ix));
28097                                                for (int j = 0; j < is; j++) {
28098                                                        oai32data[it.oIndex + j] = ox;
28099                                                }
28100                                        }
28101                                } else {
28102                                        while (it.hasNext()) {
28103                                                final long ix = it.aLong;
28104                                                int ox;
28105                                                ox = (int) toLong(Math.expm1(ix));
28106                                                for (int j = 0; j < is; j++) {
28107                                                        oai32data[it.oIndex + j] = ox;
28108                                                }
28109                                        }
28110                                }
28111                        } else {
28112                                if (it.isOutputDouble()) {
28113                                        while (it.hasNext()) {
28114                                                for (int j = 0; j < is; j++) {
28115                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28116                                                        int ox;
28117                                                        ox = (int) toLong(Math.expm1(ix));
28118                                                        oai32data[it.oIndex + j] = ox;
28119                                                }
28120                                        }
28121                                } else {
28122                                        while (it.hasNext()) {
28123                                                for (int j = 0; j < is; j++) {
28124                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28125                                                        int ox;
28126                                                        ox = (int) toLong(Math.expm1(ix));
28127                                                        oai32data[it.oIndex + j] = ox;
28128                                                }
28129                                        }
28130                                }
28131                        }
28132                        break;
28133                case Dataset.FLOAT32:
28134                        final float[] of32data = ((FloatDataset) result).getData();
28135                        if (it.isOutputDouble()) {
28136                                while (it.hasNext()) {
28137                                        final double ix = it.aDouble;
28138                                        float ox;
28139                                        ox = (float) (Math.expm1(ix));
28140                                        of32data[it.oIndex] = ox;
28141                                }
28142                        } else {
28143                                while (it.hasNext()) {
28144                                        final long ix = it.aLong;
28145                                        float ox;
28146                                        ox = (float) (Math.expm1(ix));
28147                                        of32data[it.oIndex] = ox;
28148                                }
28149                        }
28150                        break;
28151                case Dataset.FLOAT64:
28152                        final double[] of64data = ((DoubleDataset) result).getData();
28153                        if (it.isOutputDouble()) {
28154                                while (it.hasNext()) {
28155                                        final double ix = it.aDouble;
28156                                        double ox;
28157                                        ox = (Math.expm1(ix));
28158                                        of64data[it.oIndex] = ox;
28159                                }
28160                        } else {
28161                                while (it.hasNext()) {
28162                                        final long ix = it.aLong;
28163                                        double ox;
28164                                        ox = (Math.expm1(ix));
28165                                        of64data[it.oIndex] = ox;
28166                                }
28167                        }
28168                        break;
28169                case Dataset.ARRAYFLOAT32:
28170                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
28171                        if (is == 1) {
28172                                if (it.isOutputDouble()) {
28173                                        while (it.hasNext()) {
28174                                                final double ix = it.aDouble;
28175                                                float ox;
28176                                                ox = (float) (Math.expm1(ix));
28177                                                oaf32data[it.oIndex] = ox;
28178                                        }
28179                                } else {
28180                                        while (it.hasNext()) {
28181                                                final long ix = it.aLong;
28182                                                float ox;
28183                                                ox = (float) (Math.expm1(ix));
28184                                                oaf32data[it.oIndex] = ox;
28185                                        }
28186                                }
28187                        } else if (as == 1) {
28188                                if (it.isOutputDouble()) {
28189                                        while (it.hasNext()) {
28190                                                final double ix = it.aDouble;
28191                                                float ox;
28192                                                ox = (float) (Math.expm1(ix));
28193                                                for (int j = 0; j < is; j++) {
28194                                                        oaf32data[it.oIndex + j] = ox;
28195                                                }
28196                                        }
28197                                } else {
28198                                        while (it.hasNext()) {
28199                                                final long ix = it.aLong;
28200                                                float ox;
28201                                                ox = (float) (Math.expm1(ix));
28202                                                for (int j = 0; j < is; j++) {
28203                                                        oaf32data[it.oIndex + j] = ox;
28204                                                }
28205                                        }
28206                                }
28207                        } else {
28208                                if (it.isOutputDouble()) {
28209                                        while (it.hasNext()) {
28210                                                for (int j = 0; j < is; j++) {
28211                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28212                                                        float ox;
28213                                                        ox = (float) (Math.expm1(ix));
28214                                                        oaf32data[it.oIndex + j] = ox;
28215                                                }
28216                                        }
28217                                } else {
28218                                        while (it.hasNext()) {
28219                                                for (int j = 0; j < is; j++) {
28220                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28221                                                        float ox;
28222                                                        ox = (float) (Math.expm1(ix));
28223                                                        oaf32data[it.oIndex + j] = ox;
28224                                                }
28225                                        }
28226                                }
28227                        }
28228                        break;
28229                case Dataset.ARRAYFLOAT64:
28230                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
28231                        if (is == 1) {
28232                                if (it.isOutputDouble()) {
28233                                        while (it.hasNext()) {
28234                                                final double ix = it.aDouble;
28235                                                double ox;
28236                                                ox = (Math.expm1(ix));
28237                                                oaf64data[it.oIndex] = ox;
28238                                        }
28239                                } else {
28240                                        while (it.hasNext()) {
28241                                                final long ix = it.aLong;
28242                                                double ox;
28243                                                ox = (Math.expm1(ix));
28244                                                oaf64data[it.oIndex] = ox;
28245                                        }
28246                                }
28247                        } else if (as == 1) {
28248                                if (it.isOutputDouble()) {
28249                                        while (it.hasNext()) {
28250                                                final double ix = it.aDouble;
28251                                                double ox;
28252                                                ox = (Math.expm1(ix));
28253                                                for (int j = 0; j < is; j++) {
28254                                                        oaf64data[it.oIndex + j] = ox;
28255                                                }
28256                                        }
28257                                } else {
28258                                        while (it.hasNext()) {
28259                                                final long ix = it.aLong;
28260                                                double ox;
28261                                                ox = (Math.expm1(ix));
28262                                                for (int j = 0; j < is; j++) {
28263                                                        oaf64data[it.oIndex + j] = ox;
28264                                                }
28265                                        }
28266                                }
28267                        } else {
28268                                if (it.isOutputDouble()) {
28269                                        while (it.hasNext()) {
28270                                                for (int j = 0; j < is; j++) {
28271                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28272                                                        double ox;
28273                                                        ox = (Math.expm1(ix));
28274                                                        oaf64data[it.oIndex + j] = ox;
28275                                                }
28276                                        }
28277                                } else {
28278                                        while (it.hasNext()) {
28279                                                for (int j = 0; j < is; j++) {
28280                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28281                                                        double ox;
28282                                                        ox = (Math.expm1(ix));
28283                                                        oaf64data[it.oIndex + j] = ox;
28284                                                }
28285                                        }
28286                                }
28287                        }
28288                        break;
28289                case Dataset.COMPLEX64:
28290                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
28291                        if (!da.isComplex()) {
28292                                if (it.isOutputDouble()) {
28293                                        final double iy = 0;
28294                                        while (it.hasNext()) {
28295                                                final double ix = it.aDouble;
28296                                                float tf;
28297                                                float ox;
28298                                                float oy;
28299                                                tf = (float) (Math.expm1(ix));
28300                                                ox = (float) (tf*Math.cos(iy));
28301                                                oy = (float) (tf*Math.sin(iy));
28302                                                oc64data[it.oIndex] = ox;
28303                                                oc64data[it.oIndex + 1] = oy;
28304                                        }
28305                                } else {
28306                                        final long iy = 0;
28307                                        while (it.hasNext()) {
28308                                                final long ix = it.aLong;
28309                                                float tf;
28310                                                float ox;
28311                                                float oy;
28312                                                tf = (float) toLong(Math.expm1(ix));
28313                                                ox = (float) toLong(tf*Math.cos(iy));
28314                                                oy = (float) toLong(tf*Math.sin(iy));
28315                                                oc64data[it.oIndex] = ox;
28316                                                oc64data[it.oIndex + 1] = oy;
28317                                        }
28318                                }
28319                        } else {
28320                                while (it.hasNext()) {
28321                                        final double ix = it.aDouble;
28322                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
28323                                        float tf;
28324                                        float ox;
28325                                        float oy;
28326                                        tf = (float) (Math.expm1(ix));
28327                                        ox = (float) (tf*Math.cos(iy));
28328                                        oy = (float) (tf*Math.sin(iy));
28329                                        oc64data[it.oIndex] = ox;
28330                                        oc64data[it.oIndex + 1] = oy;
28331                                }
28332                        }
28333                        break;
28334                case Dataset.COMPLEX128:
28335                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
28336                        if (!da.isComplex()) {
28337                                if (it.isOutputDouble()) {
28338                                        final double iy = 0;
28339                                        while (it.hasNext()) {
28340                                                final double ix = it.aDouble;
28341                                                double tf;
28342                                                double ox;
28343                                                double oy;
28344                                                tf = (Math.expm1(ix));
28345                                                ox = (tf*Math.cos(iy));
28346                                                oy = (tf*Math.sin(iy));
28347                                                oc128data[it.oIndex] = ox;
28348                                                oc128data[it.oIndex + 1] = oy;
28349                                        }
28350                                } else {
28351                                        final long iy = 0;
28352                                        while (it.hasNext()) {
28353                                                final long ix = it.aLong;
28354                                                double tf;
28355                                                double ox;
28356                                                double oy;
28357                                                tf = (double) (Math.expm1(ix));
28358                                                ox = (double) (tf*Math.cos(iy));
28359                                                oy = (double) (tf*Math.sin(iy));
28360                                                oc128data[it.oIndex] = ox;
28361                                                oc128data[it.oIndex + 1] = oy;
28362                                        }
28363                                }
28364                        } else {
28365                                while (it.hasNext()) {
28366                                        final double ix = it.aDouble;
28367                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
28368                                        double tf;
28369                                        double ox;
28370                                        double oy;
28371                                        tf = (Math.expm1(ix));
28372                                        ox = (tf*Math.cos(iy));
28373                                        oy = (tf*Math.sin(iy));
28374                                        oc128data[it.oIndex] = ox;
28375                                        oc128data[it.oIndex + 1] = oy;
28376                                }
28377                        }
28378                        break;
28379                default:
28380                        throw new IllegalArgumentException("expm1 supports integer, compound integer, real, compound real, complex datasets only");
28381                }
28382
28383                addFunctionName(result, "expm1");
28384                return result;
28385        }
28386
28387        /**
28388         * sqrt - evaluate the square root function on each element of the dataset
28389         * @param a
28390         * @return dataset
28391         */
28392        public static Dataset sqrt(final Object a) {
28393                return sqrt(a, null);
28394        }
28395
28396        /**
28397         * sqrt - evaluate the square root function on each element of the dataset
28398         * @param a
28399         * @param o output can be null - in which case, a new dataset is created
28400         * @return dataset
28401         */
28402        public static Dataset sqrt(final Object a, final Dataset o) {
28403                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
28404                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
28405                final Dataset result = it.getOutput();
28406                if (!result.isComplex()) {
28407                        if (da.isComplex()) {
28408                                da = da.getRealView();
28409                                it = new SingleInputBroadcastIterator(da, result, true);
28410                        }
28411                }
28412                final int is = result.getElementsPerItem();
28413                final int as = da.getElementsPerItem();
28414                final int dt = result.getDType();
28415
28416                switch(dt) {
28417                case Dataset.INT8:
28418                        final byte[] oi8data = ((ByteDataset) result).getData();
28419                        if (it.isOutputDouble()) {
28420                                while (it.hasNext()) {
28421                                        final double ix = it.aDouble;
28422                                        byte ox;
28423                                        ox = (byte) toLong(Math.sqrt(ix));
28424                                        oi8data[it.oIndex] = ox;
28425                                }
28426                        } else {
28427                                while (it.hasNext()) {
28428                                        final long ix = it.aLong;
28429                                        byte ox;
28430                                        ox = (byte) toLong(Math.sqrt(ix));
28431                                        oi8data[it.oIndex] = ox;
28432                                }
28433                        }
28434                        break;
28435                case Dataset.INT16:
28436                        final short[] oi16data = ((ShortDataset) result).getData();
28437                        if (it.isOutputDouble()) {
28438                                while (it.hasNext()) {
28439                                        final double ix = it.aDouble;
28440                                        short ox;
28441                                        ox = (short) toLong(Math.sqrt(ix));
28442                                        oi16data[it.oIndex] = ox;
28443                                }
28444                        } else {
28445                                while (it.hasNext()) {
28446                                        final long ix = it.aLong;
28447                                        short ox;
28448                                        ox = (short) toLong(Math.sqrt(ix));
28449                                        oi16data[it.oIndex] = ox;
28450                                }
28451                        }
28452                        break;
28453                case Dataset.INT64:
28454                        final long[] oi64data = ((LongDataset) result).getData();
28455                        if (it.isOutputDouble()) {
28456                                while (it.hasNext()) {
28457                                        final double ix = it.aDouble;
28458                                        long ox;
28459                                        ox = toLong(Math.sqrt(ix));
28460                                        oi64data[it.oIndex] = ox;
28461                                }
28462                        } else {
28463                                while (it.hasNext()) {
28464                                        final long ix = it.aLong;
28465                                        long ox;
28466                                        ox = toLong(Math.sqrt(ix));
28467                                        oi64data[it.oIndex] = ox;
28468                                }
28469                        }
28470                        break;
28471                case Dataset.INT32:
28472                        final int[] oi32data = ((IntegerDataset) result).getData();
28473                        if (it.isOutputDouble()) {
28474                                while (it.hasNext()) {
28475                                        final double ix = it.aDouble;
28476                                        int ox;
28477                                        ox = (int) toLong(Math.sqrt(ix));
28478                                        oi32data[it.oIndex] = ox;
28479                                }
28480                        } else {
28481                                while (it.hasNext()) {
28482                                        final long ix = it.aLong;
28483                                        int ox;
28484                                        ox = (int) toLong(Math.sqrt(ix));
28485                                        oi32data[it.oIndex] = ox;
28486                                }
28487                        }
28488                        break;
28489                case Dataset.ARRAYINT8:
28490                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
28491                        if (is == 1) {
28492                                if (it.isOutputDouble()) {
28493                                        while (it.hasNext()) {
28494                                                final double ix = it.aDouble;
28495                                                byte ox;
28496                                                ox = (byte) toLong(Math.sqrt(ix));
28497                                                oai8data[it.oIndex] = ox;
28498                                        }
28499                                } else {
28500                                        while (it.hasNext()) {
28501                                                final long ix = it.aLong;
28502                                                byte ox;
28503                                                ox = (byte) toLong(Math.sqrt(ix));
28504                                                oai8data[it.oIndex] = ox;
28505                                        }
28506                                }
28507                        } else if (as == 1) {
28508                                if (it.isOutputDouble()) {
28509                                        while (it.hasNext()) {
28510                                                final double ix = it.aDouble;
28511                                                byte ox;
28512                                                ox = (byte) toLong(Math.sqrt(ix));
28513                                                for (int j = 0; j < is; j++) {
28514                                                        oai8data[it.oIndex + j] = ox;
28515                                                }
28516                                        }
28517                                } else {
28518                                        while (it.hasNext()) {
28519                                                final long ix = it.aLong;
28520                                                byte ox;
28521                                                ox = (byte) toLong(Math.sqrt(ix));
28522                                                for (int j = 0; j < is; j++) {
28523                                                        oai8data[it.oIndex + j] = ox;
28524                                                }
28525                                        }
28526                                }
28527                        } else {
28528                                if (it.isOutputDouble()) {
28529                                        while (it.hasNext()) {
28530                                                for (int j = 0; j < is; j++) {
28531                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28532                                                        byte ox;
28533                                                        ox = (byte) toLong(Math.sqrt(ix));
28534                                                        oai8data[it.oIndex + j] = ox;
28535                                                }
28536                                        }
28537                                } else {
28538                                        while (it.hasNext()) {
28539                                                for (int j = 0; j < is; j++) {
28540                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28541                                                        byte ox;
28542                                                        ox = (byte) toLong(Math.sqrt(ix));
28543                                                        oai8data[it.oIndex + j] = ox;
28544                                                }
28545                                        }
28546                                }
28547                        }
28548                        break;
28549                case Dataset.ARRAYINT16:
28550                        final short[] oai16data = ((CompoundShortDataset) result).getData();
28551                        if (is == 1) {
28552                                if (it.isOutputDouble()) {
28553                                        while (it.hasNext()) {
28554                                                final double ix = it.aDouble;
28555                                                short ox;
28556                                                ox = (short) toLong(Math.sqrt(ix));
28557                                                oai16data[it.oIndex] = ox;
28558                                        }
28559                                } else {
28560                                        while (it.hasNext()) {
28561                                                final long ix = it.aLong;
28562                                                short ox;
28563                                                ox = (short) toLong(Math.sqrt(ix));
28564                                                oai16data[it.oIndex] = ox;
28565                                        }
28566                                }
28567                        } else if (as == 1) {
28568                                if (it.isOutputDouble()) {
28569                                        while (it.hasNext()) {
28570                                                final double ix = it.aDouble;
28571                                                short ox;
28572                                                ox = (short) toLong(Math.sqrt(ix));
28573                                                for (int j = 0; j < is; j++) {
28574                                                        oai16data[it.oIndex + j] = ox;
28575                                                }
28576                                        }
28577                                } else {
28578                                        while (it.hasNext()) {
28579                                                final long ix = it.aLong;
28580                                                short ox;
28581                                                ox = (short) toLong(Math.sqrt(ix));
28582                                                for (int j = 0; j < is; j++) {
28583                                                        oai16data[it.oIndex + j] = ox;
28584                                                }
28585                                        }
28586                                }
28587                        } else {
28588                                if (it.isOutputDouble()) {
28589                                        while (it.hasNext()) {
28590                                                for (int j = 0; j < is; j++) {
28591                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28592                                                        short ox;
28593                                                        ox = (short) toLong(Math.sqrt(ix));
28594                                                        oai16data[it.oIndex + j] = ox;
28595                                                }
28596                                        }
28597                                } else {
28598                                        while (it.hasNext()) {
28599                                                for (int j = 0; j < is; j++) {
28600                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28601                                                        short ox;
28602                                                        ox = (short) toLong(Math.sqrt(ix));
28603                                                        oai16data[it.oIndex + j] = ox;
28604                                                }
28605                                        }
28606                                }
28607                        }
28608                        break;
28609                case Dataset.ARRAYINT64:
28610                        final long[] oai64data = ((CompoundLongDataset) result).getData();
28611                        if (is == 1) {
28612                                if (it.isOutputDouble()) {
28613                                        while (it.hasNext()) {
28614                                                final double ix = it.aDouble;
28615                                                long ox;
28616                                                ox = toLong(Math.sqrt(ix));
28617                                                oai64data[it.oIndex] = ox;
28618                                        }
28619                                } else {
28620                                        while (it.hasNext()) {
28621                                                final long ix = it.aLong;
28622                                                long ox;
28623                                                ox = toLong(Math.sqrt(ix));
28624                                                oai64data[it.oIndex] = ox;
28625                                        }
28626                                }
28627                        } else if (as == 1) {
28628                                if (it.isOutputDouble()) {
28629                                        while (it.hasNext()) {
28630                                                final double ix = it.aDouble;
28631                                                long ox;
28632                                                ox = toLong(Math.sqrt(ix));
28633                                                for (int j = 0; j < is; j++) {
28634                                                        oai64data[it.oIndex + j] = ox;
28635                                                }
28636                                        }
28637                                } else {
28638                                        while (it.hasNext()) {
28639                                                final long ix = it.aLong;
28640                                                long ox;
28641                                                ox = toLong(Math.sqrt(ix));
28642                                                for (int j = 0; j < is; j++) {
28643                                                        oai64data[it.oIndex + j] = ox;
28644                                                }
28645                                        }
28646                                }
28647                        } else {
28648                                if (it.isOutputDouble()) {
28649                                        while (it.hasNext()) {
28650                                                for (int j = 0; j < is; j++) {
28651                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28652                                                        long ox;
28653                                                        ox = toLong(Math.sqrt(ix));
28654                                                        oai64data[it.oIndex + j] = ox;
28655                                                }
28656                                        }
28657                                } else {
28658                                        while (it.hasNext()) {
28659                                                for (int j = 0; j < is; j++) {
28660                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28661                                                        long ox;
28662                                                        ox = toLong(Math.sqrt(ix));
28663                                                        oai64data[it.oIndex + j] = ox;
28664                                                }
28665                                        }
28666                                }
28667                        }
28668                        break;
28669                case Dataset.ARRAYINT32:
28670                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
28671                        if (is == 1) {
28672                                if (it.isOutputDouble()) {
28673                                        while (it.hasNext()) {
28674                                                final double ix = it.aDouble;
28675                                                int ox;
28676                                                ox = (int) toLong(Math.sqrt(ix));
28677                                                oai32data[it.oIndex] = ox;
28678                                        }
28679                                } else {
28680                                        while (it.hasNext()) {
28681                                                final long ix = it.aLong;
28682                                                int ox;
28683                                                ox = (int) toLong(Math.sqrt(ix));
28684                                                oai32data[it.oIndex] = ox;
28685                                        }
28686                                }
28687                        } else if (as == 1) {
28688                                if (it.isOutputDouble()) {
28689                                        while (it.hasNext()) {
28690                                                final double ix = it.aDouble;
28691                                                int ox;
28692                                                ox = (int) toLong(Math.sqrt(ix));
28693                                                for (int j = 0; j < is; j++) {
28694                                                        oai32data[it.oIndex + j] = ox;
28695                                                }
28696                                        }
28697                                } else {
28698                                        while (it.hasNext()) {
28699                                                final long ix = it.aLong;
28700                                                int ox;
28701                                                ox = (int) toLong(Math.sqrt(ix));
28702                                                for (int j = 0; j < is; j++) {
28703                                                        oai32data[it.oIndex + j] = ox;
28704                                                }
28705                                        }
28706                                }
28707                        } else {
28708                                if (it.isOutputDouble()) {
28709                                        while (it.hasNext()) {
28710                                                for (int j = 0; j < is; j++) {
28711                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28712                                                        int ox;
28713                                                        ox = (int) toLong(Math.sqrt(ix));
28714                                                        oai32data[it.oIndex + j] = ox;
28715                                                }
28716                                        }
28717                                } else {
28718                                        while (it.hasNext()) {
28719                                                for (int j = 0; j < is; j++) {
28720                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28721                                                        int ox;
28722                                                        ox = (int) toLong(Math.sqrt(ix));
28723                                                        oai32data[it.oIndex + j] = ox;
28724                                                }
28725                                        }
28726                                }
28727                        }
28728                        break;
28729                case Dataset.FLOAT32:
28730                        final float[] of32data = ((FloatDataset) result).getData();
28731                        if (it.isOutputDouble()) {
28732                                while (it.hasNext()) {
28733                                        final double ix = it.aDouble;
28734                                        float ox;
28735                                        ox = (float) (Math.sqrt(ix));
28736                                        of32data[it.oIndex] = ox;
28737                                }
28738                        } else {
28739                                while (it.hasNext()) {
28740                                        final long ix = it.aLong;
28741                                        float ox;
28742                                        ox = (float) (Math.sqrt(ix));
28743                                        of32data[it.oIndex] = ox;
28744                                }
28745                        }
28746                        break;
28747                case Dataset.FLOAT64:
28748                        final double[] of64data = ((DoubleDataset) result).getData();
28749                        if (it.isOutputDouble()) {
28750                                while (it.hasNext()) {
28751                                        final double ix = it.aDouble;
28752                                        double ox;
28753                                        ox = (Math.sqrt(ix));
28754                                        of64data[it.oIndex] = ox;
28755                                }
28756                        } else {
28757                                while (it.hasNext()) {
28758                                        final long ix = it.aLong;
28759                                        double ox;
28760                                        ox = (Math.sqrt(ix));
28761                                        of64data[it.oIndex] = ox;
28762                                }
28763                        }
28764                        break;
28765                case Dataset.ARRAYFLOAT32:
28766                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
28767                        if (is == 1) {
28768                                if (it.isOutputDouble()) {
28769                                        while (it.hasNext()) {
28770                                                final double ix = it.aDouble;
28771                                                float ox;
28772                                                ox = (float) (Math.sqrt(ix));
28773                                                oaf32data[it.oIndex] = ox;
28774                                        }
28775                                } else {
28776                                        while (it.hasNext()) {
28777                                                final long ix = it.aLong;
28778                                                float ox;
28779                                                ox = (float) (Math.sqrt(ix));
28780                                                oaf32data[it.oIndex] = ox;
28781                                        }
28782                                }
28783                        } else if (as == 1) {
28784                                if (it.isOutputDouble()) {
28785                                        while (it.hasNext()) {
28786                                                final double ix = it.aDouble;
28787                                                float ox;
28788                                                ox = (float) (Math.sqrt(ix));
28789                                                for (int j = 0; j < is; j++) {
28790                                                        oaf32data[it.oIndex + j] = ox;
28791                                                }
28792                                        }
28793                                } else {
28794                                        while (it.hasNext()) {
28795                                                final long ix = it.aLong;
28796                                                float ox;
28797                                                ox = (float) (Math.sqrt(ix));
28798                                                for (int j = 0; j < is; j++) {
28799                                                        oaf32data[it.oIndex + j] = ox;
28800                                                }
28801                                        }
28802                                }
28803                        } else {
28804                                if (it.isOutputDouble()) {
28805                                        while (it.hasNext()) {
28806                                                for (int j = 0; j < is; j++) {
28807                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28808                                                        float ox;
28809                                                        ox = (float) (Math.sqrt(ix));
28810                                                        oaf32data[it.oIndex + j] = ox;
28811                                                }
28812                                        }
28813                                } else {
28814                                        while (it.hasNext()) {
28815                                                for (int j = 0; j < is; j++) {
28816                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28817                                                        float ox;
28818                                                        ox = (float) (Math.sqrt(ix));
28819                                                        oaf32data[it.oIndex + j] = ox;
28820                                                }
28821                                        }
28822                                }
28823                        }
28824                        break;
28825                case Dataset.ARRAYFLOAT64:
28826                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
28827                        if (is == 1) {
28828                                if (it.isOutputDouble()) {
28829                                        while (it.hasNext()) {
28830                                                final double ix = it.aDouble;
28831                                                double ox;
28832                                                ox = (Math.sqrt(ix));
28833                                                oaf64data[it.oIndex] = ox;
28834                                        }
28835                                } else {
28836                                        while (it.hasNext()) {
28837                                                final long ix = it.aLong;
28838                                                double ox;
28839                                                ox = (Math.sqrt(ix));
28840                                                oaf64data[it.oIndex] = ox;
28841                                        }
28842                                }
28843                        } else if (as == 1) {
28844                                if (it.isOutputDouble()) {
28845                                        while (it.hasNext()) {
28846                                                final double ix = it.aDouble;
28847                                                double ox;
28848                                                ox = (Math.sqrt(ix));
28849                                                for (int j = 0; j < is; j++) {
28850                                                        oaf64data[it.oIndex + j] = ox;
28851                                                }
28852                                        }
28853                                } else {
28854                                        while (it.hasNext()) {
28855                                                final long ix = it.aLong;
28856                                                double ox;
28857                                                ox = (Math.sqrt(ix));
28858                                                for (int j = 0; j < is; j++) {
28859                                                        oaf64data[it.oIndex + j] = ox;
28860                                                }
28861                                        }
28862                                }
28863                        } else {
28864                                if (it.isOutputDouble()) {
28865                                        while (it.hasNext()) {
28866                                                for (int j = 0; j < is; j++) {
28867                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28868                                                        double ox;
28869                                                        ox = (Math.sqrt(ix));
28870                                                        oaf64data[it.oIndex + j] = ox;
28871                                                }
28872                                        }
28873                                } else {
28874                                        while (it.hasNext()) {
28875                                                for (int j = 0; j < is; j++) {
28876                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28877                                                        double ox;
28878                                                        ox = (Math.sqrt(ix));
28879                                                        oaf64data[it.oIndex + j] = ox;
28880                                                }
28881                                        }
28882                                }
28883                        }
28884                        break;
28885                case Dataset.COMPLEX64:
28886                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
28887                        if (!da.isComplex()) {
28888                                if (it.isOutputDouble()) {
28889                                        final double iy = 0;
28890                                        while (it.hasNext()) {
28891                                                final double ix = it.aDouble;
28892                                                Complex tz;
28893                                                float ox;
28894                                                float oy;
28895                                                tz = new Complex(ix, iy).sqrt();
28896                                                ox = (float) (tz.getReal());
28897                                                oy = (float) (tz.getImaginary());
28898                                                oc64data[it.oIndex] = ox;
28899                                                oc64data[it.oIndex + 1] = oy;
28900                                        }
28901                                } else {
28902                                        final long iy = 0;
28903                                        while (it.hasNext()) {
28904                                                final long ix = it.aLong;
28905                                                Complex tz;
28906                                                float ox;
28907                                                float oy;
28908                                                tz = new Complex(ix, iy).sqrt();
28909                                                ox = (float) toLong(tz.getReal());
28910                                                oy = (float) toLong(tz.getImaginary());
28911                                                oc64data[it.oIndex] = ox;
28912                                                oc64data[it.oIndex + 1] = oy;
28913                                        }
28914                                }
28915                        } else {
28916                                while (it.hasNext()) {
28917                                        final double ix = it.aDouble;
28918                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
28919                                        Complex tz;
28920                                        float ox;
28921                                        float oy;
28922                                        tz = new Complex(ix, iy).sqrt();
28923                                        ox = (float) (tz.getReal());
28924                                        oy = (float) (tz.getImaginary());
28925                                        oc64data[it.oIndex] = ox;
28926                                        oc64data[it.oIndex + 1] = oy;
28927                                }
28928                        }
28929                        break;
28930                case Dataset.COMPLEX128:
28931                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
28932                        if (!da.isComplex()) {
28933                                if (it.isOutputDouble()) {
28934                                        final double iy = 0;
28935                                        while (it.hasNext()) {
28936                                                final double ix = it.aDouble;
28937                                                Complex tz;
28938                                                double ox;
28939                                                double oy;
28940                                                tz = new Complex(ix, iy).sqrt();
28941                                                ox = (tz.getReal());
28942                                                oy = (tz.getImaginary());
28943                                                oc128data[it.oIndex] = ox;
28944                                                oc128data[it.oIndex + 1] = oy;
28945                                        }
28946                                } else {
28947                                        final long iy = 0;
28948                                        while (it.hasNext()) {
28949                                                final long ix = it.aLong;
28950                                                Complex tz;
28951                                                double ox;
28952                                                double oy;
28953                                                tz = new Complex(ix, iy).sqrt();
28954                                                ox = (tz.getReal());
28955                                                oy = (tz.getImaginary());
28956                                                oc128data[it.oIndex] = ox;
28957                                                oc128data[it.oIndex + 1] = oy;
28958                                        }
28959                                }
28960                        } else {
28961                                while (it.hasNext()) {
28962                                        final double ix = it.aDouble;
28963                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
28964                                        Complex tz;
28965                                        double ox;
28966                                        double oy;
28967                                        tz = new Complex(ix, iy).sqrt();
28968                                        ox = (tz.getReal());
28969                                        oy = (tz.getImaginary());
28970                                        oc128data[it.oIndex] = ox;
28971                                        oc128data[it.oIndex + 1] = oy;
28972                                }
28973                        }
28974                        break;
28975                default:
28976                        throw new IllegalArgumentException("sqrt supports integer, compound integer, real, compound real, complex datasets only");
28977                }
28978
28979                addFunctionName(result, "sqrt");
28980                return result;
28981        }
28982
28983        /**
28984         * cbrt - evaluate the cube root function on each element of the dataset
28985         * @param a
28986         * @return dataset
28987         */
28988        public static Dataset cbrt(final Object a) {
28989                return cbrt(a, null);
28990        }
28991
28992        /**
28993         * cbrt - evaluate the cube root function on each element of the dataset
28994         * @param a
28995         * @param o output can be null - in which case, a new dataset is created
28996         * @return dataset
28997         */
28998        public static Dataset cbrt(final Object a, final Dataset o) {
28999                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
29000                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
29001                final Dataset result = it.getOutput();
29002                if (!result.isComplex()) {
29003                        if (da.isComplex()) {
29004                                da = da.getRealView();
29005                                it = new SingleInputBroadcastIterator(da, result, true);
29006                        }
29007                }
29008                final int is = result.getElementsPerItem();
29009                final int as = da.getElementsPerItem();
29010                final int dt = result.getDType();
29011
29012                switch(dt) {
29013                case Dataset.INT8:
29014                        final byte[] oi8data = ((ByteDataset) result).getData();
29015                        if (it.isOutputDouble()) {
29016                                while (it.hasNext()) {
29017                                        final double ix = it.aDouble;
29018                                        byte ox;
29019                                        ox = (byte) toLong(Math.cbrt(ix));
29020                                        oi8data[it.oIndex] = ox;
29021                                }
29022                        } else {
29023                                while (it.hasNext()) {
29024                                        final long ix = it.aLong;
29025                                        byte ox;
29026                                        ox = (byte) toLong(Math.cbrt(ix));
29027                                        oi8data[it.oIndex] = ox;
29028                                }
29029                        }
29030                        break;
29031                case Dataset.INT16:
29032                        final short[] oi16data = ((ShortDataset) result).getData();
29033                        if (it.isOutputDouble()) {
29034                                while (it.hasNext()) {
29035                                        final double ix = it.aDouble;
29036                                        short ox;
29037                                        ox = (short) toLong(Math.cbrt(ix));
29038                                        oi16data[it.oIndex] = ox;
29039                                }
29040                        } else {
29041                                while (it.hasNext()) {
29042                                        final long ix = it.aLong;
29043                                        short ox;
29044                                        ox = (short) toLong(Math.cbrt(ix));
29045                                        oi16data[it.oIndex] = ox;
29046                                }
29047                        }
29048                        break;
29049                case Dataset.INT64:
29050                        final long[] oi64data = ((LongDataset) result).getData();
29051                        if (it.isOutputDouble()) {
29052                                while (it.hasNext()) {
29053                                        final double ix = it.aDouble;
29054                                        long ox;
29055                                        ox = toLong(Math.cbrt(ix));
29056                                        oi64data[it.oIndex] = ox;
29057                                }
29058                        } else {
29059                                while (it.hasNext()) {
29060                                        final long ix = it.aLong;
29061                                        long ox;
29062                                        ox = toLong(Math.cbrt(ix));
29063                                        oi64data[it.oIndex] = ox;
29064                                }
29065                        }
29066                        break;
29067                case Dataset.INT32:
29068                        final int[] oi32data = ((IntegerDataset) result).getData();
29069                        if (it.isOutputDouble()) {
29070                                while (it.hasNext()) {
29071                                        final double ix = it.aDouble;
29072                                        int ox;
29073                                        ox = (int) toLong(Math.cbrt(ix));
29074                                        oi32data[it.oIndex] = ox;
29075                                }
29076                        } else {
29077                                while (it.hasNext()) {
29078                                        final long ix = it.aLong;
29079                                        int ox;
29080                                        ox = (int) toLong(Math.cbrt(ix));
29081                                        oi32data[it.oIndex] = ox;
29082                                }
29083                        }
29084                        break;
29085                case Dataset.ARRAYINT8:
29086                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
29087                        if (is == 1) {
29088                                if (it.isOutputDouble()) {
29089                                        while (it.hasNext()) {
29090                                                final double ix = it.aDouble;
29091                                                byte ox;
29092                                                ox = (byte) toLong(Math.cbrt(ix));
29093                                                oai8data[it.oIndex] = ox;
29094                                        }
29095                                } else {
29096                                        while (it.hasNext()) {
29097                                                final long ix = it.aLong;
29098                                                byte ox;
29099                                                ox = (byte) toLong(Math.cbrt(ix));
29100                                                oai8data[it.oIndex] = ox;
29101                                        }
29102                                }
29103                        } else if (as == 1) {
29104                                if (it.isOutputDouble()) {
29105                                        while (it.hasNext()) {
29106                                                final double ix = it.aDouble;
29107                                                byte ox;
29108                                                ox = (byte) toLong(Math.cbrt(ix));
29109                                                for (int j = 0; j < is; j++) {
29110                                                        oai8data[it.oIndex + j] = ox;
29111                                                }
29112                                        }
29113                                } else {
29114                                        while (it.hasNext()) {
29115                                                final long ix = it.aLong;
29116                                                byte ox;
29117                                                ox = (byte) toLong(Math.cbrt(ix));
29118                                                for (int j = 0; j < is; j++) {
29119                                                        oai8data[it.oIndex + j] = ox;
29120                                                }
29121                                        }
29122                                }
29123                        } else {
29124                                if (it.isOutputDouble()) {
29125                                        while (it.hasNext()) {
29126                                                for (int j = 0; j < is; j++) {
29127                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29128                                                        byte ox;
29129                                                        ox = (byte) toLong(Math.cbrt(ix));
29130                                                        oai8data[it.oIndex + j] = ox;
29131                                                }
29132                                        }
29133                                } else {
29134                                        while (it.hasNext()) {
29135                                                for (int j = 0; j < is; j++) {
29136                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29137                                                        byte ox;
29138                                                        ox = (byte) toLong(Math.cbrt(ix));
29139                                                        oai8data[it.oIndex + j] = ox;
29140                                                }
29141                                        }
29142                                }
29143                        }
29144                        break;
29145                case Dataset.ARRAYINT16:
29146                        final short[] oai16data = ((CompoundShortDataset) result).getData();
29147                        if (is == 1) {
29148                                if (it.isOutputDouble()) {
29149                                        while (it.hasNext()) {
29150                                                final double ix = it.aDouble;
29151                                                short ox;
29152                                                ox = (short) toLong(Math.cbrt(ix));
29153                                                oai16data[it.oIndex] = ox;
29154                                        }
29155                                } else {
29156                                        while (it.hasNext()) {
29157                                                final long ix = it.aLong;
29158                                                short ox;
29159                                                ox = (short) toLong(Math.cbrt(ix));
29160                                                oai16data[it.oIndex] = ox;
29161                                        }
29162                                }
29163                        } else if (as == 1) {
29164                                if (it.isOutputDouble()) {
29165                                        while (it.hasNext()) {
29166                                                final double ix = it.aDouble;
29167                                                short ox;
29168                                                ox = (short) toLong(Math.cbrt(ix));
29169                                                for (int j = 0; j < is; j++) {
29170                                                        oai16data[it.oIndex + j] = ox;
29171                                                }
29172                                        }
29173                                } else {
29174                                        while (it.hasNext()) {
29175                                                final long ix = it.aLong;
29176                                                short ox;
29177                                                ox = (short) toLong(Math.cbrt(ix));
29178                                                for (int j = 0; j < is; j++) {
29179                                                        oai16data[it.oIndex + j] = ox;
29180                                                }
29181                                        }
29182                                }
29183                        } else {
29184                                if (it.isOutputDouble()) {
29185                                        while (it.hasNext()) {
29186                                                for (int j = 0; j < is; j++) {
29187                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29188                                                        short ox;
29189                                                        ox = (short) toLong(Math.cbrt(ix));
29190                                                        oai16data[it.oIndex + j] = ox;
29191                                                }
29192                                        }
29193                                } else {
29194                                        while (it.hasNext()) {
29195                                                for (int j = 0; j < is; j++) {
29196                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29197                                                        short ox;
29198                                                        ox = (short) toLong(Math.cbrt(ix));
29199                                                        oai16data[it.oIndex + j] = ox;
29200                                                }
29201                                        }
29202                                }
29203                        }
29204                        break;
29205                case Dataset.ARRAYINT64:
29206                        final long[] oai64data = ((CompoundLongDataset) result).getData();
29207                        if (is == 1) {
29208                                if (it.isOutputDouble()) {
29209                                        while (it.hasNext()) {
29210                                                final double ix = it.aDouble;
29211                                                long ox;
29212                                                ox = toLong(Math.cbrt(ix));
29213                                                oai64data[it.oIndex] = ox;
29214                                        }
29215                                } else {
29216                                        while (it.hasNext()) {
29217                                                final long ix = it.aLong;
29218                                                long ox;
29219                                                ox = toLong(Math.cbrt(ix));
29220                                                oai64data[it.oIndex] = ox;
29221                                        }
29222                                }
29223                        } else if (as == 1) {
29224                                if (it.isOutputDouble()) {
29225                                        while (it.hasNext()) {
29226                                                final double ix = it.aDouble;
29227                                                long ox;
29228                                                ox = toLong(Math.cbrt(ix));
29229                                                for (int j = 0; j < is; j++) {
29230                                                        oai64data[it.oIndex + j] = ox;
29231                                                }
29232                                        }
29233                                } else {
29234                                        while (it.hasNext()) {
29235                                                final long ix = it.aLong;
29236                                                long ox;
29237                                                ox = toLong(Math.cbrt(ix));
29238                                                for (int j = 0; j < is; j++) {
29239                                                        oai64data[it.oIndex + j] = ox;
29240                                                }
29241                                        }
29242                                }
29243                        } else {
29244                                if (it.isOutputDouble()) {
29245                                        while (it.hasNext()) {
29246                                                for (int j = 0; j < is; j++) {
29247                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29248                                                        long ox;
29249                                                        ox = toLong(Math.cbrt(ix));
29250                                                        oai64data[it.oIndex + j] = ox;
29251                                                }
29252                                        }
29253                                } else {
29254                                        while (it.hasNext()) {
29255                                                for (int j = 0; j < is; j++) {
29256                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29257                                                        long ox;
29258                                                        ox = toLong(Math.cbrt(ix));
29259                                                        oai64data[it.oIndex + j] = ox;
29260                                                }
29261                                        }
29262                                }
29263                        }
29264                        break;
29265                case Dataset.ARRAYINT32:
29266                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
29267                        if (is == 1) {
29268                                if (it.isOutputDouble()) {
29269                                        while (it.hasNext()) {
29270                                                final double ix = it.aDouble;
29271                                                int ox;
29272                                                ox = (int) toLong(Math.cbrt(ix));
29273                                                oai32data[it.oIndex] = ox;
29274                                        }
29275                                } else {
29276                                        while (it.hasNext()) {
29277                                                final long ix = it.aLong;
29278                                                int ox;
29279                                                ox = (int) toLong(Math.cbrt(ix));
29280                                                oai32data[it.oIndex] = ox;
29281                                        }
29282                                }
29283                        } else if (as == 1) {
29284                                if (it.isOutputDouble()) {
29285                                        while (it.hasNext()) {
29286                                                final double ix = it.aDouble;
29287                                                int ox;
29288                                                ox = (int) toLong(Math.cbrt(ix));
29289                                                for (int j = 0; j < is; j++) {
29290                                                        oai32data[it.oIndex + j] = ox;
29291                                                }
29292                                        }
29293                                } else {
29294                                        while (it.hasNext()) {
29295                                                final long ix = it.aLong;
29296                                                int ox;
29297                                                ox = (int) toLong(Math.cbrt(ix));
29298                                                for (int j = 0; j < is; j++) {
29299                                                        oai32data[it.oIndex + j] = ox;
29300                                                }
29301                                        }
29302                                }
29303                        } else {
29304                                if (it.isOutputDouble()) {
29305                                        while (it.hasNext()) {
29306                                                for (int j = 0; j < is; j++) {
29307                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29308                                                        int ox;
29309                                                        ox = (int) toLong(Math.cbrt(ix));
29310                                                        oai32data[it.oIndex + j] = ox;
29311                                                }
29312                                        }
29313                                } else {
29314                                        while (it.hasNext()) {
29315                                                for (int j = 0; j < is; j++) {
29316                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29317                                                        int ox;
29318                                                        ox = (int) toLong(Math.cbrt(ix));
29319                                                        oai32data[it.oIndex + j] = ox;
29320                                                }
29321                                        }
29322                                }
29323                        }
29324                        break;
29325                case Dataset.FLOAT32:
29326                        final float[] of32data = ((FloatDataset) result).getData();
29327                        if (it.isOutputDouble()) {
29328                                while (it.hasNext()) {
29329                                        final double ix = it.aDouble;
29330                                        float ox;
29331                                        ox = (float) (Math.cbrt(ix));
29332                                        of32data[it.oIndex] = ox;
29333                                }
29334                        } else {
29335                                while (it.hasNext()) {
29336                                        final long ix = it.aLong;
29337                                        float ox;
29338                                        ox = (float) (Math.cbrt(ix));
29339                                        of32data[it.oIndex] = ox;
29340                                }
29341                        }
29342                        break;
29343                case Dataset.FLOAT64:
29344                        final double[] of64data = ((DoubleDataset) result).getData();
29345                        if (it.isOutputDouble()) {
29346                                while (it.hasNext()) {
29347                                        final double ix = it.aDouble;
29348                                        double ox;
29349                                        ox = (Math.cbrt(ix));
29350                                        of64data[it.oIndex] = ox;
29351                                }
29352                        } else {
29353                                while (it.hasNext()) {
29354                                        final long ix = it.aLong;
29355                                        double ox;
29356                                        ox = (Math.cbrt(ix));
29357                                        of64data[it.oIndex] = ox;
29358                                }
29359                        }
29360                        break;
29361                case Dataset.ARRAYFLOAT32:
29362                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
29363                        if (is == 1) {
29364                                if (it.isOutputDouble()) {
29365                                        while (it.hasNext()) {
29366                                                final double ix = it.aDouble;
29367                                                float ox;
29368                                                ox = (float) (Math.cbrt(ix));
29369                                                oaf32data[it.oIndex] = ox;
29370                                        }
29371                                } else {
29372                                        while (it.hasNext()) {
29373                                                final long ix = it.aLong;
29374                                                float ox;
29375                                                ox = (float) (Math.cbrt(ix));
29376                                                oaf32data[it.oIndex] = ox;
29377                                        }
29378                                }
29379                        } else if (as == 1) {
29380                                if (it.isOutputDouble()) {
29381                                        while (it.hasNext()) {
29382                                                final double ix = it.aDouble;
29383                                                float ox;
29384                                                ox = (float) (Math.cbrt(ix));
29385                                                for (int j = 0; j < is; j++) {
29386                                                        oaf32data[it.oIndex + j] = ox;
29387                                                }
29388                                        }
29389                                } else {
29390                                        while (it.hasNext()) {
29391                                                final long ix = it.aLong;
29392                                                float ox;
29393                                                ox = (float) (Math.cbrt(ix));
29394                                                for (int j = 0; j < is; j++) {
29395                                                        oaf32data[it.oIndex + j] = ox;
29396                                                }
29397                                        }
29398                                }
29399                        } else {
29400                                if (it.isOutputDouble()) {
29401                                        while (it.hasNext()) {
29402                                                for (int j = 0; j < is; j++) {
29403                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29404                                                        float ox;
29405                                                        ox = (float) (Math.cbrt(ix));
29406                                                        oaf32data[it.oIndex + j] = ox;
29407                                                }
29408                                        }
29409                                } else {
29410                                        while (it.hasNext()) {
29411                                                for (int j = 0; j < is; j++) {
29412                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29413                                                        float ox;
29414                                                        ox = (float) (Math.cbrt(ix));
29415                                                        oaf32data[it.oIndex + j] = ox;
29416                                                }
29417                                        }
29418                                }
29419                        }
29420                        break;
29421                case Dataset.ARRAYFLOAT64:
29422                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
29423                        if (is == 1) {
29424                                if (it.isOutputDouble()) {
29425                                        while (it.hasNext()) {
29426                                                final double ix = it.aDouble;
29427                                                double ox;
29428                                                ox = (Math.cbrt(ix));
29429                                                oaf64data[it.oIndex] = ox;
29430                                        }
29431                                } else {
29432                                        while (it.hasNext()) {
29433                                                final long ix = it.aLong;
29434                                                double ox;
29435                                                ox = (Math.cbrt(ix));
29436                                                oaf64data[it.oIndex] = ox;
29437                                        }
29438                                }
29439                        } else if (as == 1) {
29440                                if (it.isOutputDouble()) {
29441                                        while (it.hasNext()) {
29442                                                final double ix = it.aDouble;
29443                                                double ox;
29444                                                ox = (Math.cbrt(ix));
29445                                                for (int j = 0; j < is; j++) {
29446                                                        oaf64data[it.oIndex + j] = ox;
29447                                                }
29448                                        }
29449                                } else {
29450                                        while (it.hasNext()) {
29451                                                final long ix = it.aLong;
29452                                                double ox;
29453                                                ox = (Math.cbrt(ix));
29454                                                for (int j = 0; j < is; j++) {
29455                                                        oaf64data[it.oIndex + j] = ox;
29456                                                }
29457                                        }
29458                                }
29459                        } else {
29460                                if (it.isOutputDouble()) {
29461                                        while (it.hasNext()) {
29462                                                for (int j = 0; j < is; j++) {
29463                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29464                                                        double ox;
29465                                                        ox = (Math.cbrt(ix));
29466                                                        oaf64data[it.oIndex + j] = ox;
29467                                                }
29468                                        }
29469                                } else {
29470                                        while (it.hasNext()) {
29471                                                for (int j = 0; j < is; j++) {
29472                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29473                                                        double ox;
29474                                                        ox = (Math.cbrt(ix));
29475                                                        oaf64data[it.oIndex + j] = ox;
29476                                                }
29477                                        }
29478                                }
29479                        }
29480                        break;
29481                case Dataset.COMPLEX64:
29482                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
29483                        if (!da.isComplex()) {
29484                                if (it.isOutputDouble()) {
29485                                        final double iy = 0;
29486                                        while (it.hasNext()) {
29487                                                final double ix = it.aDouble;
29488                                                Complex tz;
29489                                                float ox;
29490                                                float oy;
29491                                                tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
29492                                                ox = (float) (tz.getReal());
29493                                                oy = (float) (tz.getImaginary());
29494                                                oc64data[it.oIndex] = ox;
29495                                                oc64data[it.oIndex + 1] = oy;
29496                                        }
29497                                } else {
29498                                        final long iy = 0;
29499                                        while (it.hasNext()) {
29500                                                final long ix = it.aLong;
29501                                                Complex tz;
29502                                                float ox;
29503                                                float oy;
29504                                                tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
29505                                                ox = (float) toLong(tz.getReal());
29506                                                oy = (float) toLong(tz.getImaginary());
29507                                                oc64data[it.oIndex] = ox;
29508                                                oc64data[it.oIndex + 1] = oy;
29509                                        }
29510                                }
29511                        } else {
29512                                while (it.hasNext()) {
29513                                        final double ix = it.aDouble;
29514                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
29515                                        Complex tz;
29516                                        float ox;
29517                                        float oy;
29518                                        tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
29519                                        ox = (float) (tz.getReal());
29520                                        oy = (float) (tz.getImaginary());
29521                                        oc64data[it.oIndex] = ox;
29522                                        oc64data[it.oIndex + 1] = oy;
29523                                }
29524                        }
29525                        break;
29526                case Dataset.COMPLEX128:
29527                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
29528                        if (!da.isComplex()) {
29529                                if (it.isOutputDouble()) {
29530                                        final double iy = 0;
29531                                        while (it.hasNext()) {
29532                                                final double ix = it.aDouble;
29533                                                Complex tz;
29534                                                double ox;
29535                                                double oy;
29536                                                tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
29537                                                ox = (tz.getReal());
29538                                                oy = (tz.getImaginary());
29539                                                oc128data[it.oIndex] = ox;
29540                                                oc128data[it.oIndex + 1] = oy;
29541                                        }
29542                                } else {
29543                                        final long iy = 0;
29544                                        while (it.hasNext()) {
29545                                                final long ix = it.aLong;
29546                                                Complex tz;
29547                                                double ox;
29548                                                double oy;
29549                                                tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
29550                                                ox = (tz.getReal());
29551                                                oy = (tz.getImaginary());
29552                                                oc128data[it.oIndex] = ox;
29553                                                oc128data[it.oIndex + 1] = oy;
29554                                        }
29555                                }
29556                        } else {
29557                                while (it.hasNext()) {
29558                                        final double ix = it.aDouble;
29559                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
29560                                        Complex tz;
29561                                        double ox;
29562                                        double oy;
29563                                        tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
29564                                        ox = (tz.getReal());
29565                                        oy = (tz.getImaginary());
29566                                        oc128data[it.oIndex] = ox;
29567                                        oc128data[it.oIndex + 1] = oy;
29568                                }
29569                        }
29570                        break;
29571                default:
29572                        throw new IllegalArgumentException("cbrt supports integer, compound integer, real, compound real, complex datasets only");
29573                }
29574
29575                addFunctionName(result, "cbrt");
29576                return result;
29577        }
29578
29579        /**
29580         * square - square each element
29581         * @param a
29582         * @return dataset
29583         */
29584        public static Dataset square(final Object a) {
29585                return square(a, null);
29586        }
29587
29588        /**
29589         * square - square each element
29590         * @param a
29591         * @param o output can be null - in which case, a new dataset is created
29592         * @return dataset
29593         */
29594        public static Dataset square(final Object a, final Dataset o) {
29595                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
29596                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
29597                final Dataset result = it.getOutput();
29598                if (!result.isComplex()) {
29599                        if (da.isComplex()) {
29600                                da = da.getRealView();
29601                                it = new SingleInputBroadcastIterator(da, result, true);
29602                        }
29603                }
29604                final int is = result.getElementsPerItem();
29605                final int as = da.getElementsPerItem();
29606                final int dt = result.getDType();
29607
29608                switch(dt) {
29609                case Dataset.INT8:
29610                        final byte[] oi8data = ((ByteDataset) result).getData();
29611                        if (it.isOutputDouble()) {
29612                                while (it.hasNext()) {
29613                                        final double ix = it.aDouble;
29614                                        byte ox;
29615                                        ox = (byte) toLong(ix*ix);
29616                                        oi8data[it.oIndex] = ox;
29617                                }
29618                        } else {
29619                                while (it.hasNext()) {
29620                                        final long ix = it.aLong;
29621                                        byte ox;
29622                                        ox = (byte) toLong(ix*ix);
29623                                        oi8data[it.oIndex] = ox;
29624                                }
29625                        }
29626                        break;
29627                case Dataset.INT16:
29628                        final short[] oi16data = ((ShortDataset) result).getData();
29629                        if (it.isOutputDouble()) {
29630                                while (it.hasNext()) {
29631                                        final double ix = it.aDouble;
29632                                        short ox;
29633                                        ox = (short) toLong(ix*ix);
29634                                        oi16data[it.oIndex] = ox;
29635                                }
29636                        } else {
29637                                while (it.hasNext()) {
29638                                        final long ix = it.aLong;
29639                                        short ox;
29640                                        ox = (short) toLong(ix*ix);
29641                                        oi16data[it.oIndex] = ox;
29642                                }
29643                        }
29644                        break;
29645                case Dataset.INT64:
29646                        final long[] oi64data = ((LongDataset) result).getData();
29647                        if (it.isOutputDouble()) {
29648                                while (it.hasNext()) {
29649                                        final double ix = it.aDouble;
29650                                        long ox;
29651                                        ox = toLong(ix*ix);
29652                                        oi64data[it.oIndex] = ox;
29653                                }
29654                        } else {
29655                                while (it.hasNext()) {
29656                                        final long ix = it.aLong;
29657                                        long ox;
29658                                        ox = toLong(ix*ix);
29659                                        oi64data[it.oIndex] = ox;
29660                                }
29661                        }
29662                        break;
29663                case Dataset.INT32:
29664                        final int[] oi32data = ((IntegerDataset) result).getData();
29665                        if (it.isOutputDouble()) {
29666                                while (it.hasNext()) {
29667                                        final double ix = it.aDouble;
29668                                        int ox;
29669                                        ox = (int) toLong(ix*ix);
29670                                        oi32data[it.oIndex] = ox;
29671                                }
29672                        } else {
29673                                while (it.hasNext()) {
29674                                        final long ix = it.aLong;
29675                                        int ox;
29676                                        ox = (int) toLong(ix*ix);
29677                                        oi32data[it.oIndex] = ox;
29678                                }
29679                        }
29680                        break;
29681                case Dataset.ARRAYINT8:
29682                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
29683                        if (is == 1) {
29684                                if (it.isOutputDouble()) {
29685                                        while (it.hasNext()) {
29686                                                final double ix = it.aDouble;
29687                                                byte ox;
29688                                                ox = (byte) toLong(ix*ix);
29689                                                oai8data[it.oIndex] = ox;
29690                                        }
29691                                } else {
29692                                        while (it.hasNext()) {
29693                                                final long ix = it.aLong;
29694                                                byte ox;
29695                                                ox = (byte) toLong(ix*ix);
29696                                                oai8data[it.oIndex] = ox;
29697                                        }
29698                                }
29699                        } else if (as == 1) {
29700                                if (it.isOutputDouble()) {
29701                                        while (it.hasNext()) {
29702                                                final double ix = it.aDouble;
29703                                                byte ox;
29704                                                ox = (byte) toLong(ix*ix);
29705                                                for (int j = 0; j < is; j++) {
29706                                                        oai8data[it.oIndex + j] = ox;
29707                                                }
29708                                        }
29709                                } else {
29710                                        while (it.hasNext()) {
29711                                                final long ix = it.aLong;
29712                                                byte ox;
29713                                                ox = (byte) toLong(ix*ix);
29714                                                for (int j = 0; j < is; j++) {
29715                                                        oai8data[it.oIndex + j] = ox;
29716                                                }
29717                                        }
29718                                }
29719                        } else {
29720                                if (it.isOutputDouble()) {
29721                                        while (it.hasNext()) {
29722                                                for (int j = 0; j < is; j++) {
29723                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29724                                                        byte ox;
29725                                                        ox = (byte) toLong(ix*ix);
29726                                                        oai8data[it.oIndex + j] = ox;
29727                                                }
29728                                        }
29729                                } else {
29730                                        while (it.hasNext()) {
29731                                                for (int j = 0; j < is; j++) {
29732                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29733                                                        byte ox;
29734                                                        ox = (byte) toLong(ix*ix);
29735                                                        oai8data[it.oIndex + j] = ox;
29736                                                }
29737                                        }
29738                                }
29739                        }
29740                        break;
29741                case Dataset.ARRAYINT16:
29742                        final short[] oai16data = ((CompoundShortDataset) result).getData();
29743                        if (is == 1) {
29744                                if (it.isOutputDouble()) {
29745                                        while (it.hasNext()) {
29746                                                final double ix = it.aDouble;
29747                                                short ox;
29748                                                ox = (short) toLong(ix*ix);
29749                                                oai16data[it.oIndex] = ox;
29750                                        }
29751                                } else {
29752                                        while (it.hasNext()) {
29753                                                final long ix = it.aLong;
29754                                                short ox;
29755                                                ox = (short) toLong(ix*ix);
29756                                                oai16data[it.oIndex] = ox;
29757                                        }
29758                                }
29759                        } else if (as == 1) {
29760                                if (it.isOutputDouble()) {
29761                                        while (it.hasNext()) {
29762                                                final double ix = it.aDouble;
29763                                                short ox;
29764                                                ox = (short) toLong(ix*ix);
29765                                                for (int j = 0; j < is; j++) {
29766                                                        oai16data[it.oIndex + j] = ox;
29767                                                }
29768                                        }
29769                                } else {
29770                                        while (it.hasNext()) {
29771                                                final long ix = it.aLong;
29772                                                short ox;
29773                                                ox = (short) toLong(ix*ix);
29774                                                for (int j = 0; j < is; j++) {
29775                                                        oai16data[it.oIndex + j] = ox;
29776                                                }
29777                                        }
29778                                }
29779                        } else {
29780                                if (it.isOutputDouble()) {
29781                                        while (it.hasNext()) {
29782                                                for (int j = 0; j < is; j++) {
29783                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29784                                                        short ox;
29785                                                        ox = (short) toLong(ix*ix);
29786                                                        oai16data[it.oIndex + j] = ox;
29787                                                }
29788                                        }
29789                                } else {
29790                                        while (it.hasNext()) {
29791                                                for (int j = 0; j < is; j++) {
29792                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29793                                                        short ox;
29794                                                        ox = (short) toLong(ix*ix);
29795                                                        oai16data[it.oIndex + j] = ox;
29796                                                }
29797                                        }
29798                                }
29799                        }
29800                        break;
29801                case Dataset.ARRAYINT64:
29802                        final long[] oai64data = ((CompoundLongDataset) result).getData();
29803                        if (is == 1) {
29804                                if (it.isOutputDouble()) {
29805                                        while (it.hasNext()) {
29806                                                final double ix = it.aDouble;
29807                                                long ox;
29808                                                ox = toLong(ix*ix);
29809                                                oai64data[it.oIndex] = ox;
29810                                        }
29811                                } else {
29812                                        while (it.hasNext()) {
29813                                                final long ix = it.aLong;
29814                                                long ox;
29815                                                ox = toLong(ix*ix);
29816                                                oai64data[it.oIndex] = ox;
29817                                        }
29818                                }
29819                        } else if (as == 1) {
29820                                if (it.isOutputDouble()) {
29821                                        while (it.hasNext()) {
29822                                                final double ix = it.aDouble;
29823                                                long ox;
29824                                                ox = toLong(ix*ix);
29825                                                for (int j = 0; j < is; j++) {
29826                                                        oai64data[it.oIndex + j] = ox;
29827                                                }
29828                                        }
29829                                } else {
29830                                        while (it.hasNext()) {
29831                                                final long ix = it.aLong;
29832                                                long ox;
29833                                                ox = toLong(ix*ix);
29834                                                for (int j = 0; j < is; j++) {
29835                                                        oai64data[it.oIndex + j] = ox;
29836                                                }
29837                                        }
29838                                }
29839                        } else {
29840                                if (it.isOutputDouble()) {
29841                                        while (it.hasNext()) {
29842                                                for (int j = 0; j < is; j++) {
29843                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29844                                                        long ox;
29845                                                        ox = toLong(ix*ix);
29846                                                        oai64data[it.oIndex + j] = ox;
29847                                                }
29848                                        }
29849                                } else {
29850                                        while (it.hasNext()) {
29851                                                for (int j = 0; j < is; j++) {
29852                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29853                                                        long ox;
29854                                                        ox = toLong(ix*ix);
29855                                                        oai64data[it.oIndex + j] = ox;
29856                                                }
29857                                        }
29858                                }
29859                        }
29860                        break;
29861                case Dataset.ARRAYINT32:
29862                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
29863                        if (is == 1) {
29864                                if (it.isOutputDouble()) {
29865                                        while (it.hasNext()) {
29866                                                final double ix = it.aDouble;
29867                                                int ox;
29868                                                ox = (int) toLong(ix*ix);
29869                                                oai32data[it.oIndex] = ox;
29870                                        }
29871                                } else {
29872                                        while (it.hasNext()) {
29873                                                final long ix = it.aLong;
29874                                                int ox;
29875                                                ox = (int) toLong(ix*ix);
29876                                                oai32data[it.oIndex] = ox;
29877                                        }
29878                                }
29879                        } else if (as == 1) {
29880                                if (it.isOutputDouble()) {
29881                                        while (it.hasNext()) {
29882                                                final double ix = it.aDouble;
29883                                                int ox;
29884                                                ox = (int) toLong(ix*ix);
29885                                                for (int j = 0; j < is; j++) {
29886                                                        oai32data[it.oIndex + j] = ox;
29887                                                }
29888                                        }
29889                                } else {
29890                                        while (it.hasNext()) {
29891                                                final long ix = it.aLong;
29892                                                int ox;
29893                                                ox = (int) toLong(ix*ix);
29894                                                for (int j = 0; j < is; j++) {
29895                                                        oai32data[it.oIndex + j] = ox;
29896                                                }
29897                                        }
29898                                }
29899                        } else {
29900                                if (it.isOutputDouble()) {
29901                                        while (it.hasNext()) {
29902                                                for (int j = 0; j < is; j++) {
29903                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29904                                                        int ox;
29905                                                        ox = (int) toLong(ix*ix);
29906                                                        oai32data[it.oIndex + j] = ox;
29907                                                }
29908                                        }
29909                                } else {
29910                                        while (it.hasNext()) {
29911                                                for (int j = 0; j < is; j++) {
29912                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29913                                                        int ox;
29914                                                        ox = (int) toLong(ix*ix);
29915                                                        oai32data[it.oIndex + j] = ox;
29916                                                }
29917                                        }
29918                                }
29919                        }
29920                        break;
29921                case Dataset.FLOAT32:
29922                        final float[] of32data = ((FloatDataset) result).getData();
29923                        if (it.isOutputDouble()) {
29924                                while (it.hasNext()) {
29925                                        final double ix = it.aDouble;
29926                                        float ox;
29927                                        ox = (float) (ix*ix);
29928                                        of32data[it.oIndex] = ox;
29929                                }
29930                        } else {
29931                                while (it.hasNext()) {
29932                                        final long ix = it.aLong;
29933                                        float ox;
29934                                        ox = (ix*ix);
29935                                        of32data[it.oIndex] = ox;
29936                                }
29937                        }
29938                        break;
29939                case Dataset.FLOAT64:
29940                        final double[] of64data = ((DoubleDataset) result).getData();
29941                        if (it.isOutputDouble()) {
29942                                while (it.hasNext()) {
29943                                        final double ix = it.aDouble;
29944                                        double ox;
29945                                        ox = (ix*ix);
29946                                        of64data[it.oIndex] = ox;
29947                                }
29948                        } else {
29949                                while (it.hasNext()) {
29950                                        final long ix = it.aLong;
29951                                        double ox;
29952                                        ox = (ix*ix);
29953                                        of64data[it.oIndex] = ox;
29954                                }
29955                        }
29956                        break;
29957                case Dataset.ARRAYFLOAT32:
29958                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
29959                        if (is == 1) {
29960                                if (it.isOutputDouble()) {
29961                                        while (it.hasNext()) {
29962                                                final double ix = it.aDouble;
29963                                                float ox;
29964                                                ox = (float) (ix*ix);
29965                                                oaf32data[it.oIndex] = ox;
29966                                        }
29967                                } else {
29968                                        while (it.hasNext()) {
29969                                                final long ix = it.aLong;
29970                                                float ox;
29971                                                ox = (ix*ix);
29972                                                oaf32data[it.oIndex] = ox;
29973                                        }
29974                                }
29975                        } else if (as == 1) {
29976                                if (it.isOutputDouble()) {
29977                                        while (it.hasNext()) {
29978                                                final double ix = it.aDouble;
29979                                                float ox;
29980                                                ox = (float) (ix*ix);
29981                                                for (int j = 0; j < is; j++) {
29982                                                        oaf32data[it.oIndex + j] = ox;
29983                                                }
29984                                        }
29985                                } else {
29986                                        while (it.hasNext()) {
29987                                                final long ix = it.aLong;
29988                                                float ox;
29989                                                ox = (ix*ix);
29990                                                for (int j = 0; j < is; j++) {
29991                                                        oaf32data[it.oIndex + j] = ox;
29992                                                }
29993                                        }
29994                                }
29995                        } else {
29996                                if (it.isOutputDouble()) {
29997                                        while (it.hasNext()) {
29998                                                for (int j = 0; j < is; j++) {
29999                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30000                                                        float ox;
30001                                                        ox = (float) (ix*ix);
30002                                                        oaf32data[it.oIndex + j] = ox;
30003                                                }
30004                                        }
30005                                } else {
30006                                        while (it.hasNext()) {
30007                                                for (int j = 0; j < is; j++) {
30008                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30009                                                        float ox;
30010                                                        ox = (ix*ix);
30011                                                        oaf32data[it.oIndex + j] = ox;
30012                                                }
30013                                        }
30014                                }
30015                        }
30016                        break;
30017                case Dataset.ARRAYFLOAT64:
30018                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
30019                        if (is == 1) {
30020                                if (it.isOutputDouble()) {
30021                                        while (it.hasNext()) {
30022                                                final double ix = it.aDouble;
30023                                                double ox;
30024                                                ox = (ix*ix);
30025                                                oaf64data[it.oIndex] = ox;
30026                                        }
30027                                } else {
30028                                        while (it.hasNext()) {
30029                                                final long ix = it.aLong;
30030                                                double ox;
30031                                                ox = (ix*ix);
30032                                                oaf64data[it.oIndex] = ox;
30033                                        }
30034                                }
30035                        } else if (as == 1) {
30036                                if (it.isOutputDouble()) {
30037                                        while (it.hasNext()) {
30038                                                final double ix = it.aDouble;
30039                                                double ox;
30040                                                ox = (ix*ix);
30041                                                for (int j = 0; j < is; j++) {
30042                                                        oaf64data[it.oIndex + j] = ox;
30043                                                }
30044                                        }
30045                                } else {
30046                                        while (it.hasNext()) {
30047                                                final long ix = it.aLong;
30048                                                double ox;
30049                                                ox = (ix*ix);
30050                                                for (int j = 0; j < is; j++) {
30051                                                        oaf64data[it.oIndex + j] = ox;
30052                                                }
30053                                        }
30054                                }
30055                        } else {
30056                                if (it.isOutputDouble()) {
30057                                        while (it.hasNext()) {
30058                                                for (int j = 0; j < is; j++) {
30059                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30060                                                        double ox;
30061                                                        ox = (ix*ix);
30062                                                        oaf64data[it.oIndex + j] = ox;
30063                                                }
30064                                        }
30065                                } else {
30066                                        while (it.hasNext()) {
30067                                                for (int j = 0; j < is; j++) {
30068                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30069                                                        double ox;
30070                                                        ox = (ix*ix);
30071                                                        oaf64data[it.oIndex + j] = ox;
30072                                                }
30073                                        }
30074                                }
30075                        }
30076                        break;
30077                case Dataset.COMPLEX64:
30078                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
30079                        if (!da.isComplex()) {
30080                                if (it.isOutputDouble()) {
30081                                        final double iy = 0;
30082                                        while (it.hasNext()) {
30083                                                final double ix = it.aDouble;
30084                                                float ox;
30085                                                float oy;
30086                                                ox = (float) (ix*ix - iy*iy);
30087                                                oy = (float) (2.*ix*iy);
30088                                                oc64data[it.oIndex] = ox;
30089                                                oc64data[it.oIndex + 1] = oy;
30090                                        }
30091                                } else {
30092                                        final long iy = 0;
30093                                        while (it.hasNext()) {
30094                                                final long ix = it.aLong;
30095                                                float ox;
30096                                                float oy;
30097                                                ox = (float) toLong(ix*ix - iy*iy);
30098                                                oy = (float) toLong(2.*ix*iy);
30099                                                oc64data[it.oIndex] = ox;
30100                                                oc64data[it.oIndex + 1] = oy;
30101                                        }
30102                                }
30103                        } else {
30104                                while (it.hasNext()) {
30105                                        final double ix = it.aDouble;
30106                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
30107                                        float ox;
30108                                        float oy;
30109                                        ox = (float) (ix*ix - iy*iy);
30110                                        oy = (float) (2.*ix*iy);
30111                                        oc64data[it.oIndex] = ox;
30112                                        oc64data[it.oIndex + 1] = oy;
30113                                }
30114                        }
30115                        break;
30116                case Dataset.COMPLEX128:
30117                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
30118                        if (!da.isComplex()) {
30119                                if (it.isOutputDouble()) {
30120                                        final double iy = 0;
30121                                        while (it.hasNext()) {
30122                                                final double ix = it.aDouble;
30123                                                double ox;
30124                                                double oy;
30125                                                ox = (ix*ix - iy*iy);
30126                                                oy = (2.*ix*iy);
30127                                                oc128data[it.oIndex] = ox;
30128                                                oc128data[it.oIndex + 1] = oy;
30129                                        }
30130                                } else {
30131                                        final long iy = 0;
30132                                        while (it.hasNext()) {
30133                                                final long ix = it.aLong;
30134                                                double ox;
30135                                                double oy;
30136                                                ox = (ix*ix - iy*iy);
30137                                                oy = (2.*ix*iy);
30138                                                oc128data[it.oIndex] = ox;
30139                                                oc128data[it.oIndex + 1] = oy;
30140                                        }
30141                                }
30142                        } else {
30143                                while (it.hasNext()) {
30144                                        final double ix = it.aDouble;
30145                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
30146                                        double ox;
30147                                        double oy;
30148                                        ox = (ix*ix - iy*iy);
30149                                        oy = (2.*ix*iy);
30150                                        oc128data[it.oIndex] = ox;
30151                                        oc128data[it.oIndex + 1] = oy;
30152                                }
30153                        }
30154                        break;
30155                default:
30156                        throw new IllegalArgumentException("square supports integer, compound integer, real, compound real, complex datasets only");
30157                }
30158
30159                addFunctionName(result, "square");
30160                return result;
30161        }
30162
30163        /**
30164         * floor - evaluate the floor function on each element of the dataset
30165         * @param a
30166         * @return dataset
30167         */
30168        public static Dataset floor(final Object a) {
30169                return floor(a, null);
30170        }
30171
30172        /**
30173         * floor - evaluate the floor function on each element of the dataset
30174         * @param a
30175         * @param o output can be null - in which case, a new dataset is created
30176         * @return dataset
30177         */
30178        public static Dataset floor(final Object a, final Dataset o) {
30179                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
30180                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
30181                final Dataset result = it.getOutput();
30182                if (!result.isComplex()) {
30183                        if (da.isComplex()) {
30184                                da = da.getRealView();
30185                                it = new SingleInputBroadcastIterator(da, result, true);
30186                        }
30187                }
30188                final int is = result.getElementsPerItem();
30189                final int as = da.getElementsPerItem();
30190                final int dt = result.getDType();
30191
30192                switch(dt) {
30193                case Dataset.INT8:
30194                        final byte[] oi8data = ((ByteDataset) result).getData();
30195                        if (it.isOutputDouble()) {
30196                                while (it.hasNext()) {
30197                                        final double ix = it.aDouble;
30198                                        byte ox;
30199                                        ox = (byte) toLong(ix);
30200                                        oi8data[it.oIndex] = ox;
30201                                }
30202                        } else {
30203                                while (it.hasNext()) {
30204                                        final long ix = it.aLong;
30205                                        byte ox;
30206                                        ox = (byte) toLong(ix);
30207                                        oi8data[it.oIndex] = ox;
30208                                }
30209                        }
30210                        break;
30211                case Dataset.INT16:
30212                        final short[] oi16data = ((ShortDataset) result).getData();
30213                        if (it.isOutputDouble()) {
30214                                while (it.hasNext()) {
30215                                        final double ix = it.aDouble;
30216                                        short ox;
30217                                        ox = (short) toLong(ix);
30218                                        oi16data[it.oIndex] = ox;
30219                                }
30220                        } else {
30221                                while (it.hasNext()) {
30222                                        final long ix = it.aLong;
30223                                        short ox;
30224                                        ox = (short) toLong(ix);
30225                                        oi16data[it.oIndex] = ox;
30226                                }
30227                        }
30228                        break;
30229                case Dataset.INT64:
30230                        final long[] oi64data = ((LongDataset) result).getData();
30231                        if (it.isOutputDouble()) {
30232                                while (it.hasNext()) {
30233                                        final double ix = it.aDouble;
30234                                        long ox;
30235                                        ox = toLong(ix);
30236                                        oi64data[it.oIndex] = ox;
30237                                }
30238                        } else {
30239                                while (it.hasNext()) {
30240                                        final long ix = it.aLong;
30241                                        long ox;
30242                                        ox = toLong(ix);
30243                                        oi64data[it.oIndex] = ox;
30244                                }
30245                        }
30246                        break;
30247                case Dataset.INT32:
30248                        final int[] oi32data = ((IntegerDataset) result).getData();
30249                        if (it.isOutputDouble()) {
30250                                while (it.hasNext()) {
30251                                        final double ix = it.aDouble;
30252                                        int ox;
30253                                        ox = (int) toLong(ix);
30254                                        oi32data[it.oIndex] = ox;
30255                                }
30256                        } else {
30257                                while (it.hasNext()) {
30258                                        final long ix = it.aLong;
30259                                        int ox;
30260                                        ox = (int) toLong(ix);
30261                                        oi32data[it.oIndex] = ox;
30262                                }
30263                        }
30264                        break;
30265                case Dataset.ARRAYINT8:
30266                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
30267                        if (is == 1) {
30268                                if (it.isOutputDouble()) {
30269                                        while (it.hasNext()) {
30270                                                final double ix = it.aDouble;
30271                                                byte ox;
30272                                                ox = (byte) toLong(ix);
30273                                                oai8data[it.oIndex] = ox;
30274                                        }
30275                                } else {
30276                                        while (it.hasNext()) {
30277                                                final long ix = it.aLong;
30278                                                byte ox;
30279                                                ox = (byte) toLong(ix);
30280                                                oai8data[it.oIndex] = ox;
30281                                        }
30282                                }
30283                        } else if (as == 1) {
30284                                if (it.isOutputDouble()) {
30285                                        while (it.hasNext()) {
30286                                                final double ix = it.aDouble;
30287                                                byte ox;
30288                                                ox = (byte) toLong(ix);
30289                                                for (int j = 0; j < is; j++) {
30290                                                        oai8data[it.oIndex + j] = ox;
30291                                                }
30292                                        }
30293                                } else {
30294                                        while (it.hasNext()) {
30295                                                final long ix = it.aLong;
30296                                                byte ox;
30297                                                ox = (byte) toLong(ix);
30298                                                for (int j = 0; j < is; j++) {
30299                                                        oai8data[it.oIndex + j] = ox;
30300                                                }
30301                                        }
30302                                }
30303                        } else {
30304                                if (it.isOutputDouble()) {
30305                                        while (it.hasNext()) {
30306                                                for (int j = 0; j < is; j++) {
30307                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30308                                                        byte ox;
30309                                                        ox = (byte) toLong(ix);
30310                                                        oai8data[it.oIndex + j] = ox;
30311                                                }
30312                                        }
30313                                } else {
30314                                        while (it.hasNext()) {
30315                                                for (int j = 0; j < is; j++) {
30316                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30317                                                        byte ox;
30318                                                        ox = (byte) toLong(ix);
30319                                                        oai8data[it.oIndex + j] = ox;
30320                                                }
30321                                        }
30322                                }
30323                        }
30324                        break;
30325                case Dataset.ARRAYINT16:
30326                        final short[] oai16data = ((CompoundShortDataset) result).getData();
30327                        if (is == 1) {
30328                                if (it.isOutputDouble()) {
30329                                        while (it.hasNext()) {
30330                                                final double ix = it.aDouble;
30331                                                short ox;
30332                                                ox = (short) toLong(ix);
30333                                                oai16data[it.oIndex] = ox;
30334                                        }
30335                                } else {
30336                                        while (it.hasNext()) {
30337                                                final long ix = it.aLong;
30338                                                short ox;
30339                                                ox = (short) toLong(ix);
30340                                                oai16data[it.oIndex] = ox;
30341                                        }
30342                                }
30343                        } else if (as == 1) {
30344                                if (it.isOutputDouble()) {
30345                                        while (it.hasNext()) {
30346                                                final double ix = it.aDouble;
30347                                                short ox;
30348                                                ox = (short) toLong(ix);
30349                                                for (int j = 0; j < is; j++) {
30350                                                        oai16data[it.oIndex + j] = ox;
30351                                                }
30352                                        }
30353                                } else {
30354                                        while (it.hasNext()) {
30355                                                final long ix = it.aLong;
30356                                                short ox;
30357                                                ox = (short) toLong(ix);
30358                                                for (int j = 0; j < is; j++) {
30359                                                        oai16data[it.oIndex + j] = ox;
30360                                                }
30361                                        }
30362                                }
30363                        } else {
30364                                if (it.isOutputDouble()) {
30365                                        while (it.hasNext()) {
30366                                                for (int j = 0; j < is; j++) {
30367                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30368                                                        short ox;
30369                                                        ox = (short) toLong(ix);
30370                                                        oai16data[it.oIndex + j] = ox;
30371                                                }
30372                                        }
30373                                } else {
30374                                        while (it.hasNext()) {
30375                                                for (int j = 0; j < is; j++) {
30376                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30377                                                        short ox;
30378                                                        ox = (short) toLong(ix);
30379                                                        oai16data[it.oIndex + j] = ox;
30380                                                }
30381                                        }
30382                                }
30383                        }
30384                        break;
30385                case Dataset.ARRAYINT64:
30386                        final long[] oai64data = ((CompoundLongDataset) result).getData();
30387                        if (is == 1) {
30388                                if (it.isOutputDouble()) {
30389                                        while (it.hasNext()) {
30390                                                final double ix = it.aDouble;
30391                                                long ox;
30392                                                ox = toLong(ix);
30393                                                oai64data[it.oIndex] = ox;
30394                                        }
30395                                } else {
30396                                        while (it.hasNext()) {
30397                                                final long ix = it.aLong;
30398                                                long ox;
30399                                                ox = toLong(ix);
30400                                                oai64data[it.oIndex] = ox;
30401                                        }
30402                                }
30403                        } else if (as == 1) {
30404                                if (it.isOutputDouble()) {
30405                                        while (it.hasNext()) {
30406                                                final double ix = it.aDouble;
30407                                                long ox;
30408                                                ox = toLong(ix);
30409                                                for (int j = 0; j < is; j++) {
30410                                                        oai64data[it.oIndex + j] = ox;
30411                                                }
30412                                        }
30413                                } else {
30414                                        while (it.hasNext()) {
30415                                                final long ix = it.aLong;
30416                                                long ox;
30417                                                ox = toLong(ix);
30418                                                for (int j = 0; j < is; j++) {
30419                                                        oai64data[it.oIndex + j] = ox;
30420                                                }
30421                                        }
30422                                }
30423                        } else {
30424                                if (it.isOutputDouble()) {
30425                                        while (it.hasNext()) {
30426                                                for (int j = 0; j < is; j++) {
30427                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30428                                                        long ox;
30429                                                        ox = toLong(ix);
30430                                                        oai64data[it.oIndex + j] = ox;
30431                                                }
30432                                        }
30433                                } else {
30434                                        while (it.hasNext()) {
30435                                                for (int j = 0; j < is; j++) {
30436                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30437                                                        long ox;
30438                                                        ox = toLong(ix);
30439                                                        oai64data[it.oIndex + j] = ox;
30440                                                }
30441                                        }
30442                                }
30443                        }
30444                        break;
30445                case Dataset.ARRAYINT32:
30446                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
30447                        if (is == 1) {
30448                                if (it.isOutputDouble()) {
30449                                        while (it.hasNext()) {
30450                                                final double ix = it.aDouble;
30451                                                int ox;
30452                                                ox = (int) toLong(ix);
30453                                                oai32data[it.oIndex] = ox;
30454                                        }
30455                                } else {
30456                                        while (it.hasNext()) {
30457                                                final long ix = it.aLong;
30458                                                int ox;
30459                                                ox = (int) toLong(ix);
30460                                                oai32data[it.oIndex] = ox;
30461                                        }
30462                                }
30463                        } else if (as == 1) {
30464                                if (it.isOutputDouble()) {
30465                                        while (it.hasNext()) {
30466                                                final double ix = it.aDouble;
30467                                                int ox;
30468                                                ox = (int) toLong(ix);
30469                                                for (int j = 0; j < is; j++) {
30470                                                        oai32data[it.oIndex + j] = ox;
30471                                                }
30472                                        }
30473                                } else {
30474                                        while (it.hasNext()) {
30475                                                final long ix = it.aLong;
30476                                                int ox;
30477                                                ox = (int) toLong(ix);
30478                                                for (int j = 0; j < is; j++) {
30479                                                        oai32data[it.oIndex + j] = ox;
30480                                                }
30481                                        }
30482                                }
30483                        } else {
30484                                if (it.isOutputDouble()) {
30485                                        while (it.hasNext()) {
30486                                                for (int j = 0; j < is; j++) {
30487                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30488                                                        int ox;
30489                                                        ox = (int) toLong(ix);
30490                                                        oai32data[it.oIndex + j] = ox;
30491                                                }
30492                                        }
30493                                } else {
30494                                        while (it.hasNext()) {
30495                                                for (int j = 0; j < is; j++) {
30496                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30497                                                        int ox;
30498                                                        ox = (int) toLong(ix);
30499                                                        oai32data[it.oIndex + j] = ox;
30500                                                }
30501                                        }
30502                                }
30503                        }
30504                        break;
30505                case Dataset.FLOAT32:
30506                        final float[] of32data = ((FloatDataset) result).getData();
30507                        if (it.isOutputDouble()) {
30508                                while (it.hasNext()) {
30509                                        final double ix = it.aDouble;
30510                                        float ox;
30511                                        ox = (float) (Math.floor(ix));
30512                                        of32data[it.oIndex] = ox;
30513                                }
30514                        } else {
30515                                while (it.hasNext()) {
30516                                        final long ix = it.aLong;
30517                                        float ox;
30518                                        ox = (float) (Math.floor(ix));
30519                                        of32data[it.oIndex] = ox;
30520                                }
30521                        }
30522                        break;
30523                case Dataset.FLOAT64:
30524                        final double[] of64data = ((DoubleDataset) result).getData();
30525                        if (it.isOutputDouble()) {
30526                                while (it.hasNext()) {
30527                                        final double ix = it.aDouble;
30528                                        double ox;
30529                                        ox = (Math.floor(ix));
30530                                        of64data[it.oIndex] = ox;
30531                                }
30532                        } else {
30533                                while (it.hasNext()) {
30534                                        final long ix = it.aLong;
30535                                        double ox;
30536                                        ox = (Math.floor(ix));
30537                                        of64data[it.oIndex] = ox;
30538                                }
30539                        }
30540                        break;
30541                case Dataset.ARRAYFLOAT32:
30542                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
30543                        if (is == 1) {
30544                                if (it.isOutputDouble()) {
30545                                        while (it.hasNext()) {
30546                                                final double ix = it.aDouble;
30547                                                float ox;
30548                                                ox = (float) (Math.floor(ix));
30549                                                oaf32data[it.oIndex] = ox;
30550                                        }
30551                                } else {
30552                                        while (it.hasNext()) {
30553                                                final long ix = it.aLong;
30554                                                float ox;
30555                                                ox = (float) (Math.floor(ix));
30556                                                oaf32data[it.oIndex] = ox;
30557                                        }
30558                                }
30559                        } else if (as == 1) {
30560                                if (it.isOutputDouble()) {
30561                                        while (it.hasNext()) {
30562                                                final double ix = it.aDouble;
30563                                                float ox;
30564                                                ox = (float) (Math.floor(ix));
30565                                                for (int j = 0; j < is; j++) {
30566                                                        oaf32data[it.oIndex + j] = ox;
30567                                                }
30568                                        }
30569                                } else {
30570                                        while (it.hasNext()) {
30571                                                final long ix = it.aLong;
30572                                                float ox;
30573                                                ox = (float) (Math.floor(ix));
30574                                                for (int j = 0; j < is; j++) {
30575                                                        oaf32data[it.oIndex + j] = ox;
30576                                                }
30577                                        }
30578                                }
30579                        } else {
30580                                if (it.isOutputDouble()) {
30581                                        while (it.hasNext()) {
30582                                                for (int j = 0; j < is; j++) {
30583                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30584                                                        float ox;
30585                                                        ox = (float) (Math.floor(ix));
30586                                                        oaf32data[it.oIndex + j] = ox;
30587                                                }
30588                                        }
30589                                } else {
30590                                        while (it.hasNext()) {
30591                                                for (int j = 0; j < is; j++) {
30592                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30593                                                        float ox;
30594                                                        ox = (float) (Math.floor(ix));
30595                                                        oaf32data[it.oIndex + j] = ox;
30596                                                }
30597                                        }
30598                                }
30599                        }
30600                        break;
30601                case Dataset.ARRAYFLOAT64:
30602                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
30603                        if (is == 1) {
30604                                if (it.isOutputDouble()) {
30605                                        while (it.hasNext()) {
30606                                                final double ix = it.aDouble;
30607                                                double ox;
30608                                                ox = (Math.floor(ix));
30609                                                oaf64data[it.oIndex] = ox;
30610                                        }
30611                                } else {
30612                                        while (it.hasNext()) {
30613                                                final long ix = it.aLong;
30614                                                double ox;
30615                                                ox = (Math.floor(ix));
30616                                                oaf64data[it.oIndex] = ox;
30617                                        }
30618                                }
30619                        } else if (as == 1) {
30620                                if (it.isOutputDouble()) {
30621                                        while (it.hasNext()) {
30622                                                final double ix = it.aDouble;
30623                                                double ox;
30624                                                ox = (Math.floor(ix));
30625                                                for (int j = 0; j < is; j++) {
30626                                                        oaf64data[it.oIndex + j] = ox;
30627                                                }
30628                                        }
30629                                } else {
30630                                        while (it.hasNext()) {
30631                                                final long ix = it.aLong;
30632                                                double ox;
30633                                                ox = (Math.floor(ix));
30634                                                for (int j = 0; j < is; j++) {
30635                                                        oaf64data[it.oIndex + j] = ox;
30636                                                }
30637                                        }
30638                                }
30639                        } else {
30640                                if (it.isOutputDouble()) {
30641                                        while (it.hasNext()) {
30642                                                for (int j = 0; j < is; j++) {
30643                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30644                                                        double ox;
30645                                                        ox = (Math.floor(ix));
30646                                                        oaf64data[it.oIndex + j] = ox;
30647                                                }
30648                                        }
30649                                } else {
30650                                        while (it.hasNext()) {
30651                                                for (int j = 0; j < is; j++) {
30652                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30653                                                        double ox;
30654                                                        ox = (Math.floor(ix));
30655                                                        oaf64data[it.oIndex + j] = ox;
30656                                                }
30657                                        }
30658                                }
30659                        }
30660                        break;
30661                case Dataset.COMPLEX64:
30662                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
30663                        if (!da.isComplex()) {
30664                                if (it.isOutputDouble()) {
30665                                        final double iy = 0;
30666                                        while (it.hasNext()) {
30667                                                final double ix = it.aDouble;
30668                                                float ox;
30669                                                float oy;
30670                                                ox = (float) (Math.floor(ix));
30671                                                oy = (float) (Math.floor(iy));
30672                                                oc64data[it.oIndex] = ox;
30673                                                oc64data[it.oIndex + 1] = oy;
30674                                        }
30675                                } else {
30676                                        final long iy = 0;
30677                                        while (it.hasNext()) {
30678                                                final long ix = it.aLong;
30679                                                float ox;
30680                                                float oy;
30681                                                ox = (float) toLong(Math.floor(ix));
30682                                                oy = (float) toLong(Math.floor(iy));
30683                                                oc64data[it.oIndex] = ox;
30684                                                oc64data[it.oIndex + 1] = oy;
30685                                        }
30686                                }
30687                        } else {
30688                                while (it.hasNext()) {
30689                                        final double ix = it.aDouble;
30690                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
30691                                        float ox;
30692                                        float oy;
30693                                        ox = (float) (Math.floor(ix));
30694                                        oy = (float) (Math.floor(iy));
30695                                        oc64data[it.oIndex] = ox;
30696                                        oc64data[it.oIndex + 1] = oy;
30697                                }
30698                        }
30699                        break;
30700                case Dataset.COMPLEX128:
30701                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
30702                        if (!da.isComplex()) {
30703                                if (it.isOutputDouble()) {
30704                                        final double iy = 0;
30705                                        while (it.hasNext()) {
30706                                                final double ix = it.aDouble;
30707                                                double ox;
30708                                                double oy;
30709                                                ox = (Math.floor(ix));
30710                                                oy = (Math.floor(iy));
30711                                                oc128data[it.oIndex] = ox;
30712                                                oc128data[it.oIndex + 1] = oy;
30713                                        }
30714                                } else {
30715                                        final long iy = 0;
30716                                        while (it.hasNext()) {
30717                                                final long ix = it.aLong;
30718                                                double ox;
30719                                                double oy;
30720                                                ox = (double) (Math.floor(ix));
30721                                                oy = (double) (Math.floor(iy));
30722                                                oc128data[it.oIndex] = ox;
30723                                                oc128data[it.oIndex + 1] = oy;
30724                                        }
30725                                }
30726                        } else {
30727                                while (it.hasNext()) {
30728                                        final double ix = it.aDouble;
30729                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
30730                                        double ox;
30731                                        double oy;
30732                                        ox = (Math.floor(ix));
30733                                        oy = (Math.floor(iy));
30734                                        oc128data[it.oIndex] = ox;
30735                                        oc128data[it.oIndex + 1] = oy;
30736                                }
30737                        }
30738                        break;
30739                default:
30740                        throw new IllegalArgumentException("floor supports integer, compound integer, real, compound real, complex datasets only");
30741                }
30742
30743                addFunctionName(result, "floor");
30744                return result;
30745        }
30746
30747        /**
30748         * ceil - evaluate the ceiling function on each element of the dataset
30749         * @param a
30750         * @return dataset
30751         */
30752        public static Dataset ceil(final Object a) {
30753                return ceil(a, null);
30754        }
30755
30756        /**
30757         * ceil - evaluate the ceiling function on each element of the dataset
30758         * @param a
30759         * @param o output can be null - in which case, a new dataset is created
30760         * @return dataset
30761         */
30762        public static Dataset ceil(final Object a, final Dataset o) {
30763                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
30764                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
30765                final Dataset result = it.getOutput();
30766                if (!result.isComplex()) {
30767                        if (da.isComplex()) {
30768                                da = da.getRealView();
30769                                it = new SingleInputBroadcastIterator(da, result, true);
30770                        }
30771                }
30772                final int is = result.getElementsPerItem();
30773                final int as = da.getElementsPerItem();
30774                final int dt = result.getDType();
30775
30776                switch(dt) {
30777                case Dataset.INT8:
30778                        final byte[] oi8data = ((ByteDataset) result).getData();
30779                        if (it.isOutputDouble()) {
30780                                while (it.hasNext()) {
30781                                        final double ix = it.aDouble;
30782                                        byte ox;
30783                                        ox = (byte) toLong(ix);
30784                                        oi8data[it.oIndex] = ox;
30785                                }
30786                        } else {
30787                                while (it.hasNext()) {
30788                                        final long ix = it.aLong;
30789                                        byte ox;
30790                                        ox = (byte) toLong(ix);
30791                                        oi8data[it.oIndex] = ox;
30792                                }
30793                        }
30794                        break;
30795                case Dataset.INT16:
30796                        final short[] oi16data = ((ShortDataset) result).getData();
30797                        if (it.isOutputDouble()) {
30798                                while (it.hasNext()) {
30799                                        final double ix = it.aDouble;
30800                                        short ox;
30801                                        ox = (short) toLong(ix);
30802                                        oi16data[it.oIndex] = ox;
30803                                }
30804                        } else {
30805                                while (it.hasNext()) {
30806                                        final long ix = it.aLong;
30807                                        short ox;
30808                                        ox = (short) toLong(ix);
30809                                        oi16data[it.oIndex] = ox;
30810                                }
30811                        }
30812                        break;
30813                case Dataset.INT64:
30814                        final long[] oi64data = ((LongDataset) result).getData();
30815                        if (it.isOutputDouble()) {
30816                                while (it.hasNext()) {
30817                                        final double ix = it.aDouble;
30818                                        long ox;
30819                                        ox = toLong(ix);
30820                                        oi64data[it.oIndex] = ox;
30821                                }
30822                        } else {
30823                                while (it.hasNext()) {
30824                                        final long ix = it.aLong;
30825                                        long ox;
30826                                        ox = toLong(ix);
30827                                        oi64data[it.oIndex] = ox;
30828                                }
30829                        }
30830                        break;
30831                case Dataset.INT32:
30832                        final int[] oi32data = ((IntegerDataset) result).getData();
30833                        if (it.isOutputDouble()) {
30834                                while (it.hasNext()) {
30835                                        final double ix = it.aDouble;
30836                                        int ox;
30837                                        ox = (int) toLong(ix);
30838                                        oi32data[it.oIndex] = ox;
30839                                }
30840                        } else {
30841                                while (it.hasNext()) {
30842                                        final long ix = it.aLong;
30843                                        int ox;
30844                                        ox = (int) toLong(ix);
30845                                        oi32data[it.oIndex] = ox;
30846                                }
30847                        }
30848                        break;
30849                case Dataset.ARRAYINT8:
30850                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
30851                        if (is == 1) {
30852                                if (it.isOutputDouble()) {
30853                                        while (it.hasNext()) {
30854                                                final double ix = it.aDouble;
30855                                                byte ox;
30856                                                ox = (byte) toLong(ix);
30857                                                oai8data[it.oIndex] = ox;
30858                                        }
30859                                } else {
30860                                        while (it.hasNext()) {
30861                                                final long ix = it.aLong;
30862                                                byte ox;
30863                                                ox = (byte) toLong(ix);
30864                                                oai8data[it.oIndex] = ox;
30865                                        }
30866                                }
30867                        } else if (as == 1) {
30868                                if (it.isOutputDouble()) {
30869                                        while (it.hasNext()) {
30870                                                final double ix = it.aDouble;
30871                                                byte ox;
30872                                                ox = (byte) toLong(ix);
30873                                                for (int j = 0; j < is; j++) {
30874                                                        oai8data[it.oIndex + j] = ox;
30875                                                }
30876                                        }
30877                                } else {
30878                                        while (it.hasNext()) {
30879                                                final long ix = it.aLong;
30880                                                byte ox;
30881                                                ox = (byte) toLong(ix);
30882                                                for (int j = 0; j < is; j++) {
30883                                                        oai8data[it.oIndex + j] = ox;
30884                                                }
30885                                        }
30886                                }
30887                        } else {
30888                                if (it.isOutputDouble()) {
30889                                        while (it.hasNext()) {
30890                                                for (int j = 0; j < is; j++) {
30891                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30892                                                        byte ox;
30893                                                        ox = (byte) toLong(ix);
30894                                                        oai8data[it.oIndex + j] = ox;
30895                                                }
30896                                        }
30897                                } else {
30898                                        while (it.hasNext()) {
30899                                                for (int j = 0; j < is; j++) {
30900                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30901                                                        byte ox;
30902                                                        ox = (byte) toLong(ix);
30903                                                        oai8data[it.oIndex + j] = ox;
30904                                                }
30905                                        }
30906                                }
30907                        }
30908                        break;
30909                case Dataset.ARRAYINT16:
30910                        final short[] oai16data = ((CompoundShortDataset) result).getData();
30911                        if (is == 1) {
30912                                if (it.isOutputDouble()) {
30913                                        while (it.hasNext()) {
30914                                                final double ix = it.aDouble;
30915                                                short ox;
30916                                                ox = (short) toLong(ix);
30917                                                oai16data[it.oIndex] = ox;
30918                                        }
30919                                } else {
30920                                        while (it.hasNext()) {
30921                                                final long ix = it.aLong;
30922                                                short ox;
30923                                                ox = (short) toLong(ix);
30924                                                oai16data[it.oIndex] = ox;
30925                                        }
30926                                }
30927                        } else if (as == 1) {
30928                                if (it.isOutputDouble()) {
30929                                        while (it.hasNext()) {
30930                                                final double ix = it.aDouble;
30931                                                short ox;
30932                                                ox = (short) toLong(ix);
30933                                                for (int j = 0; j < is; j++) {
30934                                                        oai16data[it.oIndex + j] = ox;
30935                                                }
30936                                        }
30937                                } else {
30938                                        while (it.hasNext()) {
30939                                                final long ix = it.aLong;
30940                                                short ox;
30941                                                ox = (short) toLong(ix);
30942                                                for (int j = 0; j < is; j++) {
30943                                                        oai16data[it.oIndex + j] = ox;
30944                                                }
30945                                        }
30946                                }
30947                        } else {
30948                                if (it.isOutputDouble()) {
30949                                        while (it.hasNext()) {
30950                                                for (int j = 0; j < is; j++) {
30951                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30952                                                        short ox;
30953                                                        ox = (short) toLong(ix);
30954                                                        oai16data[it.oIndex + j] = ox;
30955                                                }
30956                                        }
30957                                } else {
30958                                        while (it.hasNext()) {
30959                                                for (int j = 0; j < is; j++) {
30960                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30961                                                        short ox;
30962                                                        ox = (short) toLong(ix);
30963                                                        oai16data[it.oIndex + j] = ox;
30964                                                }
30965                                        }
30966                                }
30967                        }
30968                        break;
30969                case Dataset.ARRAYINT64:
30970                        final long[] oai64data = ((CompoundLongDataset) result).getData();
30971                        if (is == 1) {
30972                                if (it.isOutputDouble()) {
30973                                        while (it.hasNext()) {
30974                                                final double ix = it.aDouble;
30975                                                long ox;
30976                                                ox = toLong(ix);
30977                                                oai64data[it.oIndex] = ox;
30978                                        }
30979                                } else {
30980                                        while (it.hasNext()) {
30981                                                final long ix = it.aLong;
30982                                                long ox;
30983                                                ox = toLong(ix);
30984                                                oai64data[it.oIndex] = ox;
30985                                        }
30986                                }
30987                        } else if (as == 1) {
30988                                if (it.isOutputDouble()) {
30989                                        while (it.hasNext()) {
30990                                                final double ix = it.aDouble;
30991                                                long ox;
30992                                                ox = toLong(ix);
30993                                                for (int j = 0; j < is; j++) {
30994                                                        oai64data[it.oIndex + j] = ox;
30995                                                }
30996                                        }
30997                                } else {
30998                                        while (it.hasNext()) {
30999                                                final long ix = it.aLong;
31000                                                long ox;
31001                                                ox = toLong(ix);
31002                                                for (int j = 0; j < is; j++) {
31003                                                        oai64data[it.oIndex + j] = ox;
31004                                                }
31005                                        }
31006                                }
31007                        } else {
31008                                if (it.isOutputDouble()) {
31009                                        while (it.hasNext()) {
31010                                                for (int j = 0; j < is; j++) {
31011                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31012                                                        long ox;
31013                                                        ox = toLong(ix);
31014                                                        oai64data[it.oIndex + j] = ox;
31015                                                }
31016                                        }
31017                                } else {
31018                                        while (it.hasNext()) {
31019                                                for (int j = 0; j < is; j++) {
31020                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31021                                                        long ox;
31022                                                        ox = toLong(ix);
31023                                                        oai64data[it.oIndex + j] = ox;
31024                                                }
31025                                        }
31026                                }
31027                        }
31028                        break;
31029                case Dataset.ARRAYINT32:
31030                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
31031                        if (is == 1) {
31032                                if (it.isOutputDouble()) {
31033                                        while (it.hasNext()) {
31034                                                final double ix = it.aDouble;
31035                                                int ox;
31036                                                ox = (int) toLong(ix);
31037                                                oai32data[it.oIndex] = ox;
31038                                        }
31039                                } else {
31040                                        while (it.hasNext()) {
31041                                                final long ix = it.aLong;
31042                                                int ox;
31043                                                ox = (int) toLong(ix);
31044                                                oai32data[it.oIndex] = ox;
31045                                        }
31046                                }
31047                        } else if (as == 1) {
31048                                if (it.isOutputDouble()) {
31049                                        while (it.hasNext()) {
31050                                                final double ix = it.aDouble;
31051                                                int ox;
31052                                                ox = (int) toLong(ix);
31053                                                for (int j = 0; j < is; j++) {
31054                                                        oai32data[it.oIndex + j] = ox;
31055                                                }
31056                                        }
31057                                } else {
31058                                        while (it.hasNext()) {
31059                                                final long ix = it.aLong;
31060                                                int ox;
31061                                                ox = (int) toLong(ix);
31062                                                for (int j = 0; j < is; j++) {
31063                                                        oai32data[it.oIndex + j] = ox;
31064                                                }
31065                                        }
31066                                }
31067                        } else {
31068                                if (it.isOutputDouble()) {
31069                                        while (it.hasNext()) {
31070                                                for (int j = 0; j < is; j++) {
31071                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31072                                                        int ox;
31073                                                        ox = (int) toLong(ix);
31074                                                        oai32data[it.oIndex + j] = ox;
31075                                                }
31076                                        }
31077                                } else {
31078                                        while (it.hasNext()) {
31079                                                for (int j = 0; j < is; j++) {
31080                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31081                                                        int ox;
31082                                                        ox = (int) toLong(ix);
31083                                                        oai32data[it.oIndex + j] = ox;
31084                                                }
31085                                        }
31086                                }
31087                        }
31088                        break;
31089                case Dataset.FLOAT32:
31090                        final float[] of32data = ((FloatDataset) result).getData();
31091                        if (it.isOutputDouble()) {
31092                                while (it.hasNext()) {
31093                                        final double ix = it.aDouble;
31094                                        float ox;
31095                                        ox = (float) (Math.ceil(ix));
31096                                        of32data[it.oIndex] = ox;
31097                                }
31098                        } else {
31099                                while (it.hasNext()) {
31100                                        final long ix = it.aLong;
31101                                        float ox;
31102                                        ox = (float) (Math.ceil(ix));
31103                                        of32data[it.oIndex] = ox;
31104                                }
31105                        }
31106                        break;
31107                case Dataset.FLOAT64:
31108                        final double[] of64data = ((DoubleDataset) result).getData();
31109                        if (it.isOutputDouble()) {
31110                                while (it.hasNext()) {
31111                                        final double ix = it.aDouble;
31112                                        double ox;
31113                                        ox = (Math.ceil(ix));
31114                                        of64data[it.oIndex] = ox;
31115                                }
31116                        } else {
31117                                while (it.hasNext()) {
31118                                        final long ix = it.aLong;
31119                                        double ox;
31120                                        ox = (Math.ceil(ix));
31121                                        of64data[it.oIndex] = ox;
31122                                }
31123                        }
31124                        break;
31125                case Dataset.ARRAYFLOAT32:
31126                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
31127                        if (is == 1) {
31128                                if (it.isOutputDouble()) {
31129                                        while (it.hasNext()) {
31130                                                final double ix = it.aDouble;
31131                                                float ox;
31132                                                ox = (float) (Math.ceil(ix));
31133                                                oaf32data[it.oIndex] = ox;
31134                                        }
31135                                } else {
31136                                        while (it.hasNext()) {
31137                                                final long ix = it.aLong;
31138                                                float ox;
31139                                                ox = (float) (Math.ceil(ix));
31140                                                oaf32data[it.oIndex] = ox;
31141                                        }
31142                                }
31143                        } else if (as == 1) {
31144                                if (it.isOutputDouble()) {
31145                                        while (it.hasNext()) {
31146                                                final double ix = it.aDouble;
31147                                                float ox;
31148                                                ox = (float) (Math.ceil(ix));
31149                                                for (int j = 0; j < is; j++) {
31150                                                        oaf32data[it.oIndex + j] = ox;
31151                                                }
31152                                        }
31153                                } else {
31154                                        while (it.hasNext()) {
31155                                                final long ix = it.aLong;
31156                                                float ox;
31157                                                ox = (float) (Math.ceil(ix));
31158                                                for (int j = 0; j < is; j++) {
31159                                                        oaf32data[it.oIndex + j] = ox;
31160                                                }
31161                                        }
31162                                }
31163                        } else {
31164                                if (it.isOutputDouble()) {
31165                                        while (it.hasNext()) {
31166                                                for (int j = 0; j < is; j++) {
31167                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31168                                                        float ox;
31169                                                        ox = (float) (Math.ceil(ix));
31170                                                        oaf32data[it.oIndex + j] = ox;
31171                                                }
31172                                        }
31173                                } else {
31174                                        while (it.hasNext()) {
31175                                                for (int j = 0; j < is; j++) {
31176                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31177                                                        float ox;
31178                                                        ox = (float) (Math.ceil(ix));
31179                                                        oaf32data[it.oIndex + j] = ox;
31180                                                }
31181                                        }
31182                                }
31183                        }
31184                        break;
31185                case Dataset.ARRAYFLOAT64:
31186                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
31187                        if (is == 1) {
31188                                if (it.isOutputDouble()) {
31189                                        while (it.hasNext()) {
31190                                                final double ix = it.aDouble;
31191                                                double ox;
31192                                                ox = (Math.ceil(ix));
31193                                                oaf64data[it.oIndex] = ox;
31194                                        }
31195                                } else {
31196                                        while (it.hasNext()) {
31197                                                final long ix = it.aLong;
31198                                                double ox;
31199                                                ox = (Math.ceil(ix));
31200                                                oaf64data[it.oIndex] = ox;
31201                                        }
31202                                }
31203                        } else if (as == 1) {
31204                                if (it.isOutputDouble()) {
31205                                        while (it.hasNext()) {
31206                                                final double ix = it.aDouble;
31207                                                double ox;
31208                                                ox = (Math.ceil(ix));
31209                                                for (int j = 0; j < is; j++) {
31210                                                        oaf64data[it.oIndex + j] = ox;
31211                                                }
31212                                        }
31213                                } else {
31214                                        while (it.hasNext()) {
31215                                                final long ix = it.aLong;
31216                                                double ox;
31217                                                ox = (Math.ceil(ix));
31218                                                for (int j = 0; j < is; j++) {
31219                                                        oaf64data[it.oIndex + j] = ox;
31220                                                }
31221                                        }
31222                                }
31223                        } else {
31224                                if (it.isOutputDouble()) {
31225                                        while (it.hasNext()) {
31226                                                for (int j = 0; j < is; j++) {
31227                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31228                                                        double ox;
31229                                                        ox = (Math.ceil(ix));
31230                                                        oaf64data[it.oIndex + j] = ox;
31231                                                }
31232                                        }
31233                                } else {
31234                                        while (it.hasNext()) {
31235                                                for (int j = 0; j < is; j++) {
31236                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31237                                                        double ox;
31238                                                        ox = (Math.ceil(ix));
31239                                                        oaf64data[it.oIndex + j] = ox;
31240                                                }
31241                                        }
31242                                }
31243                        }
31244                        break;
31245                case Dataset.COMPLEX64:
31246                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
31247                        if (!da.isComplex()) {
31248                                if (it.isOutputDouble()) {
31249                                        final double iy = 0;
31250                                        while (it.hasNext()) {
31251                                                final double ix = it.aDouble;
31252                                                float ox;
31253                                                float oy;
31254                                                ox = (float) (Math.ceil(ix));
31255                                                oy = (float) (Math.ceil(iy));
31256                                                oc64data[it.oIndex] = ox;
31257                                                oc64data[it.oIndex + 1] = oy;
31258                                        }
31259                                } else {
31260                                        final long iy = 0;
31261                                        while (it.hasNext()) {
31262                                                final long ix = it.aLong;
31263                                                float ox;
31264                                                float oy;
31265                                                ox = (float) toLong(Math.ceil(ix));
31266                                                oy = (float) toLong(Math.ceil(iy));
31267                                                oc64data[it.oIndex] = ox;
31268                                                oc64data[it.oIndex + 1] = oy;
31269                                        }
31270                                }
31271                        } else {
31272                                while (it.hasNext()) {
31273                                        final double ix = it.aDouble;
31274                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
31275                                        float ox;
31276                                        float oy;
31277                                        ox = (float) (Math.ceil(ix));
31278                                        oy = (float) (Math.ceil(iy));
31279                                        oc64data[it.oIndex] = ox;
31280                                        oc64data[it.oIndex + 1] = oy;
31281                                }
31282                        }
31283                        break;
31284                case Dataset.COMPLEX128:
31285                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
31286                        if (!da.isComplex()) {
31287                                if (it.isOutputDouble()) {
31288                                        final double iy = 0;
31289                                        while (it.hasNext()) {
31290                                                final double ix = it.aDouble;
31291                                                double ox;
31292                                                double oy;
31293                                                ox = (Math.ceil(ix));
31294                                                oy = (Math.ceil(iy));
31295                                                oc128data[it.oIndex] = ox;
31296                                                oc128data[it.oIndex + 1] = oy;
31297                                        }
31298                                } else {
31299                                        final long iy = 0;
31300                                        while (it.hasNext()) {
31301                                                final long ix = it.aLong;
31302                                                double ox;
31303                                                double oy;
31304                                                ox = (double) (Math.ceil(ix));
31305                                                oy = (double) (Math.ceil(iy));
31306                                                oc128data[it.oIndex] = ox;
31307                                                oc128data[it.oIndex + 1] = oy;
31308                                        }
31309                                }
31310                        } else {
31311                                while (it.hasNext()) {
31312                                        final double ix = it.aDouble;
31313                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
31314                                        double ox;
31315                                        double oy;
31316                                        ox = (Math.ceil(ix));
31317                                        oy = (Math.ceil(iy));
31318                                        oc128data[it.oIndex] = ox;
31319                                        oc128data[it.oIndex + 1] = oy;
31320                                }
31321                        }
31322                        break;
31323                default:
31324                        throw new IllegalArgumentException("ceil supports integer, compound integer, real, compound real, complex datasets only");
31325                }
31326
31327                addFunctionName(result, "ceil");
31328                return result;
31329        }
31330
31331        /**
31332         * rint - round each element of the dataset
31333         * @param a
31334         * @return dataset
31335         */
31336        public static Dataset rint(final Object a) {
31337                return rint(a, null);
31338        }
31339
31340        /**
31341         * rint - round each element of the dataset
31342         * @param a
31343         * @param o output can be null - in which case, a new dataset is created
31344         * @return dataset
31345         */
31346        public static Dataset rint(final Object a, final Dataset o) {
31347                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
31348                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
31349                final Dataset result = it.getOutput();
31350                if (!result.isComplex()) {
31351                        if (da.isComplex()) {
31352                                da = da.getRealView();
31353                                it = new SingleInputBroadcastIterator(da, result, true);
31354                        }
31355                }
31356                final int is = result.getElementsPerItem();
31357                final int as = da.getElementsPerItem();
31358                final int dt = result.getDType();
31359
31360                switch(dt) {
31361                case Dataset.INT8:
31362                        final byte[] oi8data = ((ByteDataset) result).getData();
31363                        if (it.isOutputDouble()) {
31364                                while (it.hasNext()) {
31365                                        final double ix = it.aDouble;
31366                                        byte ox;
31367                                        ox = (byte) toLong(ix);
31368                                        oi8data[it.oIndex] = ox;
31369                                }
31370                        } else {
31371                                while (it.hasNext()) {
31372                                        final long ix = it.aLong;
31373                                        byte ox;
31374                                        ox = (byte) toLong(ix);
31375                                        oi8data[it.oIndex] = ox;
31376                                }
31377                        }
31378                        break;
31379                case Dataset.INT16:
31380                        final short[] oi16data = ((ShortDataset) result).getData();
31381                        if (it.isOutputDouble()) {
31382                                while (it.hasNext()) {
31383                                        final double ix = it.aDouble;
31384                                        short ox;
31385                                        ox = (short) toLong(ix);
31386                                        oi16data[it.oIndex] = ox;
31387                                }
31388                        } else {
31389                                while (it.hasNext()) {
31390                                        final long ix = it.aLong;
31391                                        short ox;
31392                                        ox = (short) toLong(ix);
31393                                        oi16data[it.oIndex] = ox;
31394                                }
31395                        }
31396                        break;
31397                case Dataset.INT64:
31398                        final long[] oi64data = ((LongDataset) result).getData();
31399                        if (it.isOutputDouble()) {
31400                                while (it.hasNext()) {
31401                                        final double ix = it.aDouble;
31402                                        long ox;
31403                                        ox = toLong(ix);
31404                                        oi64data[it.oIndex] = ox;
31405                                }
31406                        } else {
31407                                while (it.hasNext()) {
31408                                        final long ix = it.aLong;
31409                                        long ox;
31410                                        ox = toLong(ix);
31411                                        oi64data[it.oIndex] = ox;
31412                                }
31413                        }
31414                        break;
31415                case Dataset.INT32:
31416                        final int[] oi32data = ((IntegerDataset) result).getData();
31417                        if (it.isOutputDouble()) {
31418                                while (it.hasNext()) {
31419                                        final double ix = it.aDouble;
31420                                        int ox;
31421                                        ox = (int) toLong(ix);
31422                                        oi32data[it.oIndex] = ox;
31423                                }
31424                        } else {
31425                                while (it.hasNext()) {
31426                                        final long ix = it.aLong;
31427                                        int ox;
31428                                        ox = (int) toLong(ix);
31429                                        oi32data[it.oIndex] = ox;
31430                                }
31431                        }
31432                        break;
31433                case Dataset.ARRAYINT8:
31434                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
31435                        if (is == 1) {
31436                                if (it.isOutputDouble()) {
31437                                        while (it.hasNext()) {
31438                                                final double ix = it.aDouble;
31439                                                byte ox;
31440                                                ox = (byte) toLong(ix);
31441                                                oai8data[it.oIndex] = ox;
31442                                        }
31443                                } else {
31444                                        while (it.hasNext()) {
31445                                                final long ix = it.aLong;
31446                                                byte ox;
31447                                                ox = (byte) toLong(ix);
31448                                                oai8data[it.oIndex] = ox;
31449                                        }
31450                                }
31451                        } else if (as == 1) {
31452                                if (it.isOutputDouble()) {
31453                                        while (it.hasNext()) {
31454                                                final double ix = it.aDouble;
31455                                                byte ox;
31456                                                ox = (byte) toLong(ix);
31457                                                for (int j = 0; j < is; j++) {
31458                                                        oai8data[it.oIndex + j] = ox;
31459                                                }
31460                                        }
31461                                } else {
31462                                        while (it.hasNext()) {
31463                                                final long ix = it.aLong;
31464                                                byte ox;
31465                                                ox = (byte) toLong(ix);
31466                                                for (int j = 0; j < is; j++) {
31467                                                        oai8data[it.oIndex + j] = ox;
31468                                                }
31469                                        }
31470                                }
31471                        } else {
31472                                if (it.isOutputDouble()) {
31473                                        while (it.hasNext()) {
31474                                                for (int j = 0; j < is; j++) {
31475                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31476                                                        byte ox;
31477                                                        ox = (byte) toLong(ix);
31478                                                        oai8data[it.oIndex + j] = ox;
31479                                                }
31480                                        }
31481                                } else {
31482                                        while (it.hasNext()) {
31483                                                for (int j = 0; j < is; j++) {
31484                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31485                                                        byte ox;
31486                                                        ox = (byte) toLong(ix);
31487                                                        oai8data[it.oIndex + j] = ox;
31488                                                }
31489                                        }
31490                                }
31491                        }
31492                        break;
31493                case Dataset.ARRAYINT16:
31494                        final short[] oai16data = ((CompoundShortDataset) result).getData();
31495                        if (is == 1) {
31496                                if (it.isOutputDouble()) {
31497                                        while (it.hasNext()) {
31498                                                final double ix = it.aDouble;
31499                                                short ox;
31500                                                ox = (short) toLong(ix);
31501                                                oai16data[it.oIndex] = ox;
31502                                        }
31503                                } else {
31504                                        while (it.hasNext()) {
31505                                                final long ix = it.aLong;
31506                                                short ox;
31507                                                ox = (short) toLong(ix);
31508                                                oai16data[it.oIndex] = ox;
31509                                        }
31510                                }
31511                        } else if (as == 1) {
31512                                if (it.isOutputDouble()) {
31513                                        while (it.hasNext()) {
31514                                                final double ix = it.aDouble;
31515                                                short ox;
31516                                                ox = (short) toLong(ix);
31517                                                for (int j = 0; j < is; j++) {
31518                                                        oai16data[it.oIndex + j] = ox;
31519                                                }
31520                                        }
31521                                } else {
31522                                        while (it.hasNext()) {
31523                                                final long ix = it.aLong;
31524                                                short ox;
31525                                                ox = (short) toLong(ix);
31526                                                for (int j = 0; j < is; j++) {
31527                                                        oai16data[it.oIndex + j] = ox;
31528                                                }
31529                                        }
31530                                }
31531                        } else {
31532                                if (it.isOutputDouble()) {
31533                                        while (it.hasNext()) {
31534                                                for (int j = 0; j < is; j++) {
31535                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31536                                                        short ox;
31537                                                        ox = (short) toLong(ix);
31538                                                        oai16data[it.oIndex + j] = ox;
31539                                                }
31540                                        }
31541                                } else {
31542                                        while (it.hasNext()) {
31543                                                for (int j = 0; j < is; j++) {
31544                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31545                                                        short ox;
31546                                                        ox = (short) toLong(ix);
31547                                                        oai16data[it.oIndex + j] = ox;
31548                                                }
31549                                        }
31550                                }
31551                        }
31552                        break;
31553                case Dataset.ARRAYINT64:
31554                        final long[] oai64data = ((CompoundLongDataset) result).getData();
31555                        if (is == 1) {
31556                                if (it.isOutputDouble()) {
31557                                        while (it.hasNext()) {
31558                                                final double ix = it.aDouble;
31559                                                long ox;
31560                                                ox = toLong(ix);
31561                                                oai64data[it.oIndex] = ox;
31562                                        }
31563                                } else {
31564                                        while (it.hasNext()) {
31565                                                final long ix = it.aLong;
31566                                                long ox;
31567                                                ox = toLong(ix);
31568                                                oai64data[it.oIndex] = ox;
31569                                        }
31570                                }
31571                        } else if (as == 1) {
31572                                if (it.isOutputDouble()) {
31573                                        while (it.hasNext()) {
31574                                                final double ix = it.aDouble;
31575                                                long ox;
31576                                                ox = toLong(ix);
31577                                                for (int j = 0; j < is; j++) {
31578                                                        oai64data[it.oIndex + j] = ox;
31579                                                }
31580                                        }
31581                                } else {
31582                                        while (it.hasNext()) {
31583                                                final long ix = it.aLong;
31584                                                long ox;
31585                                                ox = toLong(ix);
31586                                                for (int j = 0; j < is; j++) {
31587                                                        oai64data[it.oIndex + j] = ox;
31588                                                }
31589                                        }
31590                                }
31591                        } else {
31592                                if (it.isOutputDouble()) {
31593                                        while (it.hasNext()) {
31594                                                for (int j = 0; j < is; j++) {
31595                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31596                                                        long ox;
31597                                                        ox = toLong(ix);
31598                                                        oai64data[it.oIndex + j] = ox;
31599                                                }
31600                                        }
31601                                } else {
31602                                        while (it.hasNext()) {
31603                                                for (int j = 0; j < is; j++) {
31604                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31605                                                        long ox;
31606                                                        ox = toLong(ix);
31607                                                        oai64data[it.oIndex + j] = ox;
31608                                                }
31609                                        }
31610                                }
31611                        }
31612                        break;
31613                case Dataset.ARRAYINT32:
31614                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
31615                        if (is == 1) {
31616                                if (it.isOutputDouble()) {
31617                                        while (it.hasNext()) {
31618                                                final double ix = it.aDouble;
31619                                                int ox;
31620                                                ox = (int) toLong(ix);
31621                                                oai32data[it.oIndex] = ox;
31622                                        }
31623                                } else {
31624                                        while (it.hasNext()) {
31625                                                final long ix = it.aLong;
31626                                                int ox;
31627                                                ox = (int) toLong(ix);
31628                                                oai32data[it.oIndex] = ox;
31629                                        }
31630                                }
31631                        } else if (as == 1) {
31632                                if (it.isOutputDouble()) {
31633                                        while (it.hasNext()) {
31634                                                final double ix = it.aDouble;
31635                                                int ox;
31636                                                ox = (int) toLong(ix);
31637                                                for (int j = 0; j < is; j++) {
31638                                                        oai32data[it.oIndex + j] = ox;
31639                                                }
31640                                        }
31641                                } else {
31642                                        while (it.hasNext()) {
31643                                                final long ix = it.aLong;
31644                                                int ox;
31645                                                ox = (int) toLong(ix);
31646                                                for (int j = 0; j < is; j++) {
31647                                                        oai32data[it.oIndex + j] = ox;
31648                                                }
31649                                        }
31650                                }
31651                        } else {
31652                                if (it.isOutputDouble()) {
31653                                        while (it.hasNext()) {
31654                                                for (int j = 0; j < is; j++) {
31655                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31656                                                        int ox;
31657                                                        ox = (int) toLong(ix);
31658                                                        oai32data[it.oIndex + j] = ox;
31659                                                }
31660                                        }
31661                                } else {
31662                                        while (it.hasNext()) {
31663                                                for (int j = 0; j < is; j++) {
31664                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31665                                                        int ox;
31666                                                        ox = (int) toLong(ix);
31667                                                        oai32data[it.oIndex + j] = ox;
31668                                                }
31669                                        }
31670                                }
31671                        }
31672                        break;
31673                case Dataset.FLOAT32:
31674                        final float[] of32data = ((FloatDataset) result).getData();
31675                        if (it.isOutputDouble()) {
31676                                while (it.hasNext()) {
31677                                        final double ix = it.aDouble;
31678                                        float ox;
31679                                        ox = (float) (Math.rint(ix));
31680                                        of32data[it.oIndex] = ox;
31681                                }
31682                        } else {
31683                                while (it.hasNext()) {
31684                                        final long ix = it.aLong;
31685                                        float ox;
31686                                        ox = (float) (Math.rint(ix));
31687                                        of32data[it.oIndex] = ox;
31688                                }
31689                        }
31690                        break;
31691                case Dataset.FLOAT64:
31692                        final double[] of64data = ((DoubleDataset) result).getData();
31693                        if (it.isOutputDouble()) {
31694                                while (it.hasNext()) {
31695                                        final double ix = it.aDouble;
31696                                        double ox;
31697                                        ox = (Math.rint(ix));
31698                                        of64data[it.oIndex] = ox;
31699                                }
31700                        } else {
31701                                while (it.hasNext()) {
31702                                        final long ix = it.aLong;
31703                                        double ox;
31704                                        ox = (Math.rint(ix));
31705                                        of64data[it.oIndex] = ox;
31706                                }
31707                        }
31708                        break;
31709                case Dataset.ARRAYFLOAT32:
31710                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
31711                        if (is == 1) {
31712                                if (it.isOutputDouble()) {
31713                                        while (it.hasNext()) {
31714                                                final double ix = it.aDouble;
31715                                                float ox;
31716                                                ox = (float) (Math.rint(ix));
31717                                                oaf32data[it.oIndex] = ox;
31718                                        }
31719                                } else {
31720                                        while (it.hasNext()) {
31721                                                final long ix = it.aLong;
31722                                                float ox;
31723                                                ox = (float) (Math.rint(ix));
31724                                                oaf32data[it.oIndex] = ox;
31725                                        }
31726                                }
31727                        } else if (as == 1) {
31728                                if (it.isOutputDouble()) {
31729                                        while (it.hasNext()) {
31730                                                final double ix = it.aDouble;
31731                                                float ox;
31732                                                ox = (float) (Math.rint(ix));
31733                                                for (int j = 0; j < is; j++) {
31734                                                        oaf32data[it.oIndex + j] = ox;
31735                                                }
31736                                        }
31737                                } else {
31738                                        while (it.hasNext()) {
31739                                                final long ix = it.aLong;
31740                                                float ox;
31741                                                ox = (float) (Math.rint(ix));
31742                                                for (int j = 0; j < is; j++) {
31743                                                        oaf32data[it.oIndex + j] = ox;
31744                                                }
31745                                        }
31746                                }
31747                        } else {
31748                                if (it.isOutputDouble()) {
31749                                        while (it.hasNext()) {
31750                                                for (int j = 0; j < is; j++) {
31751                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31752                                                        float ox;
31753                                                        ox = (float) (Math.rint(ix));
31754                                                        oaf32data[it.oIndex + j] = ox;
31755                                                }
31756                                        }
31757                                } else {
31758                                        while (it.hasNext()) {
31759                                                for (int j = 0; j < is; j++) {
31760                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31761                                                        float ox;
31762                                                        ox = (float) (Math.rint(ix));
31763                                                        oaf32data[it.oIndex + j] = ox;
31764                                                }
31765                                        }
31766                                }
31767                        }
31768                        break;
31769                case Dataset.ARRAYFLOAT64:
31770                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
31771                        if (is == 1) {
31772                                if (it.isOutputDouble()) {
31773                                        while (it.hasNext()) {
31774                                                final double ix = it.aDouble;
31775                                                double ox;
31776                                                ox = (Math.rint(ix));
31777                                                oaf64data[it.oIndex] = ox;
31778                                        }
31779                                } else {
31780                                        while (it.hasNext()) {
31781                                                final long ix = it.aLong;
31782                                                double ox;
31783                                                ox = (Math.rint(ix));
31784                                                oaf64data[it.oIndex] = ox;
31785                                        }
31786                                }
31787                        } else if (as == 1) {
31788                                if (it.isOutputDouble()) {
31789                                        while (it.hasNext()) {
31790                                                final double ix = it.aDouble;
31791                                                double ox;
31792                                                ox = (Math.rint(ix));
31793                                                for (int j = 0; j < is; j++) {
31794                                                        oaf64data[it.oIndex + j] = ox;
31795                                                }
31796                                        }
31797                                } else {
31798                                        while (it.hasNext()) {
31799                                                final long ix = it.aLong;
31800                                                double ox;
31801                                                ox = (Math.rint(ix));
31802                                                for (int j = 0; j < is; j++) {
31803                                                        oaf64data[it.oIndex + j] = ox;
31804                                                }
31805                                        }
31806                                }
31807                        } else {
31808                                if (it.isOutputDouble()) {
31809                                        while (it.hasNext()) {
31810                                                for (int j = 0; j < is; j++) {
31811                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31812                                                        double ox;
31813                                                        ox = (Math.rint(ix));
31814                                                        oaf64data[it.oIndex + j] = ox;
31815                                                }
31816                                        }
31817                                } else {
31818                                        while (it.hasNext()) {
31819                                                for (int j = 0; j < is; j++) {
31820                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31821                                                        double ox;
31822                                                        ox = (Math.rint(ix));
31823                                                        oaf64data[it.oIndex + j] = ox;
31824                                                }
31825                                        }
31826                                }
31827                        }
31828                        break;
31829                case Dataset.COMPLEX64:
31830                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
31831                        if (!da.isComplex()) {
31832                                if (it.isOutputDouble()) {
31833                                        final double iy = 0;
31834                                        while (it.hasNext()) {
31835                                                final double ix = it.aDouble;
31836                                                float ox;
31837                                                float oy;
31838                                                ox = (float) (Math.rint(ix));
31839                                                oy = (float) (Math.rint(iy));
31840                                                oc64data[it.oIndex] = ox;
31841                                                oc64data[it.oIndex + 1] = oy;
31842                                        }
31843                                } else {
31844                                        final long iy = 0;
31845                                        while (it.hasNext()) {
31846                                                final long ix = it.aLong;
31847                                                float ox;
31848                                                float oy;
31849                                                ox = (float) toLong(Math.rint(ix));
31850                                                oy = (float) toLong(Math.rint(iy));
31851                                                oc64data[it.oIndex] = ox;
31852                                                oc64data[it.oIndex + 1] = oy;
31853                                        }
31854                                }
31855                        } else {
31856                                while (it.hasNext()) {
31857                                        final double ix = it.aDouble;
31858                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
31859                                        float ox;
31860                                        float oy;
31861                                        ox = (float) (Math.rint(ix));
31862                                        oy = (float) (Math.rint(iy));
31863                                        oc64data[it.oIndex] = ox;
31864                                        oc64data[it.oIndex + 1] = oy;
31865                                }
31866                        }
31867                        break;
31868                case Dataset.COMPLEX128:
31869                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
31870                        if (!da.isComplex()) {
31871                                if (it.isOutputDouble()) {
31872                                        final double iy = 0;
31873                                        while (it.hasNext()) {
31874                                                final double ix = it.aDouble;
31875                                                double ox;
31876                                                double oy;
31877                                                ox = (Math.rint(ix));
31878                                                oy = (Math.rint(iy));
31879                                                oc128data[it.oIndex] = ox;
31880                                                oc128data[it.oIndex + 1] = oy;
31881                                        }
31882                                } else {
31883                                        final long iy = 0;
31884                                        while (it.hasNext()) {
31885                                                final long ix = it.aLong;
31886                                                double ox;
31887                                                double oy;
31888                                                ox = (double) (Math.rint(ix));
31889                                                oy = (double) (Math.rint(iy));
31890                                                oc128data[it.oIndex] = ox;
31891                                                oc128data[it.oIndex + 1] = oy;
31892                                        }
31893                                }
31894                        } else {
31895                                while (it.hasNext()) {
31896                                        final double ix = it.aDouble;
31897                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
31898                                        double ox;
31899                                        double oy;
31900                                        ox = (Math.rint(ix));
31901                                        oy = (Math.rint(iy));
31902                                        oc128data[it.oIndex] = ox;
31903                                        oc128data[it.oIndex + 1] = oy;
31904                                }
31905                        }
31906                        break;
31907                default:
31908                        throw new IllegalArgumentException("rint supports integer, compound integer, real, compound real, complex datasets only");
31909                }
31910
31911                addFunctionName(result, "rint");
31912                return result;
31913        }
31914
31915        /**
31916         * truncate - truncate each element to integers of the dataset
31917         * @param a
31918         * @return dataset
31919         */
31920        public static Dataset truncate(final Object a) {
31921                return truncate(a, null);
31922        }
31923
31924        /**
31925         * truncate - truncate each element to integers of the dataset
31926         * @param a
31927         * @param o output can be null - in which case, a new dataset is created
31928         * @return dataset
31929         */
31930        public static Dataset truncate(final Object a, final Dataset o) {
31931                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
31932                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
31933                final Dataset result = it.getOutput();
31934                if (!result.isComplex()) {
31935                        if (da.isComplex()) {
31936                                da = da.getRealView();
31937                                it = new SingleInputBroadcastIterator(da, result, true);
31938                        }
31939                }
31940                final int is = result.getElementsPerItem();
31941                final int as = da.getElementsPerItem();
31942                final int dt = result.getDType();
31943
31944                switch(dt) {
31945                case Dataset.INT8:
31946                        final byte[] oi8data = ((ByteDataset) result).getData();
31947                        if (it.isOutputDouble()) {
31948                                while (it.hasNext()) {
31949                                        final double ix = it.aDouble;
31950                                        byte ox;
31951                                        ox = (byte) toLong(ix);
31952                                        oi8data[it.oIndex] = ox;
31953                                }
31954                        } else {
31955                                while (it.hasNext()) {
31956                                        final long ix = it.aLong;
31957                                        byte ox;
31958                                        ox = (byte) toLong(ix);
31959                                        oi8data[it.oIndex] = ox;
31960                                }
31961                        }
31962                        break;
31963                case Dataset.INT16:
31964                        final short[] oi16data = ((ShortDataset) result).getData();
31965                        if (it.isOutputDouble()) {
31966                                while (it.hasNext()) {
31967                                        final double ix = it.aDouble;
31968                                        short ox;
31969                                        ox = (short) toLong(ix);
31970                                        oi16data[it.oIndex] = ox;
31971                                }
31972                        } else {
31973                                while (it.hasNext()) {
31974                                        final long ix = it.aLong;
31975                                        short ox;
31976                                        ox = (short) toLong(ix);
31977                                        oi16data[it.oIndex] = ox;
31978                                }
31979                        }
31980                        break;
31981                case Dataset.INT64:
31982                        final long[] oi64data = ((LongDataset) result).getData();
31983                        if (it.isOutputDouble()) {
31984                                while (it.hasNext()) {
31985                                        final double ix = it.aDouble;
31986                                        long ox;
31987                                        ox = toLong(ix);
31988                                        oi64data[it.oIndex] = ox;
31989                                }
31990                        } else {
31991                                while (it.hasNext()) {
31992                                        final long ix = it.aLong;
31993                                        long ox;
31994                                        ox = toLong(ix);
31995                                        oi64data[it.oIndex] = ox;
31996                                }
31997                        }
31998                        break;
31999                case Dataset.INT32:
32000                        final int[] oi32data = ((IntegerDataset) result).getData();
32001                        if (it.isOutputDouble()) {
32002                                while (it.hasNext()) {
32003                                        final double ix = it.aDouble;
32004                                        int ox;
32005                                        ox = (int) toLong(ix);
32006                                        oi32data[it.oIndex] = ox;
32007                                }
32008                        } else {
32009                                while (it.hasNext()) {
32010                                        final long ix = it.aLong;
32011                                        int ox;
32012                                        ox = (int) toLong(ix);
32013                                        oi32data[it.oIndex] = ox;
32014                                }
32015                        }
32016                        break;
32017                case Dataset.ARRAYINT8:
32018                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
32019                        if (is == 1) {
32020                                if (it.isOutputDouble()) {
32021                                        while (it.hasNext()) {
32022                                                final double ix = it.aDouble;
32023                                                byte ox;
32024                                                ox = (byte) toLong(ix);
32025                                                oai8data[it.oIndex] = ox;
32026                                        }
32027                                } else {
32028                                        while (it.hasNext()) {
32029                                                final long ix = it.aLong;
32030                                                byte ox;
32031                                                ox = (byte) toLong(ix);
32032                                                oai8data[it.oIndex] = ox;
32033                                        }
32034                                }
32035                        } else if (as == 1) {
32036                                if (it.isOutputDouble()) {
32037                                        while (it.hasNext()) {
32038                                                final double ix = it.aDouble;
32039                                                byte ox;
32040                                                ox = (byte) toLong(ix);
32041                                                for (int j = 0; j < is; j++) {
32042                                                        oai8data[it.oIndex + j] = ox;
32043                                                }
32044                                        }
32045                                } else {
32046                                        while (it.hasNext()) {
32047                                                final long ix = it.aLong;
32048                                                byte ox;
32049                                                ox = (byte) toLong(ix);
32050                                                for (int j = 0; j < is; j++) {
32051                                                        oai8data[it.oIndex + j] = ox;
32052                                                }
32053                                        }
32054                                }
32055                        } else {
32056                                if (it.isOutputDouble()) {
32057                                        while (it.hasNext()) {
32058                                                for (int j = 0; j < is; j++) {
32059                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32060                                                        byte ox;
32061                                                        ox = (byte) toLong(ix);
32062                                                        oai8data[it.oIndex + j] = ox;
32063                                                }
32064                                        }
32065                                } else {
32066                                        while (it.hasNext()) {
32067                                                for (int j = 0; j < is; j++) {
32068                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32069                                                        byte ox;
32070                                                        ox = (byte) toLong(ix);
32071                                                        oai8data[it.oIndex + j] = ox;
32072                                                }
32073                                        }
32074                                }
32075                        }
32076                        break;
32077                case Dataset.ARRAYINT16:
32078                        final short[] oai16data = ((CompoundShortDataset) result).getData();
32079                        if (is == 1) {
32080                                if (it.isOutputDouble()) {
32081                                        while (it.hasNext()) {
32082                                                final double ix = it.aDouble;
32083                                                short ox;
32084                                                ox = (short) toLong(ix);
32085                                                oai16data[it.oIndex] = ox;
32086                                        }
32087                                } else {
32088                                        while (it.hasNext()) {
32089                                                final long ix = it.aLong;
32090                                                short ox;
32091                                                ox = (short) toLong(ix);
32092                                                oai16data[it.oIndex] = ox;
32093                                        }
32094                                }
32095                        } else if (as == 1) {
32096                                if (it.isOutputDouble()) {
32097                                        while (it.hasNext()) {
32098                                                final double ix = it.aDouble;
32099                                                short ox;
32100                                                ox = (short) toLong(ix);
32101                                                for (int j = 0; j < is; j++) {
32102                                                        oai16data[it.oIndex + j] = ox;
32103                                                }
32104                                        }
32105                                } else {
32106                                        while (it.hasNext()) {
32107                                                final long ix = it.aLong;
32108                                                short ox;
32109                                                ox = (short) toLong(ix);
32110                                                for (int j = 0; j < is; j++) {
32111                                                        oai16data[it.oIndex + j] = ox;
32112                                                }
32113                                        }
32114                                }
32115                        } else {
32116                                if (it.isOutputDouble()) {
32117                                        while (it.hasNext()) {
32118                                                for (int j = 0; j < is; j++) {
32119                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32120                                                        short ox;
32121                                                        ox = (short) toLong(ix);
32122                                                        oai16data[it.oIndex + j] = ox;
32123                                                }
32124                                        }
32125                                } else {
32126                                        while (it.hasNext()) {
32127                                                for (int j = 0; j < is; j++) {
32128                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32129                                                        short ox;
32130                                                        ox = (short) toLong(ix);
32131                                                        oai16data[it.oIndex + j] = ox;
32132                                                }
32133                                        }
32134                                }
32135                        }
32136                        break;
32137                case Dataset.ARRAYINT64:
32138                        final long[] oai64data = ((CompoundLongDataset) result).getData();
32139                        if (is == 1) {
32140                                if (it.isOutputDouble()) {
32141                                        while (it.hasNext()) {
32142                                                final double ix = it.aDouble;
32143                                                long ox;
32144                                                ox = toLong(ix);
32145                                                oai64data[it.oIndex] = ox;
32146                                        }
32147                                } else {
32148                                        while (it.hasNext()) {
32149                                                final long ix = it.aLong;
32150                                                long ox;
32151                                                ox = toLong(ix);
32152                                                oai64data[it.oIndex] = ox;
32153                                        }
32154                                }
32155                        } else if (as == 1) {
32156                                if (it.isOutputDouble()) {
32157                                        while (it.hasNext()) {
32158                                                final double ix = it.aDouble;
32159                                                long ox;
32160                                                ox = toLong(ix);
32161                                                for (int j = 0; j < is; j++) {
32162                                                        oai64data[it.oIndex + j] = ox;
32163                                                }
32164                                        }
32165                                } else {
32166                                        while (it.hasNext()) {
32167                                                final long ix = it.aLong;
32168                                                long ox;
32169                                                ox = toLong(ix);
32170                                                for (int j = 0; j < is; j++) {
32171                                                        oai64data[it.oIndex + j] = ox;
32172                                                }
32173                                        }
32174                                }
32175                        } else {
32176                                if (it.isOutputDouble()) {
32177                                        while (it.hasNext()) {
32178                                                for (int j = 0; j < is; j++) {
32179                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32180                                                        long ox;
32181                                                        ox = toLong(ix);
32182                                                        oai64data[it.oIndex + j] = ox;
32183                                                }
32184                                        }
32185                                } else {
32186                                        while (it.hasNext()) {
32187                                                for (int j = 0; j < is; j++) {
32188                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32189                                                        long ox;
32190                                                        ox = toLong(ix);
32191                                                        oai64data[it.oIndex + j] = ox;
32192                                                }
32193                                        }
32194                                }
32195                        }
32196                        break;
32197                case Dataset.ARRAYINT32:
32198                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
32199                        if (is == 1) {
32200                                if (it.isOutputDouble()) {
32201                                        while (it.hasNext()) {
32202                                                final double ix = it.aDouble;
32203                                                int ox;
32204                                                ox = (int) toLong(ix);
32205                                                oai32data[it.oIndex] = ox;
32206                                        }
32207                                } else {
32208                                        while (it.hasNext()) {
32209                                                final long ix = it.aLong;
32210                                                int ox;
32211                                                ox = (int) toLong(ix);
32212                                                oai32data[it.oIndex] = ox;
32213                                        }
32214                                }
32215                        } else if (as == 1) {
32216                                if (it.isOutputDouble()) {
32217                                        while (it.hasNext()) {
32218                                                final double ix = it.aDouble;
32219                                                int ox;
32220                                                ox = (int) toLong(ix);
32221                                                for (int j = 0; j < is; j++) {
32222                                                        oai32data[it.oIndex + j] = ox;
32223                                                }
32224                                        }
32225                                } else {
32226                                        while (it.hasNext()) {
32227                                                final long ix = it.aLong;
32228                                                int ox;
32229                                                ox = (int) toLong(ix);
32230                                                for (int j = 0; j < is; j++) {
32231                                                        oai32data[it.oIndex + j] = ox;
32232                                                }
32233                                        }
32234                                }
32235                        } else {
32236                                if (it.isOutputDouble()) {
32237                                        while (it.hasNext()) {
32238                                                for (int j = 0; j < is; j++) {
32239                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32240                                                        int ox;
32241                                                        ox = (int) toLong(ix);
32242                                                        oai32data[it.oIndex + j] = ox;
32243                                                }
32244                                        }
32245                                } else {
32246                                        while (it.hasNext()) {
32247                                                for (int j = 0; j < is; j++) {
32248                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32249                                                        int ox;
32250                                                        ox = (int) toLong(ix);
32251                                                        oai32data[it.oIndex + j] = ox;
32252                                                }
32253                                        }
32254                                }
32255                        }
32256                        break;
32257                case Dataset.FLOAT32:
32258                        final float[] of32data = ((FloatDataset) result).getData();
32259                        if (it.isOutputDouble()) {
32260                                while (it.hasNext()) {
32261                                        final double ix = it.aDouble;
32262                                        float ox;
32263                                        ox = (float) (toLong(ix));
32264                                        of32data[it.oIndex] = ox;
32265                                }
32266                        } else {
32267                                while (it.hasNext()) {
32268                                        final long ix = it.aLong;
32269                                        float ox;
32270                                        ox = (toLong(ix));
32271                                        of32data[it.oIndex] = ox;
32272                                }
32273                        }
32274                        break;
32275                case Dataset.FLOAT64:
32276                        final double[] of64data = ((DoubleDataset) result).getData();
32277                        if (it.isOutputDouble()) {
32278                                while (it.hasNext()) {
32279                                        final double ix = it.aDouble;
32280                                        double ox;
32281                                        ox = (toLong(ix));
32282                                        of64data[it.oIndex] = ox;
32283                                }
32284                        } else {
32285                                while (it.hasNext()) {
32286                                        final long ix = it.aLong;
32287                                        double ox;
32288                                        ox = (toLong(ix));
32289                                        of64data[it.oIndex] = ox;
32290                                }
32291                        }
32292                        break;
32293                case Dataset.ARRAYFLOAT32:
32294                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
32295                        if (is == 1) {
32296                                if (it.isOutputDouble()) {
32297                                        while (it.hasNext()) {
32298                                                final double ix = it.aDouble;
32299                                                float ox;
32300                                                ox = (float) (toLong(ix));
32301                                                oaf32data[it.oIndex] = ox;
32302                                        }
32303                                } else {
32304                                        while (it.hasNext()) {
32305                                                final long ix = it.aLong;
32306                                                float ox;
32307                                                ox = (toLong(ix));
32308                                                oaf32data[it.oIndex] = ox;
32309                                        }
32310                                }
32311                        } else if (as == 1) {
32312                                if (it.isOutputDouble()) {
32313                                        while (it.hasNext()) {
32314                                                final double ix = it.aDouble;
32315                                                float ox;
32316                                                ox = (float) (toLong(ix));
32317                                                for (int j = 0; j < is; j++) {
32318                                                        oaf32data[it.oIndex + j] = ox;
32319                                                }
32320                                        }
32321                                } else {
32322                                        while (it.hasNext()) {
32323                                                final long ix = it.aLong;
32324                                                float ox;
32325                                                ox = (toLong(ix));
32326                                                for (int j = 0; j < is; j++) {
32327                                                        oaf32data[it.oIndex + j] = ox;
32328                                                }
32329                                        }
32330                                }
32331                        } else {
32332                                if (it.isOutputDouble()) {
32333                                        while (it.hasNext()) {
32334                                                for (int j = 0; j < is; j++) {
32335                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32336                                                        float ox;
32337                                                        ox = (float) (toLong(ix));
32338                                                        oaf32data[it.oIndex + j] = ox;
32339                                                }
32340                                        }
32341                                } else {
32342                                        while (it.hasNext()) {
32343                                                for (int j = 0; j < is; j++) {
32344                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32345                                                        float ox;
32346                                                        ox = (toLong(ix));
32347                                                        oaf32data[it.oIndex + j] = ox;
32348                                                }
32349                                        }
32350                                }
32351                        }
32352                        break;
32353                case Dataset.ARRAYFLOAT64:
32354                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
32355                        if (is == 1) {
32356                                if (it.isOutputDouble()) {
32357                                        while (it.hasNext()) {
32358                                                final double ix = it.aDouble;
32359                                                double ox;
32360                                                ox = (toLong(ix));
32361                                                oaf64data[it.oIndex] = ox;
32362                                        }
32363                                } else {
32364                                        while (it.hasNext()) {
32365                                                final long ix = it.aLong;
32366                                                double ox;
32367                                                ox = (toLong(ix));
32368                                                oaf64data[it.oIndex] = ox;
32369                                        }
32370                                }
32371                        } else if (as == 1) {
32372                                if (it.isOutputDouble()) {
32373                                        while (it.hasNext()) {
32374                                                final double ix = it.aDouble;
32375                                                double ox;
32376                                                ox = (toLong(ix));
32377                                                for (int j = 0; j < is; j++) {
32378                                                        oaf64data[it.oIndex + j] = ox;
32379                                                }
32380                                        }
32381                                } else {
32382                                        while (it.hasNext()) {
32383                                                final long ix = it.aLong;
32384                                                double ox;
32385                                                ox = (toLong(ix));
32386                                                for (int j = 0; j < is; j++) {
32387                                                        oaf64data[it.oIndex + j] = ox;
32388                                                }
32389                                        }
32390                                }
32391                        } else {
32392                                if (it.isOutputDouble()) {
32393                                        while (it.hasNext()) {
32394                                                for (int j = 0; j < is; j++) {
32395                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32396                                                        double ox;
32397                                                        ox = (toLong(ix));
32398                                                        oaf64data[it.oIndex + j] = ox;
32399                                                }
32400                                        }
32401                                } else {
32402                                        while (it.hasNext()) {
32403                                                for (int j = 0; j < is; j++) {
32404                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32405                                                        double ox;
32406                                                        ox = (toLong(ix));
32407                                                        oaf64data[it.oIndex + j] = ox;
32408                                                }
32409                                        }
32410                                }
32411                        }
32412                        break;
32413                case Dataset.COMPLEX64:
32414                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
32415                        if (!da.isComplex()) {
32416                                if (it.isOutputDouble()) {
32417                                        final double iy = 0;
32418                                        while (it.hasNext()) {
32419                                                final double ix = it.aDouble;
32420                                                float ox;
32421                                                float oy;
32422                                                ox = (float) (toLong(ix));
32423                                                oy = (float) (toLong(iy));
32424                                                oc64data[it.oIndex] = ox;
32425                                                oc64data[it.oIndex + 1] = oy;
32426                                        }
32427                                } else {
32428                                        final long iy = 0;
32429                                        while (it.hasNext()) {
32430                                                final long ix = it.aLong;
32431                                                float ox;
32432                                                float oy;
32433                                                ox = (float) toLong(toLong(ix));
32434                                                oy = (float) toLong(toLong(iy));
32435                                                oc64data[it.oIndex] = ox;
32436                                                oc64data[it.oIndex + 1] = oy;
32437                                        }
32438                                }
32439                        } else {
32440                                while (it.hasNext()) {
32441                                        final double ix = it.aDouble;
32442                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
32443                                        float ox;
32444                                        float oy;
32445                                        ox = (float) (toLong(ix));
32446                                        oy = (float) (toLong(iy));
32447                                        oc64data[it.oIndex] = ox;
32448                                        oc64data[it.oIndex + 1] = oy;
32449                                }
32450                        }
32451                        break;
32452                case Dataset.COMPLEX128:
32453                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
32454                        if (!da.isComplex()) {
32455                                if (it.isOutputDouble()) {
32456                                        final double iy = 0;
32457                                        while (it.hasNext()) {
32458                                                final double ix = it.aDouble;
32459                                                double ox;
32460                                                double oy;
32461                                                ox = (toLong(ix));
32462                                                oy = (toLong(iy));
32463                                                oc128data[it.oIndex] = ox;
32464                                                oc128data[it.oIndex + 1] = oy;
32465                                        }
32466                                } else {
32467                                        final long iy = 0;
32468                                        while (it.hasNext()) {
32469                                                final long ix = it.aLong;
32470                                                double ox;
32471                                                double oy;
32472                                                ox = (toLong(ix));
32473                                                oy = (toLong(iy));
32474                                                oc128data[it.oIndex] = ox;
32475                                                oc128data[it.oIndex + 1] = oy;
32476                                        }
32477                                }
32478                        } else {
32479                                while (it.hasNext()) {
32480                                        final double ix = it.aDouble;
32481                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
32482                                        double ox;
32483                                        double oy;
32484                                        ox = (toLong(ix));
32485                                        oy = (toLong(iy));
32486                                        oc128data[it.oIndex] = ox;
32487                                        oc128data[it.oIndex + 1] = oy;
32488                                }
32489                        }
32490                        break;
32491                default:
32492                        throw new IllegalArgumentException("truncate supports integer, compound integer, real, compound real, complex datasets only");
32493                }
32494
32495                addFunctionName(result, "truncate");
32496                return result;
32497        }
32498
32499        /**
32500         * toDegrees - convert to degrees
32501         * @param a
32502         * @return dataset
32503         */
32504        public static Dataset toDegrees(final Object a) {
32505                return toDegrees(a, null);
32506        }
32507
32508        /**
32509         * toDegrees - convert to degrees
32510         * @param a
32511         * @param o output can be null - in which case, a new dataset is created
32512         * @return dataset
32513         */
32514        public static Dataset toDegrees(final Object a, final Dataset o) {
32515                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
32516                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
32517                final Dataset result = it.getOutput();
32518                if (!result.isComplex()) {
32519                        if (da.isComplex()) {
32520                                da = da.getRealView();
32521                                it = new SingleInputBroadcastIterator(da, result, true);
32522                        }
32523                }
32524                final int is = result.getElementsPerItem();
32525                final int as = da.getElementsPerItem();
32526                final int dt = result.getDType();
32527
32528                switch(dt) {
32529                case Dataset.INT8:
32530                        final byte[] oi8data = ((ByteDataset) result).getData();
32531                        if (it.isOutputDouble()) {
32532                                while (it.hasNext()) {
32533                                        final double ix = it.aDouble;
32534                                        byte ox;
32535                                        ox = (byte) toLong(Math.toDegrees(ix));
32536                                        oi8data[it.oIndex] = ox;
32537                                }
32538                        } else {
32539                                while (it.hasNext()) {
32540                                        final long ix = it.aLong;
32541                                        byte ox;
32542                                        ox = (byte) toLong(Math.toDegrees(ix));
32543                                        oi8data[it.oIndex] = ox;
32544                                }
32545                        }
32546                        break;
32547                case Dataset.INT16:
32548                        final short[] oi16data = ((ShortDataset) result).getData();
32549                        if (it.isOutputDouble()) {
32550                                while (it.hasNext()) {
32551                                        final double ix = it.aDouble;
32552                                        short ox;
32553                                        ox = (short) toLong(Math.toDegrees(ix));
32554                                        oi16data[it.oIndex] = ox;
32555                                }
32556                        } else {
32557                                while (it.hasNext()) {
32558                                        final long ix = it.aLong;
32559                                        short ox;
32560                                        ox = (short) toLong(Math.toDegrees(ix));
32561                                        oi16data[it.oIndex] = ox;
32562                                }
32563                        }
32564                        break;
32565                case Dataset.INT64:
32566                        final long[] oi64data = ((LongDataset) result).getData();
32567                        if (it.isOutputDouble()) {
32568                                while (it.hasNext()) {
32569                                        final double ix = it.aDouble;
32570                                        long ox;
32571                                        ox = toLong(Math.toDegrees(ix));
32572                                        oi64data[it.oIndex] = ox;
32573                                }
32574                        } else {
32575                                while (it.hasNext()) {
32576                                        final long ix = it.aLong;
32577                                        long ox;
32578                                        ox = toLong(Math.toDegrees(ix));
32579                                        oi64data[it.oIndex] = ox;
32580                                }
32581                        }
32582                        break;
32583                case Dataset.INT32:
32584                        final int[] oi32data = ((IntegerDataset) result).getData();
32585                        if (it.isOutputDouble()) {
32586                                while (it.hasNext()) {
32587                                        final double ix = it.aDouble;
32588                                        int ox;
32589                                        ox = (int) toLong(Math.toDegrees(ix));
32590                                        oi32data[it.oIndex] = ox;
32591                                }
32592                        } else {
32593                                while (it.hasNext()) {
32594                                        final long ix = it.aLong;
32595                                        int ox;
32596                                        ox = (int) toLong(Math.toDegrees(ix));
32597                                        oi32data[it.oIndex] = ox;
32598                                }
32599                        }
32600                        break;
32601                case Dataset.ARRAYINT8:
32602                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
32603                        if (is == 1) {
32604                                if (it.isOutputDouble()) {
32605                                        while (it.hasNext()) {
32606                                                final double ix = it.aDouble;
32607                                                byte ox;
32608                                                ox = (byte) toLong(Math.toDegrees(ix));
32609                                                oai8data[it.oIndex] = ox;
32610                                        }
32611                                } else {
32612                                        while (it.hasNext()) {
32613                                                final long ix = it.aLong;
32614                                                byte ox;
32615                                                ox = (byte) toLong(Math.toDegrees(ix));
32616                                                oai8data[it.oIndex] = ox;
32617                                        }
32618                                }
32619                        } else if (as == 1) {
32620                                if (it.isOutputDouble()) {
32621                                        while (it.hasNext()) {
32622                                                final double ix = it.aDouble;
32623                                                byte ox;
32624                                                ox = (byte) toLong(Math.toDegrees(ix));
32625                                                for (int j = 0; j < is; j++) {
32626                                                        oai8data[it.oIndex + j] = ox;
32627                                                }
32628                                        }
32629                                } else {
32630                                        while (it.hasNext()) {
32631                                                final long ix = it.aLong;
32632                                                byte ox;
32633                                                ox = (byte) toLong(Math.toDegrees(ix));
32634                                                for (int j = 0; j < is; j++) {
32635                                                        oai8data[it.oIndex + j] = ox;
32636                                                }
32637                                        }
32638                                }
32639                        } else {
32640                                if (it.isOutputDouble()) {
32641                                        while (it.hasNext()) {
32642                                                for (int j = 0; j < is; j++) {
32643                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32644                                                        byte ox;
32645                                                        ox = (byte) toLong(Math.toDegrees(ix));
32646                                                        oai8data[it.oIndex + j] = ox;
32647                                                }
32648                                        }
32649                                } else {
32650                                        while (it.hasNext()) {
32651                                                for (int j = 0; j < is; j++) {
32652                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32653                                                        byte ox;
32654                                                        ox = (byte) toLong(Math.toDegrees(ix));
32655                                                        oai8data[it.oIndex + j] = ox;
32656                                                }
32657                                        }
32658                                }
32659                        }
32660                        break;
32661                case Dataset.ARRAYINT16:
32662                        final short[] oai16data = ((CompoundShortDataset) result).getData();
32663                        if (is == 1) {
32664                                if (it.isOutputDouble()) {
32665                                        while (it.hasNext()) {
32666                                                final double ix = it.aDouble;
32667                                                short ox;
32668                                                ox = (short) toLong(Math.toDegrees(ix));
32669                                                oai16data[it.oIndex] = ox;
32670                                        }
32671                                } else {
32672                                        while (it.hasNext()) {
32673                                                final long ix = it.aLong;
32674                                                short ox;
32675                                                ox = (short) toLong(Math.toDegrees(ix));
32676                                                oai16data[it.oIndex] = ox;
32677                                        }
32678                                }
32679                        } else if (as == 1) {
32680                                if (it.isOutputDouble()) {
32681                                        while (it.hasNext()) {
32682                                                final double ix = it.aDouble;
32683                                                short ox;
32684                                                ox = (short) toLong(Math.toDegrees(ix));
32685                                                for (int j = 0; j < is; j++) {
32686                                                        oai16data[it.oIndex + j] = ox;
32687                                                }
32688                                        }
32689                                } else {
32690                                        while (it.hasNext()) {
32691                                                final long ix = it.aLong;
32692                                                short ox;
32693                                                ox = (short) toLong(Math.toDegrees(ix));
32694                                                for (int j = 0; j < is; j++) {
32695                                                        oai16data[it.oIndex + j] = ox;
32696                                                }
32697                                        }
32698                                }
32699                        } else {
32700                                if (it.isOutputDouble()) {
32701                                        while (it.hasNext()) {
32702                                                for (int j = 0; j < is; j++) {
32703                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32704                                                        short ox;
32705                                                        ox = (short) toLong(Math.toDegrees(ix));
32706                                                        oai16data[it.oIndex + j] = ox;
32707                                                }
32708                                        }
32709                                } else {
32710                                        while (it.hasNext()) {
32711                                                for (int j = 0; j < is; j++) {
32712                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32713                                                        short ox;
32714                                                        ox = (short) toLong(Math.toDegrees(ix));
32715                                                        oai16data[it.oIndex + j] = ox;
32716                                                }
32717                                        }
32718                                }
32719                        }
32720                        break;
32721                case Dataset.ARRAYINT64:
32722                        final long[] oai64data = ((CompoundLongDataset) result).getData();
32723                        if (is == 1) {
32724                                if (it.isOutputDouble()) {
32725                                        while (it.hasNext()) {
32726                                                final double ix = it.aDouble;
32727                                                long ox;
32728                                                ox = toLong(Math.toDegrees(ix));
32729                                                oai64data[it.oIndex] = ox;
32730                                        }
32731                                } else {
32732                                        while (it.hasNext()) {
32733                                                final long ix = it.aLong;
32734                                                long ox;
32735                                                ox = toLong(Math.toDegrees(ix));
32736                                                oai64data[it.oIndex] = ox;
32737                                        }
32738                                }
32739                        } else if (as == 1) {
32740                                if (it.isOutputDouble()) {
32741                                        while (it.hasNext()) {
32742                                                final double ix = it.aDouble;
32743                                                long ox;
32744                                                ox = toLong(Math.toDegrees(ix));
32745                                                for (int j = 0; j < is; j++) {
32746                                                        oai64data[it.oIndex + j] = ox;
32747                                                }
32748                                        }
32749                                } else {
32750                                        while (it.hasNext()) {
32751                                                final long ix = it.aLong;
32752                                                long ox;
32753                                                ox = toLong(Math.toDegrees(ix));
32754                                                for (int j = 0; j < is; j++) {
32755                                                        oai64data[it.oIndex + j] = ox;
32756                                                }
32757                                        }
32758                                }
32759                        } else {
32760                                if (it.isOutputDouble()) {
32761                                        while (it.hasNext()) {
32762                                                for (int j = 0; j < is; j++) {
32763                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32764                                                        long ox;
32765                                                        ox = toLong(Math.toDegrees(ix));
32766                                                        oai64data[it.oIndex + j] = ox;
32767                                                }
32768                                        }
32769                                } else {
32770                                        while (it.hasNext()) {
32771                                                for (int j = 0; j < is; j++) {
32772                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32773                                                        long ox;
32774                                                        ox = toLong(Math.toDegrees(ix));
32775                                                        oai64data[it.oIndex + j] = ox;
32776                                                }
32777                                        }
32778                                }
32779                        }
32780                        break;
32781                case Dataset.ARRAYINT32:
32782                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
32783                        if (is == 1) {
32784                                if (it.isOutputDouble()) {
32785                                        while (it.hasNext()) {
32786                                                final double ix = it.aDouble;
32787                                                int ox;
32788                                                ox = (int) toLong(Math.toDegrees(ix));
32789                                                oai32data[it.oIndex] = ox;
32790                                        }
32791                                } else {
32792                                        while (it.hasNext()) {
32793                                                final long ix = it.aLong;
32794                                                int ox;
32795                                                ox = (int) toLong(Math.toDegrees(ix));
32796                                                oai32data[it.oIndex] = ox;
32797                                        }
32798                                }
32799                        } else if (as == 1) {
32800                                if (it.isOutputDouble()) {
32801                                        while (it.hasNext()) {
32802                                                final double ix = it.aDouble;
32803                                                int ox;
32804                                                ox = (int) toLong(Math.toDegrees(ix));
32805                                                for (int j = 0; j < is; j++) {
32806                                                        oai32data[it.oIndex + j] = ox;
32807                                                }
32808                                        }
32809                                } else {
32810                                        while (it.hasNext()) {
32811                                                final long ix = it.aLong;
32812                                                int ox;
32813                                                ox = (int) toLong(Math.toDegrees(ix));
32814                                                for (int j = 0; j < is; j++) {
32815                                                        oai32data[it.oIndex + j] = ox;
32816                                                }
32817                                        }
32818                                }
32819                        } else {
32820                                if (it.isOutputDouble()) {
32821                                        while (it.hasNext()) {
32822                                                for (int j = 0; j < is; j++) {
32823                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32824                                                        int ox;
32825                                                        ox = (int) toLong(Math.toDegrees(ix));
32826                                                        oai32data[it.oIndex + j] = ox;
32827                                                }
32828                                        }
32829                                } else {
32830                                        while (it.hasNext()) {
32831                                                for (int j = 0; j < is; j++) {
32832                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32833                                                        int ox;
32834                                                        ox = (int) toLong(Math.toDegrees(ix));
32835                                                        oai32data[it.oIndex + j] = ox;
32836                                                }
32837                                        }
32838                                }
32839                        }
32840                        break;
32841                case Dataset.FLOAT32:
32842                        final float[] of32data = ((FloatDataset) result).getData();
32843                        if (it.isOutputDouble()) {
32844                                while (it.hasNext()) {
32845                                        final double ix = it.aDouble;
32846                                        float ox;
32847                                        ox = (float) (Math.toDegrees(ix));
32848                                        of32data[it.oIndex] = ox;
32849                                }
32850                        } else {
32851                                while (it.hasNext()) {
32852                                        final long ix = it.aLong;
32853                                        float ox;
32854                                        ox = (float) (Math.toDegrees(ix));
32855                                        of32data[it.oIndex] = ox;
32856                                }
32857                        }
32858                        break;
32859                case Dataset.FLOAT64:
32860                        final double[] of64data = ((DoubleDataset) result).getData();
32861                        if (it.isOutputDouble()) {
32862                                while (it.hasNext()) {
32863                                        final double ix = it.aDouble;
32864                                        double ox;
32865                                        ox = (Math.toDegrees(ix));
32866                                        of64data[it.oIndex] = ox;
32867                                }
32868                        } else {
32869                                while (it.hasNext()) {
32870                                        final long ix = it.aLong;
32871                                        double ox;
32872                                        ox = (Math.toDegrees(ix));
32873                                        of64data[it.oIndex] = ox;
32874                                }
32875                        }
32876                        break;
32877                case Dataset.ARRAYFLOAT32:
32878                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
32879                        if (is == 1) {
32880                                if (it.isOutputDouble()) {
32881                                        while (it.hasNext()) {
32882                                                final double ix = it.aDouble;
32883                                                float ox;
32884                                                ox = (float) (Math.toDegrees(ix));
32885                                                oaf32data[it.oIndex] = ox;
32886                                        }
32887                                } else {
32888                                        while (it.hasNext()) {
32889                                                final long ix = it.aLong;
32890                                                float ox;
32891                                                ox = (float) (Math.toDegrees(ix));
32892                                                oaf32data[it.oIndex] = ox;
32893                                        }
32894                                }
32895                        } else if (as == 1) {
32896                                if (it.isOutputDouble()) {
32897                                        while (it.hasNext()) {
32898                                                final double ix = it.aDouble;
32899                                                float ox;
32900                                                ox = (float) (Math.toDegrees(ix));
32901                                                for (int j = 0; j < is; j++) {
32902                                                        oaf32data[it.oIndex + j] = ox;
32903                                                }
32904                                        }
32905                                } else {
32906                                        while (it.hasNext()) {
32907                                                final long ix = it.aLong;
32908                                                float ox;
32909                                                ox = (float) (Math.toDegrees(ix));
32910                                                for (int j = 0; j < is; j++) {
32911                                                        oaf32data[it.oIndex + j] = ox;
32912                                                }
32913                                        }
32914                                }
32915                        } else {
32916                                if (it.isOutputDouble()) {
32917                                        while (it.hasNext()) {
32918                                                for (int j = 0; j < is; j++) {
32919                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32920                                                        float ox;
32921                                                        ox = (float) (Math.toDegrees(ix));
32922                                                        oaf32data[it.oIndex + j] = ox;
32923                                                }
32924                                        }
32925                                } else {
32926                                        while (it.hasNext()) {
32927                                                for (int j = 0; j < is; j++) {
32928                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32929                                                        float ox;
32930                                                        ox = (float) (Math.toDegrees(ix));
32931                                                        oaf32data[it.oIndex + j] = ox;
32932                                                }
32933                                        }
32934                                }
32935                        }
32936                        break;
32937                case Dataset.ARRAYFLOAT64:
32938                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
32939                        if (is == 1) {
32940                                if (it.isOutputDouble()) {
32941                                        while (it.hasNext()) {
32942                                                final double ix = it.aDouble;
32943                                                double ox;
32944                                                ox = (Math.toDegrees(ix));
32945                                                oaf64data[it.oIndex] = ox;
32946                                        }
32947                                } else {
32948                                        while (it.hasNext()) {
32949                                                final long ix = it.aLong;
32950                                                double ox;
32951                                                ox = (Math.toDegrees(ix));
32952                                                oaf64data[it.oIndex] = ox;
32953                                        }
32954                                }
32955                        } else if (as == 1) {
32956                                if (it.isOutputDouble()) {
32957                                        while (it.hasNext()) {
32958                                                final double ix = it.aDouble;
32959                                                double ox;
32960                                                ox = (Math.toDegrees(ix));
32961                                                for (int j = 0; j < is; j++) {
32962                                                        oaf64data[it.oIndex + j] = ox;
32963                                                }
32964                                        }
32965                                } else {
32966                                        while (it.hasNext()) {
32967                                                final long ix = it.aLong;
32968                                                double ox;
32969                                                ox = (Math.toDegrees(ix));
32970                                                for (int j = 0; j < is; j++) {
32971                                                        oaf64data[it.oIndex + j] = ox;
32972                                                }
32973                                        }
32974                                }
32975                        } else {
32976                                if (it.isOutputDouble()) {
32977                                        while (it.hasNext()) {
32978                                                for (int j = 0; j < is; j++) {
32979                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32980                                                        double ox;
32981                                                        ox = (Math.toDegrees(ix));
32982                                                        oaf64data[it.oIndex + j] = ox;
32983                                                }
32984                                        }
32985                                } else {
32986                                        while (it.hasNext()) {
32987                                                for (int j = 0; j < is; j++) {
32988                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32989                                                        double ox;
32990                                                        ox = (Math.toDegrees(ix));
32991                                                        oaf64data[it.oIndex + j] = ox;
32992                                                }
32993                                        }
32994                                }
32995                        }
32996                        break;
32997                case Dataset.COMPLEX64:
32998                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
32999                        if (!da.isComplex()) {
33000                                if (it.isOutputDouble()) {
33001                                        final double iy = 0;
33002                                        while (it.hasNext()) {
33003                                                final double ix = it.aDouble;
33004                                                float ox;
33005                                                float oy;
33006                                                ox = (float) (Math.toDegrees(ix));
33007                                                oy = (float) (Math.toDegrees(iy));
33008                                                oc64data[it.oIndex] = ox;
33009                                                oc64data[it.oIndex + 1] = oy;
33010                                        }
33011                                } else {
33012                                        final long iy = 0;
33013                                        while (it.hasNext()) {
33014                                                final long ix = it.aLong;
33015                                                float ox;
33016                                                float oy;
33017                                                ox = (float) toLong(Math.toDegrees(ix));
33018                                                oy = (float) toLong(Math.toDegrees(iy));
33019                                                oc64data[it.oIndex] = ox;
33020                                                oc64data[it.oIndex + 1] = oy;
33021                                        }
33022                                }
33023                        } else {
33024                                while (it.hasNext()) {
33025                                        final double ix = it.aDouble;
33026                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
33027                                        float ox;
33028                                        float oy;
33029                                        ox = (float) (Math.toDegrees(ix));
33030                                        oy = (float) (Math.toDegrees(iy));
33031                                        oc64data[it.oIndex] = ox;
33032                                        oc64data[it.oIndex + 1] = oy;
33033                                }
33034                        }
33035                        break;
33036                case Dataset.COMPLEX128:
33037                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
33038                        if (!da.isComplex()) {
33039                                if (it.isOutputDouble()) {
33040                                        final double iy = 0;
33041                                        while (it.hasNext()) {
33042                                                final double ix = it.aDouble;
33043                                                double ox;
33044                                                double oy;
33045                                                ox = (Math.toDegrees(ix));
33046                                                oy = (Math.toDegrees(iy));
33047                                                oc128data[it.oIndex] = ox;
33048                                                oc128data[it.oIndex + 1] = oy;
33049                                        }
33050                                } else {
33051                                        final long iy = 0;
33052                                        while (it.hasNext()) {
33053                                                final long ix = it.aLong;
33054                                                double ox;
33055                                                double oy;
33056                                                ox = (double) (Math.toDegrees(ix));
33057                                                oy = (double) (Math.toDegrees(iy));
33058                                                oc128data[it.oIndex] = ox;
33059                                                oc128data[it.oIndex + 1] = oy;
33060                                        }
33061                                }
33062                        } else {
33063                                while (it.hasNext()) {
33064                                        final double ix = it.aDouble;
33065                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
33066                                        double ox;
33067                                        double oy;
33068                                        ox = (Math.toDegrees(ix));
33069                                        oy = (Math.toDegrees(iy));
33070                                        oc128data[it.oIndex] = ox;
33071                                        oc128data[it.oIndex + 1] = oy;
33072                                }
33073                        }
33074                        break;
33075                default:
33076                        throw new IllegalArgumentException("toDegrees supports integer, compound integer, real, compound real, complex datasets only");
33077                }
33078
33079                addFunctionName(result, "toDegrees");
33080                return result;
33081        }
33082
33083        /**
33084         * toRadians - convert to radians
33085         * @param a
33086         * @return dataset
33087         */
33088        public static Dataset toRadians(final Object a) {
33089                return toRadians(a, null);
33090        }
33091
33092        /**
33093         * toRadians - convert to radians
33094         * @param a
33095         * @param o output can be null - in which case, a new dataset is created
33096         * @return dataset
33097         */
33098        public static Dataset toRadians(final Object a, final Dataset o) {
33099                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
33100                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
33101                final Dataset result = it.getOutput();
33102                if (!result.isComplex()) {
33103                        if (da.isComplex()) {
33104                                da = da.getRealView();
33105                                it = new SingleInputBroadcastIterator(da, result, true);
33106                        }
33107                }
33108                final int is = result.getElementsPerItem();
33109                final int as = da.getElementsPerItem();
33110                final int dt = result.getDType();
33111
33112                switch(dt) {
33113                case Dataset.INT8:
33114                        final byte[] oi8data = ((ByteDataset) result).getData();
33115                        if (it.isOutputDouble()) {
33116                                while (it.hasNext()) {
33117                                        final double ix = it.aDouble;
33118                                        byte ox;
33119                                        ox = (byte) toLong(Math.toRadians(ix));
33120                                        oi8data[it.oIndex] = ox;
33121                                }
33122                        } else {
33123                                while (it.hasNext()) {
33124                                        final long ix = it.aLong;
33125                                        byte ox;
33126                                        ox = (byte) toLong(Math.toRadians(ix));
33127                                        oi8data[it.oIndex] = ox;
33128                                }
33129                        }
33130                        break;
33131                case Dataset.INT16:
33132                        final short[] oi16data = ((ShortDataset) result).getData();
33133                        if (it.isOutputDouble()) {
33134                                while (it.hasNext()) {
33135                                        final double ix = it.aDouble;
33136                                        short ox;
33137                                        ox = (short) toLong(Math.toRadians(ix));
33138                                        oi16data[it.oIndex] = ox;
33139                                }
33140                        } else {
33141                                while (it.hasNext()) {
33142                                        final long ix = it.aLong;
33143                                        short ox;
33144                                        ox = (short) toLong(Math.toRadians(ix));
33145                                        oi16data[it.oIndex] = ox;
33146                                }
33147                        }
33148                        break;
33149                case Dataset.INT64:
33150                        final long[] oi64data = ((LongDataset) result).getData();
33151                        if (it.isOutputDouble()) {
33152                                while (it.hasNext()) {
33153                                        final double ix = it.aDouble;
33154                                        long ox;
33155                                        ox = toLong(Math.toRadians(ix));
33156                                        oi64data[it.oIndex] = ox;
33157                                }
33158                        } else {
33159                                while (it.hasNext()) {
33160                                        final long ix = it.aLong;
33161                                        long ox;
33162                                        ox = toLong(Math.toRadians(ix));
33163                                        oi64data[it.oIndex] = ox;
33164                                }
33165                        }
33166                        break;
33167                case Dataset.INT32:
33168                        final int[] oi32data = ((IntegerDataset) result).getData();
33169                        if (it.isOutputDouble()) {
33170                                while (it.hasNext()) {
33171                                        final double ix = it.aDouble;
33172                                        int ox;
33173                                        ox = (int) toLong(Math.toRadians(ix));
33174                                        oi32data[it.oIndex] = ox;
33175                                }
33176                        } else {
33177                                while (it.hasNext()) {
33178                                        final long ix = it.aLong;
33179                                        int ox;
33180                                        ox = (int) toLong(Math.toRadians(ix));
33181                                        oi32data[it.oIndex] = ox;
33182                                }
33183                        }
33184                        break;
33185                case Dataset.ARRAYINT8:
33186                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
33187                        if (is == 1) {
33188                                if (it.isOutputDouble()) {
33189                                        while (it.hasNext()) {
33190                                                final double ix = it.aDouble;
33191                                                byte ox;
33192                                                ox = (byte) toLong(Math.toRadians(ix));
33193                                                oai8data[it.oIndex] = ox;
33194                                        }
33195                                } else {
33196                                        while (it.hasNext()) {
33197                                                final long ix = it.aLong;
33198                                                byte ox;
33199                                                ox = (byte) toLong(Math.toRadians(ix));
33200                                                oai8data[it.oIndex] = ox;
33201                                        }
33202                                }
33203                        } else if (as == 1) {
33204                                if (it.isOutputDouble()) {
33205                                        while (it.hasNext()) {
33206                                                final double ix = it.aDouble;
33207                                                byte ox;
33208                                                ox = (byte) toLong(Math.toRadians(ix));
33209                                                for (int j = 0; j < is; j++) {
33210                                                        oai8data[it.oIndex + j] = ox;
33211                                                }
33212                                        }
33213                                } else {
33214                                        while (it.hasNext()) {
33215                                                final long ix = it.aLong;
33216                                                byte ox;
33217                                                ox = (byte) toLong(Math.toRadians(ix));
33218                                                for (int j = 0; j < is; j++) {
33219                                                        oai8data[it.oIndex + j] = ox;
33220                                                }
33221                                        }
33222                                }
33223                        } else {
33224                                if (it.isOutputDouble()) {
33225                                        while (it.hasNext()) {
33226                                                for (int j = 0; j < is; j++) {
33227                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33228                                                        byte ox;
33229                                                        ox = (byte) toLong(Math.toRadians(ix));
33230                                                        oai8data[it.oIndex + j] = ox;
33231                                                }
33232                                        }
33233                                } else {
33234                                        while (it.hasNext()) {
33235                                                for (int j = 0; j < is; j++) {
33236                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33237                                                        byte ox;
33238                                                        ox = (byte) toLong(Math.toRadians(ix));
33239                                                        oai8data[it.oIndex + j] = ox;
33240                                                }
33241                                        }
33242                                }
33243                        }
33244                        break;
33245                case Dataset.ARRAYINT16:
33246                        final short[] oai16data = ((CompoundShortDataset) result).getData();
33247                        if (is == 1) {
33248                                if (it.isOutputDouble()) {
33249                                        while (it.hasNext()) {
33250                                                final double ix = it.aDouble;
33251                                                short ox;
33252                                                ox = (short) toLong(Math.toRadians(ix));
33253                                                oai16data[it.oIndex] = ox;
33254                                        }
33255                                } else {
33256                                        while (it.hasNext()) {
33257                                                final long ix = it.aLong;
33258                                                short ox;
33259                                                ox = (short) toLong(Math.toRadians(ix));
33260                                                oai16data[it.oIndex] = ox;
33261                                        }
33262                                }
33263                        } else if (as == 1) {
33264                                if (it.isOutputDouble()) {
33265                                        while (it.hasNext()) {
33266                                                final double ix = it.aDouble;
33267                                                short ox;
33268                                                ox = (short) toLong(Math.toRadians(ix));
33269                                                for (int j = 0; j < is; j++) {
33270                                                        oai16data[it.oIndex + j] = ox;
33271                                                }
33272                                        }
33273                                } else {
33274                                        while (it.hasNext()) {
33275                                                final long ix = it.aLong;
33276                                                short ox;
33277                                                ox = (short) toLong(Math.toRadians(ix));
33278                                                for (int j = 0; j < is; j++) {
33279                                                        oai16data[it.oIndex + j] = ox;
33280                                                }
33281                                        }
33282                                }
33283                        } else {
33284                                if (it.isOutputDouble()) {
33285                                        while (it.hasNext()) {
33286                                                for (int j = 0; j < is; j++) {
33287                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33288                                                        short ox;
33289                                                        ox = (short) toLong(Math.toRadians(ix));
33290                                                        oai16data[it.oIndex + j] = ox;
33291                                                }
33292                                        }
33293                                } else {
33294                                        while (it.hasNext()) {
33295                                                for (int j = 0; j < is; j++) {
33296                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33297                                                        short ox;
33298                                                        ox = (short) toLong(Math.toRadians(ix));
33299                                                        oai16data[it.oIndex + j] = ox;
33300                                                }
33301                                        }
33302                                }
33303                        }
33304                        break;
33305                case Dataset.ARRAYINT64:
33306                        final long[] oai64data = ((CompoundLongDataset) result).getData();
33307                        if (is == 1) {
33308                                if (it.isOutputDouble()) {
33309                                        while (it.hasNext()) {
33310                                                final double ix = it.aDouble;
33311                                                long ox;
33312                                                ox = toLong(Math.toRadians(ix));
33313                                                oai64data[it.oIndex] = ox;
33314                                        }
33315                                } else {
33316                                        while (it.hasNext()) {
33317                                                final long ix = it.aLong;
33318                                                long ox;
33319                                                ox = toLong(Math.toRadians(ix));
33320                                                oai64data[it.oIndex] = ox;
33321                                        }
33322                                }
33323                        } else if (as == 1) {
33324                                if (it.isOutputDouble()) {
33325                                        while (it.hasNext()) {
33326                                                final double ix = it.aDouble;
33327                                                long ox;
33328                                                ox = toLong(Math.toRadians(ix));
33329                                                for (int j = 0; j < is; j++) {
33330                                                        oai64data[it.oIndex + j] = ox;
33331                                                }
33332                                        }
33333                                } else {
33334                                        while (it.hasNext()) {
33335                                                final long ix = it.aLong;
33336                                                long ox;
33337                                                ox = toLong(Math.toRadians(ix));
33338                                                for (int j = 0; j < is; j++) {
33339                                                        oai64data[it.oIndex + j] = ox;
33340                                                }
33341                                        }
33342                                }
33343                        } else {
33344                                if (it.isOutputDouble()) {
33345                                        while (it.hasNext()) {
33346                                                for (int j = 0; j < is; j++) {
33347                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33348                                                        long ox;
33349                                                        ox = toLong(Math.toRadians(ix));
33350                                                        oai64data[it.oIndex + j] = ox;
33351                                                }
33352                                        }
33353                                } else {
33354                                        while (it.hasNext()) {
33355                                                for (int j = 0; j < is; j++) {
33356                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33357                                                        long ox;
33358                                                        ox = toLong(Math.toRadians(ix));
33359                                                        oai64data[it.oIndex + j] = ox;
33360                                                }
33361                                        }
33362                                }
33363                        }
33364                        break;
33365                case Dataset.ARRAYINT32:
33366                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
33367                        if (is == 1) {
33368                                if (it.isOutputDouble()) {
33369                                        while (it.hasNext()) {
33370                                                final double ix = it.aDouble;
33371                                                int ox;
33372                                                ox = (int) toLong(Math.toRadians(ix));
33373                                                oai32data[it.oIndex] = ox;
33374                                        }
33375                                } else {
33376                                        while (it.hasNext()) {
33377                                                final long ix = it.aLong;
33378                                                int ox;
33379                                                ox = (int) toLong(Math.toRadians(ix));
33380                                                oai32data[it.oIndex] = ox;
33381                                        }
33382                                }
33383                        } else if (as == 1) {
33384                                if (it.isOutputDouble()) {
33385                                        while (it.hasNext()) {
33386                                                final double ix = it.aDouble;
33387                                                int ox;
33388                                                ox = (int) toLong(Math.toRadians(ix));
33389                                                for (int j = 0; j < is; j++) {
33390                                                        oai32data[it.oIndex + j] = ox;
33391                                                }
33392                                        }
33393                                } else {
33394                                        while (it.hasNext()) {
33395                                                final long ix = it.aLong;
33396                                                int ox;
33397                                                ox = (int) toLong(Math.toRadians(ix));
33398                                                for (int j = 0; j < is; j++) {
33399                                                        oai32data[it.oIndex + j] = ox;
33400                                                }
33401                                        }
33402                                }
33403                        } else {
33404                                if (it.isOutputDouble()) {
33405                                        while (it.hasNext()) {
33406                                                for (int j = 0; j < is; j++) {
33407                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33408                                                        int ox;
33409                                                        ox = (int) toLong(Math.toRadians(ix));
33410                                                        oai32data[it.oIndex + j] = ox;
33411                                                }
33412                                        }
33413                                } else {
33414                                        while (it.hasNext()) {
33415                                                for (int j = 0; j < is; j++) {
33416                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33417                                                        int ox;
33418                                                        ox = (int) toLong(Math.toRadians(ix));
33419                                                        oai32data[it.oIndex + j] = ox;
33420                                                }
33421                                        }
33422                                }
33423                        }
33424                        break;
33425                case Dataset.FLOAT32:
33426                        final float[] of32data = ((FloatDataset) result).getData();
33427                        if (it.isOutputDouble()) {
33428                                while (it.hasNext()) {
33429                                        final double ix = it.aDouble;
33430                                        float ox;
33431                                        ox = (float) (Math.toRadians(ix));
33432                                        of32data[it.oIndex] = ox;
33433                                }
33434                        } else {
33435                                while (it.hasNext()) {
33436                                        final long ix = it.aLong;
33437                                        float ox;
33438                                        ox = (float) (Math.toRadians(ix));
33439                                        of32data[it.oIndex] = ox;
33440                                }
33441                        }
33442                        break;
33443                case Dataset.FLOAT64:
33444                        final double[] of64data = ((DoubleDataset) result).getData();
33445                        if (it.isOutputDouble()) {
33446                                while (it.hasNext()) {
33447                                        final double ix = it.aDouble;
33448                                        double ox;
33449                                        ox = (Math.toRadians(ix));
33450                                        of64data[it.oIndex] = ox;
33451                                }
33452                        } else {
33453                                while (it.hasNext()) {
33454                                        final long ix = it.aLong;
33455                                        double ox;
33456                                        ox = (Math.toRadians(ix));
33457                                        of64data[it.oIndex] = ox;
33458                                }
33459                        }
33460                        break;
33461                case Dataset.ARRAYFLOAT32:
33462                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
33463                        if (is == 1) {
33464                                if (it.isOutputDouble()) {
33465                                        while (it.hasNext()) {
33466                                                final double ix = it.aDouble;
33467                                                float ox;
33468                                                ox = (float) (Math.toRadians(ix));
33469                                                oaf32data[it.oIndex] = ox;
33470                                        }
33471                                } else {
33472                                        while (it.hasNext()) {
33473                                                final long ix = it.aLong;
33474                                                float ox;
33475                                                ox = (float) (Math.toRadians(ix));
33476                                                oaf32data[it.oIndex] = ox;
33477                                        }
33478                                }
33479                        } else if (as == 1) {
33480                                if (it.isOutputDouble()) {
33481                                        while (it.hasNext()) {
33482                                                final double ix = it.aDouble;
33483                                                float ox;
33484                                                ox = (float) (Math.toRadians(ix));
33485                                                for (int j = 0; j < is; j++) {
33486                                                        oaf32data[it.oIndex + j] = ox;
33487                                                }
33488                                        }
33489                                } else {
33490                                        while (it.hasNext()) {
33491                                                final long ix = it.aLong;
33492                                                float ox;
33493                                                ox = (float) (Math.toRadians(ix));
33494                                                for (int j = 0; j < is; j++) {
33495                                                        oaf32data[it.oIndex + j] = ox;
33496                                                }
33497                                        }
33498                                }
33499                        } else {
33500                                if (it.isOutputDouble()) {
33501                                        while (it.hasNext()) {
33502                                                for (int j = 0; j < is; j++) {
33503                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33504                                                        float ox;
33505                                                        ox = (float) (Math.toRadians(ix));
33506                                                        oaf32data[it.oIndex + j] = ox;
33507                                                }
33508                                        }
33509                                } else {
33510                                        while (it.hasNext()) {
33511                                                for (int j = 0; j < is; j++) {
33512                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33513                                                        float ox;
33514                                                        ox = (float) (Math.toRadians(ix));
33515                                                        oaf32data[it.oIndex + j] = ox;
33516                                                }
33517                                        }
33518                                }
33519                        }
33520                        break;
33521                case Dataset.ARRAYFLOAT64:
33522                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
33523                        if (is == 1) {
33524                                if (it.isOutputDouble()) {
33525                                        while (it.hasNext()) {
33526                                                final double ix = it.aDouble;
33527                                                double ox;
33528                                                ox = (Math.toRadians(ix));
33529                                                oaf64data[it.oIndex] = ox;
33530                                        }
33531                                } else {
33532                                        while (it.hasNext()) {
33533                                                final long ix = it.aLong;
33534                                                double ox;
33535                                                ox = (Math.toRadians(ix));
33536                                                oaf64data[it.oIndex] = ox;
33537                                        }
33538                                }
33539                        } else if (as == 1) {
33540                                if (it.isOutputDouble()) {
33541                                        while (it.hasNext()) {
33542                                                final double ix = it.aDouble;
33543                                                double ox;
33544                                                ox = (Math.toRadians(ix));
33545                                                for (int j = 0; j < is; j++) {
33546                                                        oaf64data[it.oIndex + j] = ox;
33547                                                }
33548                                        }
33549                                } else {
33550                                        while (it.hasNext()) {
33551                                                final long ix = it.aLong;
33552                                                double ox;
33553                                                ox = (Math.toRadians(ix));
33554                                                for (int j = 0; j < is; j++) {
33555                                                        oaf64data[it.oIndex + j] = ox;
33556                                                }
33557                                        }
33558                                }
33559                        } else {
33560                                if (it.isOutputDouble()) {
33561                                        while (it.hasNext()) {
33562                                                for (int j = 0; j < is; j++) {
33563                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33564                                                        double ox;
33565                                                        ox = (Math.toRadians(ix));
33566                                                        oaf64data[it.oIndex + j] = ox;
33567                                                }
33568                                        }
33569                                } else {
33570                                        while (it.hasNext()) {
33571                                                for (int j = 0; j < is; j++) {
33572                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33573                                                        double ox;
33574                                                        ox = (Math.toRadians(ix));
33575                                                        oaf64data[it.oIndex + j] = ox;
33576                                                }
33577                                        }
33578                                }
33579                        }
33580                        break;
33581                case Dataset.COMPLEX64:
33582                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
33583                        if (!da.isComplex()) {
33584                                if (it.isOutputDouble()) {
33585                                        final double iy = 0;
33586                                        while (it.hasNext()) {
33587                                                final double ix = it.aDouble;
33588                                                float ox;
33589                                                float oy;
33590                                                ox = (float) (Math.toRadians(ix));
33591                                                oy = (float) (Math.toRadians(iy));
33592                                                oc64data[it.oIndex] = ox;
33593                                                oc64data[it.oIndex + 1] = oy;
33594                                        }
33595                                } else {
33596                                        final long iy = 0;
33597                                        while (it.hasNext()) {
33598                                                final long ix = it.aLong;
33599                                                float ox;
33600                                                float oy;
33601                                                ox = (float) toLong(Math.toRadians(ix));
33602                                                oy = (float) toLong(Math.toRadians(iy));
33603                                                oc64data[it.oIndex] = ox;
33604                                                oc64data[it.oIndex + 1] = oy;
33605                                        }
33606                                }
33607                        } else {
33608                                while (it.hasNext()) {
33609                                        final double ix = it.aDouble;
33610                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
33611                                        float ox;
33612                                        float oy;
33613                                        ox = (float) (Math.toRadians(ix));
33614                                        oy = (float) (Math.toRadians(iy));
33615                                        oc64data[it.oIndex] = ox;
33616                                        oc64data[it.oIndex + 1] = oy;
33617                                }
33618                        }
33619                        break;
33620                case Dataset.COMPLEX128:
33621                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
33622                        if (!da.isComplex()) {
33623                                if (it.isOutputDouble()) {
33624                                        final double iy = 0;
33625                                        while (it.hasNext()) {
33626                                                final double ix = it.aDouble;
33627                                                double ox;
33628                                                double oy;
33629                                                ox = (Math.toRadians(ix));
33630                                                oy = (Math.toRadians(iy));
33631                                                oc128data[it.oIndex] = ox;
33632                                                oc128data[it.oIndex + 1] = oy;
33633                                        }
33634                                } else {
33635                                        final long iy = 0;
33636                                        while (it.hasNext()) {
33637                                                final long ix = it.aLong;
33638                                                double ox;
33639                                                double oy;
33640                                                ox = (double) (Math.toRadians(ix));
33641                                                oy = (double) (Math.toRadians(iy));
33642                                                oc128data[it.oIndex] = ox;
33643                                                oc128data[it.oIndex + 1] = oy;
33644                                        }
33645                                }
33646                        } else {
33647                                while (it.hasNext()) {
33648                                        final double ix = it.aDouble;
33649                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
33650                                        double ox;
33651                                        double oy;
33652                                        ox = (Math.toRadians(ix));
33653                                        oy = (Math.toRadians(iy));
33654                                        oc128data[it.oIndex] = ox;
33655                                        oc128data[it.oIndex + 1] = oy;
33656                                }
33657                        }
33658                        break;
33659                default:
33660                        throw new IllegalArgumentException("toRadians supports integer, compound integer, real, compound real, complex datasets only");
33661                }
33662
33663                addFunctionName(result, "toRadians");
33664                return result;
33665        }
33666
33667        /**
33668         * signum - sign of each element
33669         * @param a
33670         * @return dataset
33671         */
33672        public static Dataset signum(final Object a) {
33673                return signum(a, null);
33674        }
33675
33676        /**
33677         * signum - sign of each element
33678         * @param a
33679         * @param o output can be null - in which case, a new dataset is created
33680         * @return dataset
33681         */
33682        public static Dataset signum(final Object a, final Dataset o) {
33683                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
33684                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
33685                final Dataset result = it.getOutput();
33686                if (!result.isComplex()) {
33687                        if (da.isComplex()) {
33688                                da = da.getRealView();
33689                                it = new SingleInputBroadcastIterator(da, result, true);
33690                        }
33691                }
33692                final int is = result.getElementsPerItem();
33693                final int as = da.getElementsPerItem();
33694                final int dt = result.getDType();
33695
33696                switch(dt) {
33697                case Dataset.INT8:
33698                        final byte[] oi8data = ((ByteDataset) result).getData();
33699                        if (it.isOutputDouble()) {
33700                                while (it.hasNext()) {
33701                                        final double ix = it.aDouble;
33702                                        byte ox;
33703                                        ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33704                                        oi8data[it.oIndex] = ox;
33705                                }
33706                        } else {
33707                                while (it.hasNext()) {
33708                                        final long ix = it.aLong;
33709                                        byte ox;
33710                                        ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33711                                        oi8data[it.oIndex] = ox;
33712                                }
33713                        }
33714                        break;
33715                case Dataset.INT16:
33716                        final short[] oi16data = ((ShortDataset) result).getData();
33717                        if (it.isOutputDouble()) {
33718                                while (it.hasNext()) {
33719                                        final double ix = it.aDouble;
33720                                        short ox;
33721                                        ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33722                                        oi16data[it.oIndex] = ox;
33723                                }
33724                        } else {
33725                                while (it.hasNext()) {
33726                                        final long ix = it.aLong;
33727                                        short ox;
33728                                        ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33729                                        oi16data[it.oIndex] = ox;
33730                                }
33731                        }
33732                        break;
33733                case Dataset.INT64:
33734                        final long[] oi64data = ((LongDataset) result).getData();
33735                        if (it.isOutputDouble()) {
33736                                while (it.hasNext()) {
33737                                        final double ix = it.aDouble;
33738                                        long ox;
33739                                        ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33740                                        oi64data[it.oIndex] = ox;
33741                                }
33742                        } else {
33743                                while (it.hasNext()) {
33744                                        final long ix = it.aLong;
33745                                        long ox;
33746                                        ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33747                                        oi64data[it.oIndex] = ox;
33748                                }
33749                        }
33750                        break;
33751                case Dataset.INT32:
33752                        final int[] oi32data = ((IntegerDataset) result).getData();
33753                        if (it.isOutputDouble()) {
33754                                while (it.hasNext()) {
33755                                        final double ix = it.aDouble;
33756                                        int ox;
33757                                        ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33758                                        oi32data[it.oIndex] = ox;
33759                                }
33760                        } else {
33761                                while (it.hasNext()) {
33762                                        final long ix = it.aLong;
33763                                        int ox;
33764                                        ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33765                                        oi32data[it.oIndex] = ox;
33766                                }
33767                        }
33768                        break;
33769                case Dataset.ARRAYINT8:
33770                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
33771                        if (is == 1) {
33772                                if (it.isOutputDouble()) {
33773                                        while (it.hasNext()) {
33774                                                final double ix = it.aDouble;
33775                                                byte ox;
33776                                                ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33777                                                oai8data[it.oIndex] = ox;
33778                                        }
33779                                } else {
33780                                        while (it.hasNext()) {
33781                                                final long ix = it.aLong;
33782                                                byte ox;
33783                                                ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33784                                                oai8data[it.oIndex] = ox;
33785                                        }
33786                                }
33787                        } else if (as == 1) {
33788                                if (it.isOutputDouble()) {
33789                                        while (it.hasNext()) {
33790                                                final double ix = it.aDouble;
33791                                                byte ox;
33792                                                ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33793                                                for (int j = 0; j < is; j++) {
33794                                                        oai8data[it.oIndex + j] = ox;
33795                                                }
33796                                        }
33797                                } else {
33798                                        while (it.hasNext()) {
33799                                                final long ix = it.aLong;
33800                                                byte ox;
33801                                                ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33802                                                for (int j = 0; j < is; j++) {
33803                                                        oai8data[it.oIndex + j] = ox;
33804                                                }
33805                                        }
33806                                }
33807                        } else {
33808                                if (it.isOutputDouble()) {
33809                                        while (it.hasNext()) {
33810                                                for (int j = 0; j < is; j++) {
33811                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33812                                                        byte ox;
33813                                                        ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33814                                                        oai8data[it.oIndex + j] = ox;
33815                                                }
33816                                        }
33817                                } else {
33818                                        while (it.hasNext()) {
33819                                                for (int j = 0; j < is; j++) {
33820                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33821                                                        byte ox;
33822                                                        ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33823                                                        oai8data[it.oIndex + j] = ox;
33824                                                }
33825                                        }
33826                                }
33827                        }
33828                        break;
33829                case Dataset.ARRAYINT16:
33830                        final short[] oai16data = ((CompoundShortDataset) result).getData();
33831                        if (is == 1) {
33832                                if (it.isOutputDouble()) {
33833                                        while (it.hasNext()) {
33834                                                final double ix = it.aDouble;
33835                                                short ox;
33836                                                ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33837                                                oai16data[it.oIndex] = ox;
33838                                        }
33839                                } else {
33840                                        while (it.hasNext()) {
33841                                                final long ix = it.aLong;
33842                                                short ox;
33843                                                ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33844                                                oai16data[it.oIndex] = ox;
33845                                        }
33846                                }
33847                        } else if (as == 1) {
33848                                if (it.isOutputDouble()) {
33849                                        while (it.hasNext()) {
33850                                                final double ix = it.aDouble;
33851                                                short ox;
33852                                                ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33853                                                for (int j = 0; j < is; j++) {
33854                                                        oai16data[it.oIndex + j] = ox;
33855                                                }
33856                                        }
33857                                } else {
33858                                        while (it.hasNext()) {
33859                                                final long ix = it.aLong;
33860                                                short ox;
33861                                                ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33862                                                for (int j = 0; j < is; j++) {
33863                                                        oai16data[it.oIndex + j] = ox;
33864                                                }
33865                                        }
33866                                }
33867                        } else {
33868                                if (it.isOutputDouble()) {
33869                                        while (it.hasNext()) {
33870                                                for (int j = 0; j < is; j++) {
33871                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33872                                                        short ox;
33873                                                        ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33874                                                        oai16data[it.oIndex + j] = ox;
33875                                                }
33876                                        }
33877                                } else {
33878                                        while (it.hasNext()) {
33879                                                for (int j = 0; j < is; j++) {
33880                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33881                                                        short ox;
33882                                                        ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33883                                                        oai16data[it.oIndex + j] = ox;
33884                                                }
33885                                        }
33886                                }
33887                        }
33888                        break;
33889                case Dataset.ARRAYINT64:
33890                        final long[] oai64data = ((CompoundLongDataset) result).getData();
33891                        if (is == 1) {
33892                                if (it.isOutputDouble()) {
33893                                        while (it.hasNext()) {
33894                                                final double ix = it.aDouble;
33895                                                long ox;
33896                                                ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33897                                                oai64data[it.oIndex] = ox;
33898                                        }
33899                                } else {
33900                                        while (it.hasNext()) {
33901                                                final long ix = it.aLong;
33902                                                long ox;
33903                                                ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33904                                                oai64data[it.oIndex] = ox;
33905                                        }
33906                                }
33907                        } else if (as == 1) {
33908                                if (it.isOutputDouble()) {
33909                                        while (it.hasNext()) {
33910                                                final double ix = it.aDouble;
33911                                                long ox;
33912                                                ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33913                                                for (int j = 0; j < is; j++) {
33914                                                        oai64data[it.oIndex + j] = ox;
33915                                                }
33916                                        }
33917                                } else {
33918                                        while (it.hasNext()) {
33919                                                final long ix = it.aLong;
33920                                                long ox;
33921                                                ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33922                                                for (int j = 0; j < is; j++) {
33923                                                        oai64data[it.oIndex + j] = ox;
33924                                                }
33925                                        }
33926                                }
33927                        } else {
33928                                if (it.isOutputDouble()) {
33929                                        while (it.hasNext()) {
33930                                                for (int j = 0; j < is; j++) {
33931                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33932                                                        long ox;
33933                                                        ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33934                                                        oai64data[it.oIndex + j] = ox;
33935                                                }
33936                                        }
33937                                } else {
33938                                        while (it.hasNext()) {
33939                                                for (int j = 0; j < is; j++) {
33940                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33941                                                        long ox;
33942                                                        ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33943                                                        oai64data[it.oIndex + j] = ox;
33944                                                }
33945                                        }
33946                                }
33947                        }
33948                        break;
33949                case Dataset.ARRAYINT32:
33950                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
33951                        if (is == 1) {
33952                                if (it.isOutputDouble()) {
33953                                        while (it.hasNext()) {
33954                                                final double ix = it.aDouble;
33955                                                int ox;
33956                                                ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33957                                                oai32data[it.oIndex] = ox;
33958                                        }
33959                                } else {
33960                                        while (it.hasNext()) {
33961                                                final long ix = it.aLong;
33962                                                int ox;
33963                                                ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33964                                                oai32data[it.oIndex] = ox;
33965                                        }
33966                                }
33967                        } else if (as == 1) {
33968                                if (it.isOutputDouble()) {
33969                                        while (it.hasNext()) {
33970                                                final double ix = it.aDouble;
33971                                                int ox;
33972                                                ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33973                                                for (int j = 0; j < is; j++) {
33974                                                        oai32data[it.oIndex + j] = ox;
33975                                                }
33976                                        }
33977                                } else {
33978                                        while (it.hasNext()) {
33979                                                final long ix = it.aLong;
33980                                                int ox;
33981                                                ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33982                                                for (int j = 0; j < is; j++) {
33983                                                        oai32data[it.oIndex + j] = ox;
33984                                                }
33985                                        }
33986                                }
33987                        } else {
33988                                if (it.isOutputDouble()) {
33989                                        while (it.hasNext()) {
33990                                                for (int j = 0; j < is; j++) {
33991                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33992                                                        int ox;
33993                                                        ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33994                                                        oai32data[it.oIndex + j] = ox;
33995                                                }
33996                                        }
33997                                } else {
33998                                        while (it.hasNext()) {
33999                                                for (int j = 0; j < is; j++) {
34000                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34001                                                        int ox;
34002                                                        ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
34003                                                        oai32data[it.oIndex + j] = ox;
34004                                                }
34005                                        }
34006                                }
34007                        }
34008                        break;
34009                case Dataset.FLOAT32:
34010                        final float[] of32data = ((FloatDataset) result).getData();
34011                        if (it.isOutputDouble()) {
34012                                while (it.hasNext()) {
34013                                        final double ix = it.aDouble;
34014                                        float ox;
34015                                        ox = (float) (Math.signum(ix));
34016                                        of32data[it.oIndex] = ox;
34017                                }
34018                        } else {
34019                                while (it.hasNext()) {
34020                                        final long ix = it.aLong;
34021                                        float ox;
34022                                        ox = (float) (Math.signum(ix));
34023                                        of32data[it.oIndex] = ox;
34024                                }
34025                        }
34026                        break;
34027                case Dataset.FLOAT64:
34028                        final double[] of64data = ((DoubleDataset) result).getData();
34029                        if (it.isOutputDouble()) {
34030                                while (it.hasNext()) {
34031                                        final double ix = it.aDouble;
34032                                        double ox;
34033                                        ox = (Math.signum(ix));
34034                                        of64data[it.oIndex] = ox;
34035                                }
34036                        } else {
34037                                while (it.hasNext()) {
34038                                        final long ix = it.aLong;
34039                                        double ox;
34040                                        ox = (Math.signum(ix));
34041                                        of64data[it.oIndex] = ox;
34042                                }
34043                        }
34044                        break;
34045                case Dataset.ARRAYFLOAT32:
34046                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
34047                        if (is == 1) {
34048                                if (it.isOutputDouble()) {
34049                                        while (it.hasNext()) {
34050                                                final double ix = it.aDouble;
34051                                                float ox;
34052                                                ox = (float) (Math.signum(ix));
34053                                                oaf32data[it.oIndex] = ox;
34054                                        }
34055                                } else {
34056                                        while (it.hasNext()) {
34057                                                final long ix = it.aLong;
34058                                                float ox;
34059                                                ox = (float) (Math.signum(ix));
34060                                                oaf32data[it.oIndex] = ox;
34061                                        }
34062                                }
34063                        } else if (as == 1) {
34064                                if (it.isOutputDouble()) {
34065                                        while (it.hasNext()) {
34066                                                final double ix = it.aDouble;
34067                                                float ox;
34068                                                ox = (float) (Math.signum(ix));
34069                                                for (int j = 0; j < is; j++) {
34070                                                        oaf32data[it.oIndex + j] = ox;
34071                                                }
34072                                        }
34073                                } else {
34074                                        while (it.hasNext()) {
34075                                                final long ix = it.aLong;
34076                                                float ox;
34077                                                ox = (float) (Math.signum(ix));
34078                                                for (int j = 0; j < is; j++) {
34079                                                        oaf32data[it.oIndex + j] = ox;
34080                                                }
34081                                        }
34082                                }
34083                        } else {
34084                                if (it.isOutputDouble()) {
34085                                        while (it.hasNext()) {
34086                                                for (int j = 0; j < is; j++) {
34087                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34088                                                        float ox;
34089                                                        ox = (float) (Math.signum(ix));
34090                                                        oaf32data[it.oIndex + j] = ox;
34091                                                }
34092                                        }
34093                                } else {
34094                                        while (it.hasNext()) {
34095                                                for (int j = 0; j < is; j++) {
34096                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34097                                                        float ox;
34098                                                        ox = (float) (Math.signum(ix));
34099                                                        oaf32data[it.oIndex + j] = ox;
34100                                                }
34101                                        }
34102                                }
34103                        }
34104                        break;
34105                case Dataset.ARRAYFLOAT64:
34106                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
34107                        if (is == 1) {
34108                                if (it.isOutputDouble()) {
34109                                        while (it.hasNext()) {
34110                                                final double ix = it.aDouble;
34111                                                double ox;
34112                                                ox = (Math.signum(ix));
34113                                                oaf64data[it.oIndex] = ox;
34114                                        }
34115                                } else {
34116                                        while (it.hasNext()) {
34117                                                final long ix = it.aLong;
34118                                                double ox;
34119                                                ox = (Math.signum(ix));
34120                                                oaf64data[it.oIndex] = ox;
34121                                        }
34122                                }
34123                        } else if (as == 1) {
34124                                if (it.isOutputDouble()) {
34125                                        while (it.hasNext()) {
34126                                                final double ix = it.aDouble;
34127                                                double ox;
34128                                                ox = (Math.signum(ix));
34129                                                for (int j = 0; j < is; j++) {
34130                                                        oaf64data[it.oIndex + j] = ox;
34131                                                }
34132                                        }
34133                                } else {
34134                                        while (it.hasNext()) {
34135                                                final long ix = it.aLong;
34136                                                double ox;
34137                                                ox = (Math.signum(ix));
34138                                                for (int j = 0; j < is; j++) {
34139                                                        oaf64data[it.oIndex + j] = ox;
34140                                                }
34141                                        }
34142                                }
34143                        } else {
34144                                if (it.isOutputDouble()) {
34145                                        while (it.hasNext()) {
34146                                                for (int j = 0; j < is; j++) {
34147                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34148                                                        double ox;
34149                                                        ox = (Math.signum(ix));
34150                                                        oaf64data[it.oIndex + j] = ox;
34151                                                }
34152                                        }
34153                                } else {
34154                                        while (it.hasNext()) {
34155                                                for (int j = 0; j < is; j++) {
34156                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34157                                                        double ox;
34158                                                        ox = (Math.signum(ix));
34159                                                        oaf64data[it.oIndex + j] = ox;
34160                                                }
34161                                        }
34162                                }
34163                        }
34164                        break;
34165                case Dataset.COMPLEX64:
34166                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
34167                        if (!da.isComplex()) {
34168                                if (it.isOutputDouble()) {
34169                                        final double iy = 0;
34170                                        while (it.hasNext()) {
34171                                                final double ix = it.aDouble;
34172                                                float ox;
34173                                                float oy;
34174                                                ox = (float) (Math.signum(ix));
34175                                                oy = (float) (Math.signum(iy));
34176                                                oc64data[it.oIndex] = ox;
34177                                                oc64data[it.oIndex + 1] = oy;
34178                                        }
34179                                } else {
34180                                        final long iy = 0;
34181                                        while (it.hasNext()) {
34182                                                final long ix = it.aLong;
34183                                                float ox;
34184                                                float oy;
34185                                                ox = (float) toLong(Math.signum(ix));
34186                                                oy = (float) toLong(Math.signum(iy));
34187                                                oc64data[it.oIndex] = ox;
34188                                                oc64data[it.oIndex + 1] = oy;
34189                                        }
34190                                }
34191                        } else {
34192                                while (it.hasNext()) {
34193                                        final double ix = it.aDouble;
34194                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
34195                                        float ox;
34196                                        float oy;
34197                                        ox = (float) (Math.signum(ix));
34198                                        oy = (float) (Math.signum(iy));
34199                                        oc64data[it.oIndex] = ox;
34200                                        oc64data[it.oIndex + 1] = oy;
34201                                }
34202                        }
34203                        break;
34204                case Dataset.COMPLEX128:
34205                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
34206                        if (!da.isComplex()) {
34207                                if (it.isOutputDouble()) {
34208                                        final double iy = 0;
34209                                        while (it.hasNext()) {
34210                                                final double ix = it.aDouble;
34211                                                double ox;
34212                                                double oy;
34213                                                ox = (Math.signum(ix));
34214                                                oy = (Math.signum(iy));
34215                                                oc128data[it.oIndex] = ox;
34216                                                oc128data[it.oIndex + 1] = oy;
34217                                        }
34218                                } else {
34219                                        final long iy = 0;
34220                                        while (it.hasNext()) {
34221                                                final long ix = it.aLong;
34222                                                double ox;
34223                                                double oy;
34224                                                ox = (double) (Math.signum(ix));
34225                                                oy = (double) (Math.signum(iy));
34226                                                oc128data[it.oIndex] = ox;
34227                                                oc128data[it.oIndex + 1] = oy;
34228                                        }
34229                                }
34230                        } else {
34231                                while (it.hasNext()) {
34232                                        final double ix = it.aDouble;
34233                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
34234                                        double ox;
34235                                        double oy;
34236                                        ox = (Math.signum(ix));
34237                                        oy = (Math.signum(iy));
34238                                        oc128data[it.oIndex] = ox;
34239                                        oc128data[it.oIndex + 1] = oy;
34240                                }
34241                        }
34242                        break;
34243                default:
34244                        throw new IllegalArgumentException("signum supports integer, compound integer, real, compound real, complex datasets only");
34245                }
34246
34247                addFunctionName(result, "signum");
34248                return result;
34249        }
34250
34251        /**
34252         * negative - negative value of each element
34253         * @param a
34254         * @return dataset
34255         */
34256        public static Dataset negative(final Object a) {
34257                return negative(a, null);
34258        }
34259
34260        /**
34261         * negative - negative value of each element
34262         * @param a
34263         * @param o output can be null - in which case, a new dataset is created
34264         * @return dataset
34265         */
34266        public static Dataset negative(final Object a, final Dataset o) {
34267                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
34268                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
34269                final Dataset result = it.getOutput();
34270                if (!result.isComplex()) {
34271                        if (da.isComplex()) {
34272                                da = da.getRealView();
34273                                it = new SingleInputBroadcastIterator(da, result, true);
34274                        }
34275                }
34276                final int is = result.getElementsPerItem();
34277                final int as = da.getElementsPerItem();
34278                final int dt = result.getDType();
34279
34280                switch(dt) {
34281                case Dataset.INT8:
34282                        final byte[] oi8data = ((ByteDataset) result).getData();
34283                        if (it.isOutputDouble()) {
34284                                while (it.hasNext()) {
34285                                        final double ix = it.aDouble;
34286                                        byte ox;
34287                                        ox = (byte) toLong(-ix);
34288                                        oi8data[it.oIndex] = ox;
34289                                }
34290                        } else {
34291                                while (it.hasNext()) {
34292                                        final long ix = it.aLong;
34293                                        byte ox;
34294                                        ox = (byte) toLong(-ix);
34295                                        oi8data[it.oIndex] = ox;
34296                                }
34297                        }
34298                        break;
34299                case Dataset.INT16:
34300                        final short[] oi16data = ((ShortDataset) result).getData();
34301                        if (it.isOutputDouble()) {
34302                                while (it.hasNext()) {
34303                                        final double ix = it.aDouble;
34304                                        short ox;
34305                                        ox = (short) toLong(-ix);
34306                                        oi16data[it.oIndex] = ox;
34307                                }
34308                        } else {
34309                                while (it.hasNext()) {
34310                                        final long ix = it.aLong;
34311                                        short ox;
34312                                        ox = (short) toLong(-ix);
34313                                        oi16data[it.oIndex] = ox;
34314                                }
34315                        }
34316                        break;
34317                case Dataset.INT64:
34318                        final long[] oi64data = ((LongDataset) result).getData();
34319                        if (it.isOutputDouble()) {
34320                                while (it.hasNext()) {
34321                                        final double ix = it.aDouble;
34322                                        long ox;
34323                                        ox = toLong(-ix);
34324                                        oi64data[it.oIndex] = ox;
34325                                }
34326                        } else {
34327                                while (it.hasNext()) {
34328                                        final long ix = it.aLong;
34329                                        long ox;
34330                                        ox = toLong(-ix);
34331                                        oi64data[it.oIndex] = ox;
34332                                }
34333                        }
34334                        break;
34335                case Dataset.INT32:
34336                        final int[] oi32data = ((IntegerDataset) result).getData();
34337                        if (it.isOutputDouble()) {
34338                                while (it.hasNext()) {
34339                                        final double ix = it.aDouble;
34340                                        int ox;
34341                                        ox = (int) toLong(-ix);
34342                                        oi32data[it.oIndex] = ox;
34343                                }
34344                        } else {
34345                                while (it.hasNext()) {
34346                                        final long ix = it.aLong;
34347                                        int ox;
34348                                        ox = (int) toLong(-ix);
34349                                        oi32data[it.oIndex] = ox;
34350                                }
34351                        }
34352                        break;
34353                case Dataset.ARRAYINT8:
34354                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
34355                        if (is == 1) {
34356                                if (it.isOutputDouble()) {
34357                                        while (it.hasNext()) {
34358                                                final double ix = it.aDouble;
34359                                                byte ox;
34360                                                ox = (byte) toLong(-ix);
34361                                                oai8data[it.oIndex] = ox;
34362                                        }
34363                                } else {
34364                                        while (it.hasNext()) {
34365                                                final long ix = it.aLong;
34366                                                byte ox;
34367                                                ox = (byte) toLong(-ix);
34368                                                oai8data[it.oIndex] = ox;
34369                                        }
34370                                }
34371                        } else if (as == 1) {
34372                                if (it.isOutputDouble()) {
34373                                        while (it.hasNext()) {
34374                                                final double ix = it.aDouble;
34375                                                byte ox;
34376                                                ox = (byte) toLong(-ix);
34377                                                for (int j = 0; j < is; j++) {
34378                                                        oai8data[it.oIndex + j] = ox;
34379                                                }
34380                                        }
34381                                } else {
34382                                        while (it.hasNext()) {
34383                                                final long ix = it.aLong;
34384                                                byte ox;
34385                                                ox = (byte) toLong(-ix);
34386                                                for (int j = 0; j < is; j++) {
34387                                                        oai8data[it.oIndex + j] = ox;
34388                                                }
34389                                        }
34390                                }
34391                        } else {
34392                                if (it.isOutputDouble()) {
34393                                        while (it.hasNext()) {
34394                                                for (int j = 0; j < is; j++) {
34395                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34396                                                        byte ox;
34397                                                        ox = (byte) toLong(-ix);
34398                                                        oai8data[it.oIndex + j] = ox;
34399                                                }
34400                                        }
34401                                } else {
34402                                        while (it.hasNext()) {
34403                                                for (int j = 0; j < is; j++) {
34404                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34405                                                        byte ox;
34406                                                        ox = (byte) toLong(-ix);
34407                                                        oai8data[it.oIndex + j] = ox;
34408                                                }
34409                                        }
34410                                }
34411                        }
34412                        break;
34413                case Dataset.ARRAYINT16:
34414                        final short[] oai16data = ((CompoundShortDataset) result).getData();
34415                        if (is == 1) {
34416                                if (it.isOutputDouble()) {
34417                                        while (it.hasNext()) {
34418                                                final double ix = it.aDouble;
34419                                                short ox;
34420                                                ox = (short) toLong(-ix);
34421                                                oai16data[it.oIndex] = ox;
34422                                        }
34423                                } else {
34424                                        while (it.hasNext()) {
34425                                                final long ix = it.aLong;
34426                                                short ox;
34427                                                ox = (short) toLong(-ix);
34428                                                oai16data[it.oIndex] = ox;
34429                                        }
34430                                }
34431                        } else if (as == 1) {
34432                                if (it.isOutputDouble()) {
34433                                        while (it.hasNext()) {
34434                                                final double ix = it.aDouble;
34435                                                short ox;
34436                                                ox = (short) toLong(-ix);
34437                                                for (int j = 0; j < is; j++) {
34438                                                        oai16data[it.oIndex + j] = ox;
34439                                                }
34440                                        }
34441                                } else {
34442                                        while (it.hasNext()) {
34443                                                final long ix = it.aLong;
34444                                                short ox;
34445                                                ox = (short) toLong(-ix);
34446                                                for (int j = 0; j < is; j++) {
34447                                                        oai16data[it.oIndex + j] = ox;
34448                                                }
34449                                        }
34450                                }
34451                        } else {
34452                                if (it.isOutputDouble()) {
34453                                        while (it.hasNext()) {
34454                                                for (int j = 0; j < is; j++) {
34455                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34456                                                        short ox;
34457                                                        ox = (short) toLong(-ix);
34458                                                        oai16data[it.oIndex + j] = ox;
34459                                                }
34460                                        }
34461                                } else {
34462                                        while (it.hasNext()) {
34463                                                for (int j = 0; j < is; j++) {
34464                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34465                                                        short ox;
34466                                                        ox = (short) toLong(-ix);
34467                                                        oai16data[it.oIndex + j] = ox;
34468                                                }
34469                                        }
34470                                }
34471                        }
34472                        break;
34473                case Dataset.ARRAYINT64:
34474                        final long[] oai64data = ((CompoundLongDataset) result).getData();
34475                        if (is == 1) {
34476                                if (it.isOutputDouble()) {
34477                                        while (it.hasNext()) {
34478                                                final double ix = it.aDouble;
34479                                                long ox;
34480                                                ox = toLong(-ix);
34481                                                oai64data[it.oIndex] = ox;
34482                                        }
34483                                } else {
34484                                        while (it.hasNext()) {
34485                                                final long ix = it.aLong;
34486                                                long ox;
34487                                                ox = toLong(-ix);
34488                                                oai64data[it.oIndex] = ox;
34489                                        }
34490                                }
34491                        } else if (as == 1) {
34492                                if (it.isOutputDouble()) {
34493                                        while (it.hasNext()) {
34494                                                final double ix = it.aDouble;
34495                                                long ox;
34496                                                ox = toLong(-ix);
34497                                                for (int j = 0; j < is; j++) {
34498                                                        oai64data[it.oIndex + j] = ox;
34499                                                }
34500                                        }
34501                                } else {
34502                                        while (it.hasNext()) {
34503                                                final long ix = it.aLong;
34504                                                long ox;
34505                                                ox = toLong(-ix);
34506                                                for (int j = 0; j < is; j++) {
34507                                                        oai64data[it.oIndex + j] = ox;
34508                                                }
34509                                        }
34510                                }
34511                        } else {
34512                                if (it.isOutputDouble()) {
34513                                        while (it.hasNext()) {
34514                                                for (int j = 0; j < is; j++) {
34515                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34516                                                        long ox;
34517                                                        ox = toLong(-ix);
34518                                                        oai64data[it.oIndex + j] = ox;
34519                                                }
34520                                        }
34521                                } else {
34522                                        while (it.hasNext()) {
34523                                                for (int j = 0; j < is; j++) {
34524                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34525                                                        long ox;
34526                                                        ox = toLong(-ix);
34527                                                        oai64data[it.oIndex + j] = ox;
34528                                                }
34529                                        }
34530                                }
34531                        }
34532                        break;
34533                case Dataset.ARRAYINT32:
34534                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
34535                        if (is == 1) {
34536                                if (it.isOutputDouble()) {
34537                                        while (it.hasNext()) {
34538                                                final double ix = it.aDouble;
34539                                                int ox;
34540                                                ox = (int) toLong(-ix);
34541                                                oai32data[it.oIndex] = ox;
34542                                        }
34543                                } else {
34544                                        while (it.hasNext()) {
34545                                                final long ix = it.aLong;
34546                                                int ox;
34547                                                ox = (int) toLong(-ix);
34548                                                oai32data[it.oIndex] = ox;
34549                                        }
34550                                }
34551                        } else if (as == 1) {
34552                                if (it.isOutputDouble()) {
34553                                        while (it.hasNext()) {
34554                                                final double ix = it.aDouble;
34555                                                int ox;
34556                                                ox = (int) toLong(-ix);
34557                                                for (int j = 0; j < is; j++) {
34558                                                        oai32data[it.oIndex + j] = ox;
34559                                                }
34560                                        }
34561                                } else {
34562                                        while (it.hasNext()) {
34563                                                final long ix = it.aLong;
34564                                                int ox;
34565                                                ox = (int) toLong(-ix);
34566                                                for (int j = 0; j < is; j++) {
34567                                                        oai32data[it.oIndex + j] = ox;
34568                                                }
34569                                        }
34570                                }
34571                        } else {
34572                                if (it.isOutputDouble()) {
34573                                        while (it.hasNext()) {
34574                                                for (int j = 0; j < is; j++) {
34575                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34576                                                        int ox;
34577                                                        ox = (int) toLong(-ix);
34578                                                        oai32data[it.oIndex + j] = ox;
34579                                                }
34580                                        }
34581                                } else {
34582                                        while (it.hasNext()) {
34583                                                for (int j = 0; j < is; j++) {
34584                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34585                                                        int ox;
34586                                                        ox = (int) toLong(-ix);
34587                                                        oai32data[it.oIndex + j] = ox;
34588                                                }
34589                                        }
34590                                }
34591                        }
34592                        break;
34593                case Dataset.FLOAT32:
34594                        final float[] of32data = ((FloatDataset) result).getData();
34595                        if (it.isOutputDouble()) {
34596                                while (it.hasNext()) {
34597                                        final double ix = it.aDouble;
34598                                        float ox;
34599                                        ox = (float) (-ix);
34600                                        of32data[it.oIndex] = ox;
34601                                }
34602                        } else {
34603                                while (it.hasNext()) {
34604                                        final long ix = it.aLong;
34605                                        float ox;
34606                                        ox = (-ix);
34607                                        of32data[it.oIndex] = ox;
34608                                }
34609                        }
34610                        break;
34611                case Dataset.FLOAT64:
34612                        final double[] of64data = ((DoubleDataset) result).getData();
34613                        if (it.isOutputDouble()) {
34614                                while (it.hasNext()) {
34615                                        final double ix = it.aDouble;
34616                                        double ox;
34617                                        ox = (-ix);
34618                                        of64data[it.oIndex] = ox;
34619                                }
34620                        } else {
34621                                while (it.hasNext()) {
34622                                        final long ix = it.aLong;
34623                                        double ox;
34624                                        ox = (-ix);
34625                                        of64data[it.oIndex] = ox;
34626                                }
34627                        }
34628                        break;
34629                case Dataset.ARRAYFLOAT32:
34630                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
34631                        if (is == 1) {
34632                                if (it.isOutputDouble()) {
34633                                        while (it.hasNext()) {
34634                                                final double ix = it.aDouble;
34635                                                float ox;
34636                                                ox = (float) (-ix);
34637                                                oaf32data[it.oIndex] = ox;
34638                                        }
34639                                } else {
34640                                        while (it.hasNext()) {
34641                                                final long ix = it.aLong;
34642                                                float ox;
34643                                                ox = (-ix);
34644                                                oaf32data[it.oIndex] = ox;
34645                                        }
34646                                }
34647                        } else if (as == 1) {
34648                                if (it.isOutputDouble()) {
34649                                        while (it.hasNext()) {
34650                                                final double ix = it.aDouble;
34651                                                float ox;
34652                                                ox = (float) (-ix);
34653                                                for (int j = 0; j < is; j++) {
34654                                                        oaf32data[it.oIndex + j] = ox;
34655                                                }
34656                                        }
34657                                } else {
34658                                        while (it.hasNext()) {
34659                                                final long ix = it.aLong;
34660                                                float ox;
34661                                                ox = (-ix);
34662                                                for (int j = 0; j < is; j++) {
34663                                                        oaf32data[it.oIndex + j] = ox;
34664                                                }
34665                                        }
34666                                }
34667                        } else {
34668                                if (it.isOutputDouble()) {
34669                                        while (it.hasNext()) {
34670                                                for (int j = 0; j < is; j++) {
34671                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34672                                                        float ox;
34673                                                        ox = (float) (-ix);
34674                                                        oaf32data[it.oIndex + j] = ox;
34675                                                }
34676                                        }
34677                                } else {
34678                                        while (it.hasNext()) {
34679                                                for (int j = 0; j < is; j++) {
34680                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34681                                                        float ox;
34682                                                        ox = (-ix);
34683                                                        oaf32data[it.oIndex + j] = ox;
34684                                                }
34685                                        }
34686                                }
34687                        }
34688                        break;
34689                case Dataset.ARRAYFLOAT64:
34690                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
34691                        if (is == 1) {
34692                                if (it.isOutputDouble()) {
34693                                        while (it.hasNext()) {
34694                                                final double ix = it.aDouble;
34695                                                double ox;
34696                                                ox = (-ix);
34697                                                oaf64data[it.oIndex] = ox;
34698                                        }
34699                                } else {
34700                                        while (it.hasNext()) {
34701                                                final long ix = it.aLong;
34702                                                double ox;
34703                                                ox = (-ix);
34704                                                oaf64data[it.oIndex] = ox;
34705                                        }
34706                                }
34707                        } else if (as == 1) {
34708                                if (it.isOutputDouble()) {
34709                                        while (it.hasNext()) {
34710                                                final double ix = it.aDouble;
34711                                                double ox;
34712                                                ox = (-ix);
34713                                                for (int j = 0; j < is; j++) {
34714                                                        oaf64data[it.oIndex + j] = ox;
34715                                                }
34716                                        }
34717                                } else {
34718                                        while (it.hasNext()) {
34719                                                final long ix = it.aLong;
34720                                                double ox;
34721                                                ox = (-ix);
34722                                                for (int j = 0; j < is; j++) {
34723                                                        oaf64data[it.oIndex + j] = ox;
34724                                                }
34725                                        }
34726                                }
34727                        } else {
34728                                if (it.isOutputDouble()) {
34729                                        while (it.hasNext()) {
34730                                                for (int j = 0; j < is; j++) {
34731                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34732                                                        double ox;
34733                                                        ox = (-ix);
34734                                                        oaf64data[it.oIndex + j] = ox;
34735                                                }
34736                                        }
34737                                } else {
34738                                        while (it.hasNext()) {
34739                                                for (int j = 0; j < is; j++) {
34740                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34741                                                        double ox;
34742                                                        ox = (-ix);
34743                                                        oaf64data[it.oIndex + j] = ox;
34744                                                }
34745                                        }
34746                                }
34747                        }
34748                        break;
34749                case Dataset.COMPLEX64:
34750                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
34751                        if (!da.isComplex()) {
34752                                if (it.isOutputDouble()) {
34753                                        final double iy = 0;
34754                                        while (it.hasNext()) {
34755                                                final double ix = it.aDouble;
34756                                                float ox;
34757                                                float oy;
34758                                                ox = (float) (-ix);
34759                                                oy = (float) (-iy);
34760                                                oc64data[it.oIndex] = ox;
34761                                                oc64data[it.oIndex + 1] = oy;
34762                                        }
34763                                } else {
34764                                        final long iy = 0;
34765                                        while (it.hasNext()) {
34766                                                final long ix = it.aLong;
34767                                                float ox;
34768                                                float oy;
34769                                                ox = (float) toLong(-ix);
34770                                                oy = (float) toLong(-iy);
34771                                                oc64data[it.oIndex] = ox;
34772                                                oc64data[it.oIndex + 1] = oy;
34773                                        }
34774                                }
34775                        } else {
34776                                while (it.hasNext()) {
34777                                        final double ix = it.aDouble;
34778                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
34779                                        float ox;
34780                                        float oy;
34781                                        ox = (float) (-ix);
34782                                        oy = (float) (-iy);
34783                                        oc64data[it.oIndex] = ox;
34784                                        oc64data[it.oIndex + 1] = oy;
34785                                }
34786                        }
34787                        break;
34788                case Dataset.COMPLEX128:
34789                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
34790                        if (!da.isComplex()) {
34791                                if (it.isOutputDouble()) {
34792                                        final double iy = 0;
34793                                        while (it.hasNext()) {
34794                                                final double ix = it.aDouble;
34795                                                double ox;
34796                                                double oy;
34797                                                ox = (-ix);
34798                                                oy = (-iy);
34799                                                oc128data[it.oIndex] = ox;
34800                                                oc128data[it.oIndex + 1] = oy;
34801                                        }
34802                                } else {
34803                                        final long iy = 0;
34804                                        while (it.hasNext()) {
34805                                                final long ix = it.aLong;
34806                                                double ox;
34807                                                double oy;
34808                                                ox = (-ix);
34809                                                oy = (-iy);
34810                                                oc128data[it.oIndex] = ox;
34811                                                oc128data[it.oIndex + 1] = oy;
34812                                        }
34813                                }
34814                        } else {
34815                                while (it.hasNext()) {
34816                                        final double ix = it.aDouble;
34817                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
34818                                        double ox;
34819                                        double oy;
34820                                        ox = (-ix);
34821                                        oy = (-iy);
34822                                        oc128data[it.oIndex] = ox;
34823                                        oc128data[it.oIndex + 1] = oy;
34824                                }
34825                        }
34826                        break;
34827                default:
34828                        throw new IllegalArgumentException("negative supports integer, compound integer, real, compound real, complex datasets only");
34829                }
34830
34831                addFunctionName(result, "negative");
34832                return result;
34833        }
34834
34835        /**
34836         * lowerClip - clip elements to lower limit
34837         * @param a
34838         * @param pa
34839         * @return dataset
34840         * @since 2.3
34841         */
34842        public static Dataset lowerClip(final Object a, final Object pa) {
34843                return lowerClip(a, null, pa);
34844        }
34845
34846        /**
34847         * lowerClip - clip elements to lower limit
34848         * @param a
34849         * @param o output can be null - in which case, a new dataset is created
34850         * @param pa
34851         * @return dataset
34852         * @since 2.3
34853         */
34854        public static Dataset lowerClip(final Object a, final Dataset o, final Object pa) {
34855                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
34856                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
34857                final Dataset result = it.getOutput();
34858                if (!result.isComplex()) {
34859                        if (da.isComplex()) {
34860                                da = da.getRealView();
34861                                it = new SingleInputBroadcastIterator(da, result, true);
34862                        }
34863                }
34864                final int is = result.getElementsPerItem();
34865                final int as = da.getElementsPerItem();
34866                final int dt = result.getDType();
34867                final double pax = DTypeUtils.toReal(pa);
34868
34869                switch(dt) {
34870                case Dataset.INT8:
34871                        final byte[] oi8data = ((ByteDataset) result).getData();
34872                        if (it.isOutputDouble()) {
34873                                while (it.hasNext()) {
34874                                        final double ix = it.aDouble;
34875                                        byte ox;
34876                                        if (ix < pax)
34877                                        ox = (byte) toLong(pax);
34878                                        else
34879                                        ox = (byte) toLong(ix);
34880                                        oi8data[it.oIndex] = ox;
34881                                }
34882                        } else {
34883                                while (it.hasNext()) {
34884                                        final long ix = it.aLong;
34885                                        byte ox;
34886                                        if (ix < pax)
34887                                        ox = (byte) toLong(pax);
34888                                        else
34889                                        ox = (byte) toLong(ix);
34890                                        oi8data[it.oIndex] = ox;
34891                                }
34892                        }
34893                        break;
34894                case Dataset.INT16:
34895                        final short[] oi16data = ((ShortDataset) result).getData();
34896                        if (it.isOutputDouble()) {
34897                                while (it.hasNext()) {
34898                                        final double ix = it.aDouble;
34899                                        short ox;
34900                                        if (ix < pax)
34901                                        ox = (short) toLong(pax);
34902                                        else
34903                                        ox = (short) toLong(ix);
34904                                        oi16data[it.oIndex] = ox;
34905                                }
34906                        } else {
34907                                while (it.hasNext()) {
34908                                        final long ix = it.aLong;
34909                                        short ox;
34910                                        if (ix < pax)
34911                                        ox = (short) toLong(pax);
34912                                        else
34913                                        ox = (short) toLong(ix);
34914                                        oi16data[it.oIndex] = ox;
34915                                }
34916                        }
34917                        break;
34918                case Dataset.INT64:
34919                        final long[] oi64data = ((LongDataset) result).getData();
34920                        if (it.isOutputDouble()) {
34921                                while (it.hasNext()) {
34922                                        final double ix = it.aDouble;
34923                                        long ox;
34924                                        if (ix < pax)
34925                                        ox = toLong(pax);
34926                                        else
34927                                        ox = toLong(ix);
34928                                        oi64data[it.oIndex] = ox;
34929                                }
34930                        } else {
34931                                while (it.hasNext()) {
34932                                        final long ix = it.aLong;
34933                                        long ox;
34934                                        if (ix < pax)
34935                                        ox = toLong(pax);
34936                                        else
34937                                        ox = toLong(ix);
34938                                        oi64data[it.oIndex] = ox;
34939                                }
34940                        }
34941                        break;
34942                case Dataset.INT32:
34943                        final int[] oi32data = ((IntegerDataset) result).getData();
34944                        if (it.isOutputDouble()) {
34945                                while (it.hasNext()) {
34946                                        final double ix = it.aDouble;
34947                                        int ox;
34948                                        if (ix < pax)
34949                                        ox = (int) toLong(pax);
34950                                        else
34951                                        ox = (int) toLong(ix);
34952                                        oi32data[it.oIndex] = ox;
34953                                }
34954                        } else {
34955                                while (it.hasNext()) {
34956                                        final long ix = it.aLong;
34957                                        int ox;
34958                                        if (ix < pax)
34959                                        ox = (int) toLong(pax);
34960                                        else
34961                                        ox = (int) toLong(ix);
34962                                        oi32data[it.oIndex] = ox;
34963                                }
34964                        }
34965                        break;
34966                case Dataset.ARRAYINT8:
34967                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
34968                        if (is == 1) {
34969                                if (it.isOutputDouble()) {
34970                                        while (it.hasNext()) {
34971                                                final double ix = it.aDouble;
34972                                                byte ox;
34973                                                if (ix < pax)
34974                                                ox = (byte) toLong(pax);
34975                                                else
34976                                                ox = (byte) toLong(ix);
34977                                                oai8data[it.oIndex] = ox;
34978                                        }
34979                                } else {
34980                                        while (it.hasNext()) {
34981                                                final long ix = it.aLong;
34982                                                byte ox;
34983                                                if (ix < pax)
34984                                                ox = (byte) toLong(pax);
34985                                                else
34986                                                ox = (byte) toLong(ix);
34987                                                oai8data[it.oIndex] = ox;
34988                                        }
34989                                }
34990                        } else if (as == 1) {
34991                                if (it.isOutputDouble()) {
34992                                        while (it.hasNext()) {
34993                                                final double ix = it.aDouble;
34994                                                byte ox;
34995                                                if (ix < pax)
34996                                                ox = (byte) toLong(pax);
34997                                                else
34998                                                ox = (byte) toLong(ix);
34999                                                for (int j = 0; j < is; j++) {
35000                                                        oai8data[it.oIndex + j] = ox;
35001                                                }
35002                                        }
35003                                } else {
35004                                        while (it.hasNext()) {
35005                                                final long ix = it.aLong;
35006                                                byte ox;
35007                                                if (ix < pax)
35008                                                ox = (byte) toLong(pax);
35009                                                else
35010                                                ox = (byte) toLong(ix);
35011                                                for (int j = 0; j < is; j++) {
35012                                                        oai8data[it.oIndex + j] = ox;
35013                                                }
35014                                        }
35015                                }
35016                        } else {
35017                                if (it.isOutputDouble()) {
35018                                        while (it.hasNext()) {
35019                                                for (int j = 0; j < is; j++) {
35020                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
35021                                                        byte ox;
35022                                                        if (ix < pax)
35023                                                        ox = (byte) toLong(pax);
35024                                                        else
35025                                                        ox = (byte) toLong(ix);
35026                                                        oai8data[it.oIndex + j] = ox;
35027                                                }
35028                                        }
35029                                } else {
35030                                        while (it.hasNext()) {
35031                                                for (int j = 0; j < is; j++) {
35032                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
35033                                                        byte ox;
35034                                                        if (ix < pax)
35035                                                        ox = (byte) toLong(pax);
35036                                                        else
35037                                                        ox = (byte) toLong(ix);
35038                                                        oai8data[it.oIndex + j] = ox;
35039                                                }
35040                                        }
35041                                }
35042                        }
35043                        break;
35044                case Dataset.ARRAYINT16:
35045                        final short[] oai16data = ((CompoundShortDataset) result).getData();
35046                        if (is == 1) {
35047                                if (it.isOutputDouble()) {
35048                                        while (it.hasNext()) {
35049                                                final double ix = it.aDouble;
35050                                                short ox;
35051                                                if (ix < pax)
35052                                                ox = (short) toLong(pax);
35053                                                else
35054                                                ox = (short) toLong(ix);
35055                                                oai16data[it.oIndex] = ox;
35056                                        }
35057                                } else {
35058                                        while (it.hasNext()) {
35059                                                final long ix = it.aLong;
35060                                                short ox;
35061                                                if (ix < pax)
35062                                                ox = (short) toLong(pax);
35063                                                else
35064                                                ox = (short) toLong(ix);
35065                                                oai16data[it.oIndex] = ox;
35066                                        }
35067                                }
35068                        } else if (as == 1) {
35069                                if (it.isOutputDouble()) {
35070                                        while (it.hasNext()) {
35071                                                final double ix = it.aDouble;
35072                                                short ox;
35073                                                if (ix < pax)
35074                                                ox = (short) toLong(pax);
35075                                                else
35076                                                ox = (short) toLong(ix);
35077                                                for (int j = 0; j < is; j++) {
35078                                                        oai16data[it.oIndex + j] = ox;
35079                                                }
35080                                        }
35081                                } else {
35082                                        while (it.hasNext()) {
35083                                                final long ix = it.aLong;
35084                                                short ox;
35085                                                if (ix < pax)
35086                                                ox = (short) toLong(pax);
35087                                                else
35088                                                ox = (short) toLong(ix);
35089                                                for (int j = 0; j < is; j++) {
35090                                                        oai16data[it.oIndex + j] = ox;
35091                                                }
35092                                        }
35093                                }
35094                        } else {
35095                                if (it.isOutputDouble()) {
35096                                        while (it.hasNext()) {
35097                                                for (int j = 0; j < is; j++) {
35098                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
35099                                                        short ox;
35100                                                        if (ix < pax)
35101                                                        ox = (short) toLong(pax);
35102                                                        else
35103                                                        ox = (short) toLong(ix);
35104                                                        oai16data[it.oIndex + j] = ox;
35105                                                }
35106                                        }
35107                                } else {
35108                                        while (it.hasNext()) {
35109                                                for (int j = 0; j < is; j++) {
35110                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
35111                                                        short ox;
35112                                                        if (ix < pax)
35113                                                        ox = (short) toLong(pax);
35114                                                        else
35115                                                        ox = (short) toLong(ix);
35116                                                        oai16data[it.oIndex + j] = ox;
35117                                                }
35118                                        }
35119                                }
35120                        }
35121                        break;
35122                case Dataset.ARRAYINT64:
35123                        final long[] oai64data = ((CompoundLongDataset) result).getData();
35124                        if (is == 1) {
35125                                if (it.isOutputDouble()) {
35126                                        while (it.hasNext()) {
35127                                                final double ix = it.aDouble;
35128                                                long ox;
35129                                                if (ix < pax)
35130                                                ox = toLong(pax);
35131                                                else
35132                                                ox = toLong(ix);
35133                                                oai64data[it.oIndex] = ox;
35134                                        }
35135                                } else {
35136                                        while (it.hasNext()) {
35137                                                final long ix = it.aLong;
35138                                                long ox;
35139                                                if (ix < pax)
35140                                                ox = toLong(pax);
35141                                                else
35142                                                ox = toLong(ix);
35143                                                oai64data[it.oIndex] = ox;
35144                                        }
35145                                }
35146                        } else if (as == 1) {
35147                                if (it.isOutputDouble()) {
35148                                        while (it.hasNext()) {
35149                                                final double ix = it.aDouble;
35150                                                long ox;
35151                                                if (ix < pax)
35152                                                ox = toLong(pax);
35153                                                else
35154                                                ox = toLong(ix);
35155                                                for (int j = 0; j < is; j++) {
35156                                                        oai64data[it.oIndex + j] = ox;
35157                                                }
35158                                        }
35159                                } else {
35160                                        while (it.hasNext()) {
35161                                                final long ix = it.aLong;
35162                                                long ox;
35163                                                if (ix < pax)
35164                                                ox = toLong(pax);
35165                                                else
35166                                                ox = toLong(ix);
35167                                                for (int j = 0; j < is; j++) {
35168                                                        oai64data[it.oIndex + j] = ox;
35169                                                }
35170                                        }
35171                                }
35172                        } else {
35173                                if (it.isOutputDouble()) {
35174                                        while (it.hasNext()) {
35175                                                for (int j = 0; j < is; j++) {
35176                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
35177                                                        long ox;
35178                                                        if (ix < pax)
35179                                                        ox = toLong(pax);
35180                                                        else
35181                                                        ox = toLong(ix);
35182                                                        oai64data[it.oIndex + j] = ox;
35183                                                }
35184                                        }
35185                                } else {
35186                                        while (it.hasNext()) {
35187                                                for (int j = 0; j < is; j++) {
35188                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
35189                                                        long ox;
35190                                                        if (ix < pax)
35191                                                        ox = toLong(pax);
35192                                                        else
35193                                                        ox = toLong(ix);
35194                                                        oai64data[it.oIndex + j] = ox;
35195                                                }
35196                                        }
35197                                }
35198                        }
35199                        break;
35200                case Dataset.ARRAYINT32:
35201                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
35202                        if (is == 1) {
35203                                if (it.isOutputDouble()) {
35204                                        while (it.hasNext()) {
35205                                                final double ix = it.aDouble;
35206                                                int ox;
35207                                                if (ix < pax)
35208                                                ox = (int) toLong(pax);
35209                                                else
35210                                                ox = (int) toLong(ix);
35211                                                oai32data[it.oIndex] = ox;
35212                                        }
35213                                } else {
35214                                        while (it.hasNext()) {
35215                                                final long ix = it.aLong;
35216                                                int ox;
35217                                                if (ix < pax)
35218                                                ox = (int) toLong(pax);
35219                                                else
35220                                                ox = (int) toLong(ix);
35221                                                oai32data[it.oIndex] = ox;
35222                                        }
35223                                }
35224                        } else if (as == 1) {
35225                                if (it.isOutputDouble()) {
35226                                        while (it.hasNext()) {
35227                                                final double ix = it.aDouble;
35228                                                int ox;
35229                                                if (ix < pax)
35230                                                ox = (int) toLong(pax);
35231                                                else
35232                                                ox = (int) toLong(ix);
35233                                                for (int j = 0; j < is; j++) {
35234                                                        oai32data[it.oIndex + j] = ox;
35235                                                }
35236                                        }
35237                                } else {
35238                                        while (it.hasNext()) {
35239                                                final long ix = it.aLong;
35240                                                int ox;
35241                                                if (ix < pax)
35242                                                ox = (int) toLong(pax);
35243                                                else
35244                                                ox = (int) toLong(ix);
35245                                                for (int j = 0; j < is; j++) {
35246                                                        oai32data[it.oIndex + j] = ox;
35247                                                }
35248                                        }
35249                                }
35250                        } else {
35251                                if (it.isOutputDouble()) {
35252                                        while (it.hasNext()) {
35253                                                for (int j = 0; j < is; j++) {
35254                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
35255                                                        int ox;
35256                                                        if (ix < pax)
35257                                                        ox = (int) toLong(pax);
35258                                                        else
35259                                                        ox = (int) toLong(ix);
35260                                                        oai32data[it.oIndex + j] = ox;
35261                                                }
35262                                        }
35263                                } else {
35264                                        while (it.hasNext()) {
35265                                                for (int j = 0; j < is; j++) {
35266                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
35267                                                        int ox;
35268                                                        if (ix < pax)
35269                                                        ox = (int) toLong(pax);
35270                                                        else
35271                                                        ox = (int) toLong(ix);
35272                                                        oai32data[it.oIndex + j] = ox;
35273                                                }
35274                                        }
35275                                }
35276                        }
35277                        break;
35278                case Dataset.FLOAT32:
35279                        final float[] of32data = ((FloatDataset) result).getData();
35280                        if (it.isOutputDouble()) {
35281                                while (it.hasNext()) {
35282                                        final double ix = it.aDouble;
35283                                        float ox;
35284                                        if (ix < pax)
35285                                        ox = (float) (pax);
35286                                        else
35287                                        ox = (float) (ix);
35288                                        of32data[it.oIndex] = ox;
35289                                }
35290                        } else {
35291                                while (it.hasNext()) {
35292                                        final long ix = it.aLong;
35293                                        float ox;
35294                                        if (ix < pax)
35295                                        ox = (float) (pax);
35296                                        else
35297                                        ox = (ix);
35298                                        of32data[it.oIndex] = ox;
35299                                }
35300                        }
35301                        break;
35302                case Dataset.FLOAT64:
35303                        final double[] of64data = ((DoubleDataset) result).getData();
35304                        if (it.isOutputDouble()) {
35305                                while (it.hasNext()) {
35306                                        final double ix = it.aDouble;
35307                                        double ox;
35308                                        if (ix < pax)
35309                                        ox = (pax);
35310                                        else
35311                                        ox = (ix);
35312                                        of64data[it.oIndex] = ox;
35313                                }
35314                        } else {
35315                                while (it.hasNext()) {
35316                                        final long ix = it.aLong;
35317                                        double ox;
35318                                        if (ix < pax)
35319                                        ox = (pax);
35320                                        else
35321                                        ox = (ix);
35322                                        of64data[it.oIndex] = ox;
35323                                }
35324                        }
35325                        break;
35326                case Dataset.ARRAYFLOAT32:
35327                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
35328                        if (is == 1) {
35329                                if (it.isOutputDouble()) {
35330                                        while (it.hasNext()) {
35331                                                final double ix = it.aDouble;
35332                                                float ox;
35333                                                if (ix < pax)
35334                                                ox = (float) (pax);
35335                                                else
35336                                                ox = (float) (ix);
35337                                                oaf32data[it.oIndex] = ox;
35338                                        }
35339                                } else {
35340                                        while (it.hasNext()) {
35341                                                final long ix = it.aLong;
35342                                                float ox;
35343                                                if (ix < pax)
35344                                                ox = (float) (pax);
35345                                                else
35346                                                ox = (ix);
35347                                                oaf32data[it.oIndex] = ox;
35348                                        }
35349                                }
35350                        } else if (as == 1) {
35351                                if (it.isOutputDouble()) {
35352                                        while (it.hasNext()) {
35353                                                final double ix = it.aDouble;
35354                                                float ox;
35355                                                if (ix < pax)
35356                                                ox = (float) (pax);
35357                                                else
35358                                                ox = (float) (ix);
35359                                                for (int j = 0; j < is; j++) {
35360                                                        oaf32data[it.oIndex + j] = ox;
35361                                                }
35362                                        }
35363                                } else {
35364                                        while (it.hasNext()) {
35365                                                final long ix = it.aLong;
35366                                                float ox;
35367                                                if (ix < pax)
35368                                                ox = (float) (pax);
35369                                                else
35370                                                ox = (ix);
35371                                                for (int j = 0; j < is; j++) {
35372                                                        oaf32data[it.oIndex + j] = ox;
35373                                                }
35374                                        }
35375                                }
35376                        } else {
35377                                if (it.isOutputDouble()) {
35378                                        while (it.hasNext()) {
35379                                                for (int j = 0; j < is; j++) {
35380                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
35381                                                        float ox;
35382                                                        if (ix < pax)
35383                                                        ox = (float) (pax);
35384                                                        else
35385                                                        ox = (float) (ix);
35386                                                        oaf32data[it.oIndex + j] = ox;
35387                                                }
35388                                        }
35389                                } else {
35390                                        while (it.hasNext()) {
35391                                                for (int j = 0; j < is; j++) {
35392                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
35393                                                        float ox;
35394                                                        if (ix < pax)
35395                                                        ox = (float) (pax);
35396                                                        else
35397                                                        ox = (ix);
35398                                                        oaf32data[it.oIndex + j] = ox;
35399                                                }
35400                                        }
35401                                }
35402                        }
35403                        break;
35404                case Dataset.ARRAYFLOAT64:
35405                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
35406                        if (is == 1) {
35407                                if (it.isOutputDouble()) {
35408                                        while (it.hasNext()) {
35409                                                final double ix = it.aDouble;
35410                                                double ox;
35411                                                if (ix < pax)
35412                                                ox = (pax);
35413                                                else
35414                                                ox = (ix);
35415                                                oaf64data[it.oIndex] = ox;
35416                                        }
35417                                } else {
35418                                        while (it.hasNext()) {
35419                                                final long ix = it.aLong;
35420                                                double ox;
35421                                                if (ix < pax)
35422                                                ox = (pax);
35423                                                else
35424                                                ox = (ix);
35425                                                oaf64data[it.oIndex] = ox;
35426                                        }
35427                                }
35428                        } else if (as == 1) {
35429                                if (it.isOutputDouble()) {
35430                                        while (it.hasNext()) {
35431                                                final double ix = it.aDouble;
35432                                                double ox;
35433                                                if (ix < pax)
35434                                                ox = (pax);
35435                                                else
35436                                                ox = (ix);
35437                                                for (int j = 0; j < is; j++) {
35438                                                        oaf64data[it.oIndex + j] = ox;
35439                                                }
35440                                        }
35441                                } else {
35442                                        while (it.hasNext()) {
35443                                                final long ix = it.aLong;
35444                                                double ox;
35445                                                if (ix < pax)
35446                                                ox = (pax);
35447                                                else
35448                                                ox = (ix);
35449                                                for (int j = 0; j < is; j++) {
35450                                                        oaf64data[it.oIndex + j] = ox;
35451                                                }
35452                                        }
35453                                }
35454                        } else {
35455                                if (it.isOutputDouble()) {
35456                                        while (it.hasNext()) {
35457                                                for (int j = 0; j < is; j++) {
35458                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
35459                                                        double ox;
35460                                                        if (ix < pax)
35461                                                        ox = (pax);
35462                                                        else
35463                                                        ox = (ix);
35464                                                        oaf64data[it.oIndex + j] = ox;
35465                                                }
35466                                        }
35467                                } else {
35468                                        while (it.hasNext()) {
35469                                                for (int j = 0; j < is; j++) {
35470                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
35471                                                        double ox;
35472                                                        if (ix < pax)
35473                                                        ox = (pax);
35474                                                        else
35475                                                        ox = (ix);
35476                                                        oaf64data[it.oIndex + j] = ox;
35477                                                }
35478                                        }
35479                                }
35480                        }
35481                        break;
35482                default:
35483                        throw new IllegalArgumentException("lowerClip supports integer, compound integer, real, compound real datasets only");
35484                }
35485
35486                addFunctionName(result, "lowerClip");
35487                return result;
35488        }
35489
35490        /**
35491         * upperClip - clip elements to upper limit
35492         * @param a
35493         * @param pa
35494         * @return dataset
35495         * @since 2.3
35496         */
35497        public static Dataset upperClip(final Object a, final Object pa) {
35498                return upperClip(a, null, pa);
35499        }
35500
35501        /**
35502         * upperClip - clip elements to upper limit
35503         * @param a
35504         * @param o output can be null - in which case, a new dataset is created
35505         * @param pa
35506         * @return dataset
35507         * @since 2.3
35508         */
35509        public static Dataset upperClip(final Object a, final Dataset o, final Object pa) {
35510                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
35511                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
35512                final Dataset result = it.getOutput();
35513                if (!result.isComplex()) {
35514                        if (da.isComplex()) {
35515                                da = da.getRealView();
35516                                it = new SingleInputBroadcastIterator(da, result, true);
35517                        }
35518                }
35519                final int is = result.getElementsPerItem();
35520                final int as = da.getElementsPerItem();
35521                final int dt = result.getDType();
35522                final double pax = DTypeUtils.toReal(pa);
35523
35524                switch(dt) {
35525                case Dataset.INT8:
35526                        final byte[] oi8data = ((ByteDataset) result).getData();
35527                        if (it.isOutputDouble()) {
35528                                while (it.hasNext()) {
35529                                        final double ix = it.aDouble;
35530                                        byte ox;
35531                                        if (ix > pax)
35532                                        ox = (byte) toLong(pax);
35533                                        else
35534                                        ox = (byte) toLong(ix);
35535                                        oi8data[it.oIndex] = ox;
35536                                }
35537                        } else {
35538                                while (it.hasNext()) {
35539                                        final long ix = it.aLong;
35540                                        byte ox;
35541                                        if (ix > pax)
35542                                        ox = (byte) toLong(pax);
35543                                        else
35544                                        ox = (byte) toLong(ix);
35545                                        oi8data[it.oIndex] = ox;
35546                                }
35547                        }
35548                        break;
35549                case Dataset.INT16:
35550                        final short[] oi16data = ((ShortDataset) result).getData();
35551                        if (it.isOutputDouble()) {
35552                                while (it.hasNext()) {
35553                                        final double ix = it.aDouble;
35554                                        short ox;
35555                                        if (ix > pax)
35556                                        ox = (short) toLong(pax);
35557                                        else
35558                                        ox = (short) toLong(ix);
35559                                        oi16data[it.oIndex] = ox;
35560                                }
35561                        } else {
35562                                while (it.hasNext()) {
35563                                        final long ix = it.aLong;
35564                                        short ox;
35565                                        if (ix > pax)
35566                                        ox = (short) toLong(pax);
35567                                        else
35568                                        ox = (short) toLong(ix);
35569                                        oi16data[it.oIndex] = ox;
35570                                }
35571                        }
35572                        break;
35573                case Dataset.INT64:
35574                        final long[] oi64data = ((LongDataset) result).getData();
35575                        if (it.isOutputDouble()) {
35576                                while (it.hasNext()) {
35577                                        final double ix = it.aDouble;
35578                                        long ox;
35579                                        if (ix > pax)
35580                                        ox = toLong(pax);
35581                                        else
35582                                        ox = toLong(ix);
35583                                        oi64data[it.oIndex] = ox;
35584                                }
35585                        } else {
35586                                while (it.hasNext()) {
35587                                        final long ix = it.aLong;
35588                                        long ox;
35589                                        if (ix > pax)
35590                                        ox = toLong(pax);
35591                                        else
35592                                        ox = toLong(ix);
35593                                        oi64data[it.oIndex] = ox;
35594                                }
35595                        }
35596                        break;
35597                case Dataset.INT32:
35598                        final int[] oi32data = ((IntegerDataset) result).getData();
35599                        if (it.isOutputDouble()) {
35600                                while (it.hasNext()) {
35601                                        final double ix = it.aDouble;
35602                                        int ox;
35603                                        if (ix > pax)
35604                                        ox = (int) toLong(pax);
35605                                        else
35606                                        ox = (int) toLong(ix);
35607                                        oi32data[it.oIndex] = ox;
35608                                }
35609                        } else {
35610                                while (it.hasNext()) {
35611                                        final long ix = it.aLong;
35612                                        int ox;
35613                                        if (ix > pax)
35614                                        ox = (int) toLong(pax);
35615                                        else
35616                                        ox = (int) toLong(ix);
35617                                        oi32data[it.oIndex] = ox;
35618                                }
35619                        }
35620                        break;
35621                case Dataset.ARRAYINT8:
35622                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
35623                        if (is == 1) {
35624                                if (it.isOutputDouble()) {
35625                                        while (it.hasNext()) {
35626                                                final double ix = it.aDouble;
35627                                                byte ox;
35628                                                if (ix > pax)
35629                                                ox = (byte) toLong(pax);
35630                                                else
35631                                                ox = (byte) toLong(ix);
35632                                                oai8data[it.oIndex] = ox;
35633                                        }
35634                                } else {
35635                                        while (it.hasNext()) {
35636                                                final long ix = it.aLong;
35637                                                byte ox;
35638                                                if (ix > pax)
35639                                                ox = (byte) toLong(pax);
35640                                                else
35641                                                ox = (byte) toLong(ix);
35642                                                oai8data[it.oIndex] = ox;
35643                                        }
35644                                }
35645                        } else if (as == 1) {
35646                                if (it.isOutputDouble()) {
35647                                        while (it.hasNext()) {
35648                                                final double ix = it.aDouble;
35649                                                byte ox;
35650                                                if (ix > pax)
35651                                                ox = (byte) toLong(pax);
35652                                                else
35653                                                ox = (byte) toLong(ix);
35654                                                for (int j = 0; j < is; j++) {
35655                                                        oai8data[it.oIndex + j] = ox;
35656                                                }
35657                                        }
35658                                } else {
35659                                        while (it.hasNext()) {
35660                                                final long ix = it.aLong;
35661                                                byte ox;
35662                                                if (ix > pax)
35663                                                ox = (byte) toLong(pax);
35664                                                else
35665                                                ox = (byte) toLong(ix);
35666                                                for (int j = 0; j < is; j++) {
35667                                                        oai8data[it.oIndex + j] = ox;
35668                                                }
35669                                        }
35670                                }
35671                        } else {
35672                                if (it.isOutputDouble()) {
35673                                        while (it.hasNext()) {
35674                                                for (int j = 0; j < is; j++) {
35675                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
35676                                                        byte ox;
35677                                                        if (ix > pax)
35678                                                        ox = (byte) toLong(pax);
35679                                                        else
35680                                                        ox = (byte) toLong(ix);
35681                                                        oai8data[it.oIndex + j] = ox;
35682                                                }
35683                                        }
35684                                } else {
35685                                        while (it.hasNext()) {
35686                                                for (int j = 0; j < is; j++) {
35687                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
35688                                                        byte ox;
35689                                                        if (ix > pax)
35690                                                        ox = (byte) toLong(pax);
35691                                                        else
35692                                                        ox = (byte) toLong(ix);
35693                                                        oai8data[it.oIndex + j] = ox;
35694                                                }
35695                                        }
35696                                }
35697                        }
35698                        break;
35699                case Dataset.ARRAYINT16:
35700                        final short[] oai16data = ((CompoundShortDataset) result).getData();
35701                        if (is == 1) {
35702                                if (it.isOutputDouble()) {
35703                                        while (it.hasNext()) {
35704                                                final double ix = it.aDouble;
35705                                                short ox;
35706                                                if (ix > pax)
35707                                                ox = (short) toLong(pax);
35708                                                else
35709                                                ox = (short) toLong(ix);
35710                                                oai16data[it.oIndex] = ox;
35711                                        }
35712                                } else {
35713                                        while (it.hasNext()) {
35714                                                final long ix = it.aLong;
35715                                                short ox;
35716                                                if (ix > pax)
35717                                                ox = (short) toLong(pax);
35718                                                else
35719                                                ox = (short) toLong(ix);
35720                                                oai16data[it.oIndex] = ox;
35721                                        }
35722                                }
35723                        } else if (as == 1) {
35724                                if (it.isOutputDouble()) {
35725                                        while (it.hasNext()) {
35726                                                final double ix = it.aDouble;
35727                                                short ox;
35728                                                if (ix > pax)
35729                                                ox = (short) toLong(pax);
35730                                                else
35731                                                ox = (short) toLong(ix);
35732                                                for (int j = 0; j < is; j++) {
35733                                                        oai16data[it.oIndex + j] = ox;
35734                                                }
35735                                        }
35736                                } else {
35737                                        while (it.hasNext()) {
35738                                                final long ix = it.aLong;
35739                                                short ox;
35740                                                if (ix > pax)
35741                                                ox = (short) toLong(pax);
35742                                                else
35743                                                ox = (short) toLong(ix);
35744                                                for (int j = 0; j < is; j++) {
35745                                                        oai16data[it.oIndex + j] = ox;
35746                                                }
35747                                        }
35748                                }
35749                        } else {
35750                                if (it.isOutputDouble()) {
35751                                        while (it.hasNext()) {
35752                                                for (int j = 0; j < is; j++) {
35753                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
35754                                                        short ox;
35755                                                        if (ix > pax)
35756                                                        ox = (short) toLong(pax);
35757                                                        else
35758                                                        ox = (short) toLong(ix);
35759                                                        oai16data[it.oIndex + j] = ox;
35760                                                }
35761                                        }
35762                                } else {
35763                                        while (it.hasNext()) {
35764                                                for (int j = 0; j < is; j++) {
35765                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
35766                                                        short ox;
35767                                                        if (ix > pax)
35768                                                        ox = (short) toLong(pax);
35769                                                        else
35770                                                        ox = (short) toLong(ix);
35771                                                        oai16data[it.oIndex + j] = ox;
35772                                                }
35773                                        }
35774                                }
35775                        }
35776                        break;
35777                case Dataset.ARRAYINT64:
35778                        final long[] oai64data = ((CompoundLongDataset) result).getData();
35779                        if (is == 1) {
35780                                if (it.isOutputDouble()) {
35781                                        while (it.hasNext()) {
35782                                                final double ix = it.aDouble;
35783                                                long ox;
35784                                                if (ix > pax)
35785                                                ox = toLong(pax);
35786                                                else
35787                                                ox = toLong(ix);
35788                                                oai64data[it.oIndex] = ox;
35789                                        }
35790                                } else {
35791                                        while (it.hasNext()) {
35792                                                final long ix = it.aLong;
35793                                                long ox;
35794                                                if (ix > pax)
35795                                                ox = toLong(pax);
35796                                                else
35797                                                ox = toLong(ix);
35798                                                oai64data[it.oIndex] = ox;
35799                                        }
35800                                }
35801                        } else if (as == 1) {
35802                                if (it.isOutputDouble()) {
35803                                        while (it.hasNext()) {
35804                                                final double ix = it.aDouble;
35805                                                long ox;
35806                                                if (ix > pax)
35807                                                ox = toLong(pax);
35808                                                else
35809                                                ox = toLong(ix);
35810                                                for (int j = 0; j < is; j++) {
35811                                                        oai64data[it.oIndex + j] = ox;
35812                                                }
35813                                        }
35814                                } else {
35815                                        while (it.hasNext()) {
35816                                                final long ix = it.aLong;
35817                                                long ox;
35818                                                if (ix > pax)
35819                                                ox = toLong(pax);
35820                                                else
35821                                                ox = toLong(ix);
35822                                                for (int j = 0; j < is; j++) {
35823                                                        oai64data[it.oIndex + j] = ox;
35824                                                }
35825                                        }
35826                                }
35827                        } else {
35828                                if (it.isOutputDouble()) {
35829                                        while (it.hasNext()) {
35830                                                for (int j = 0; j < is; j++) {
35831                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
35832                                                        long ox;
35833                                                        if (ix > pax)
35834                                                        ox = toLong(pax);
35835                                                        else
35836                                                        ox = toLong(ix);
35837                                                        oai64data[it.oIndex + j] = ox;
35838                                                }
35839                                        }
35840                                } else {
35841                                        while (it.hasNext()) {
35842                                                for (int j = 0; j < is; j++) {
35843                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
35844                                                        long ox;
35845                                                        if (ix > pax)
35846                                                        ox = toLong(pax);
35847                                                        else
35848                                                        ox = toLong(ix);
35849                                                        oai64data[it.oIndex + j] = ox;
35850                                                }
35851                                        }
35852                                }
35853                        }
35854                        break;
35855                case Dataset.ARRAYINT32:
35856                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
35857                        if (is == 1) {
35858                                if (it.isOutputDouble()) {
35859                                        while (it.hasNext()) {
35860                                                final double ix = it.aDouble;
35861                                                int ox;
35862                                                if (ix > pax)
35863                                                ox = (int) toLong(pax);
35864                                                else
35865                                                ox = (int) toLong(ix);
35866                                                oai32data[it.oIndex] = ox;
35867                                        }
35868                                } else {
35869                                        while (it.hasNext()) {
35870                                                final long ix = it.aLong;
35871                                                int ox;
35872                                                if (ix > pax)
35873                                                ox = (int) toLong(pax);
35874                                                else
35875                                                ox = (int) toLong(ix);
35876                                                oai32data[it.oIndex] = ox;
35877                                        }
35878                                }
35879                        } else if (as == 1) {
35880                                if (it.isOutputDouble()) {
35881                                        while (it.hasNext()) {
35882                                                final double ix = it.aDouble;
35883                                                int ox;
35884                                                if (ix > pax)
35885                                                ox = (int) toLong(pax);
35886                                                else
35887                                                ox = (int) toLong(ix);
35888                                                for (int j = 0; j < is; j++) {
35889                                                        oai32data[it.oIndex + j] = ox;
35890                                                }
35891                                        }
35892                                } else {
35893                                        while (it.hasNext()) {
35894                                                final long ix = it.aLong;
35895                                                int ox;
35896                                                if (ix > pax)
35897                                                ox = (int) toLong(pax);
35898                                                else
35899                                                ox = (int) toLong(ix);
35900                                                for (int j = 0; j < is; j++) {
35901                                                        oai32data[it.oIndex + j] = ox;
35902                                                }
35903                                        }
35904                                }
35905                        } else {
35906                                if (it.isOutputDouble()) {
35907                                        while (it.hasNext()) {
35908                                                for (int j = 0; j < is; j++) {
35909                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
35910                                                        int ox;
35911                                                        if (ix > pax)
35912                                                        ox = (int) toLong(pax);
35913                                                        else
35914                                                        ox = (int) toLong(ix);
35915                                                        oai32data[it.oIndex + j] = ox;
35916                                                }
35917                                        }
35918                                } else {
35919                                        while (it.hasNext()) {
35920                                                for (int j = 0; j < is; j++) {
35921                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
35922                                                        int ox;
35923                                                        if (ix > pax)
35924                                                        ox = (int) toLong(pax);
35925                                                        else
35926                                                        ox = (int) toLong(ix);
35927                                                        oai32data[it.oIndex + j] = ox;
35928                                                }
35929                                        }
35930                                }
35931                        }
35932                        break;
35933                case Dataset.FLOAT32:
35934                        final float[] of32data = ((FloatDataset) result).getData();
35935                        if (it.isOutputDouble()) {
35936                                while (it.hasNext()) {
35937                                        final double ix = it.aDouble;
35938                                        float ox;
35939                                        if (ix > pax)
35940                                        ox = (float) (pax);
35941                                        else
35942                                        ox = (float) (ix);
35943                                        of32data[it.oIndex] = ox;
35944                                }
35945                        } else {
35946                                while (it.hasNext()) {
35947                                        final long ix = it.aLong;
35948                                        float ox;
35949                                        if (ix > pax)
35950                                        ox = (float) (pax);
35951                                        else
35952                                        ox = (ix);
35953                                        of32data[it.oIndex] = ox;
35954                                }
35955                        }
35956                        break;
35957                case Dataset.FLOAT64:
35958                        final double[] of64data = ((DoubleDataset) result).getData();
35959                        if (it.isOutputDouble()) {
35960                                while (it.hasNext()) {
35961                                        final double ix = it.aDouble;
35962                                        double ox;
35963                                        if (ix > pax)
35964                                        ox = (pax);
35965                                        else
35966                                        ox = (ix);
35967                                        of64data[it.oIndex] = ox;
35968                                }
35969                        } else {
35970                                while (it.hasNext()) {
35971                                        final long ix = it.aLong;
35972                                        double ox;
35973                                        if (ix > pax)
35974                                        ox = (pax);
35975                                        else
35976                                        ox = (ix);
35977                                        of64data[it.oIndex] = ox;
35978                                }
35979                        }
35980                        break;
35981                case Dataset.ARRAYFLOAT32:
35982                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
35983                        if (is == 1) {
35984                                if (it.isOutputDouble()) {
35985                                        while (it.hasNext()) {
35986                                                final double ix = it.aDouble;
35987                                                float ox;
35988                                                if (ix > pax)
35989                                                ox = (float) (pax);
35990                                                else
35991                                                ox = (float) (ix);
35992                                                oaf32data[it.oIndex] = ox;
35993                                        }
35994                                } else {
35995                                        while (it.hasNext()) {
35996                                                final long ix = it.aLong;
35997                                                float ox;
35998                                                if (ix > pax)
35999                                                ox = (float) (pax);
36000                                                else
36001                                                ox = (ix);
36002                                                oaf32data[it.oIndex] = ox;
36003                                        }
36004                                }
36005                        } else if (as == 1) {
36006                                if (it.isOutputDouble()) {
36007                                        while (it.hasNext()) {
36008                                                final double ix = it.aDouble;
36009                                                float ox;
36010                                                if (ix > pax)
36011                                                ox = (float) (pax);
36012                                                else
36013                                                ox = (float) (ix);
36014                                                for (int j = 0; j < is; j++) {
36015                                                        oaf32data[it.oIndex + j] = ox;
36016                                                }
36017                                        }
36018                                } else {
36019                                        while (it.hasNext()) {
36020                                                final long ix = it.aLong;
36021                                                float ox;
36022                                                if (ix > pax)
36023                                                ox = (float) (pax);
36024                                                else
36025                                                ox = (ix);
36026                                                for (int j = 0; j < is; j++) {
36027                                                        oaf32data[it.oIndex + j] = ox;
36028                                                }
36029                                        }
36030                                }
36031                        } else {
36032                                if (it.isOutputDouble()) {
36033                                        while (it.hasNext()) {
36034                                                for (int j = 0; j < is; j++) {
36035                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
36036                                                        float ox;
36037                                                        if (ix > pax)
36038                                                        ox = (float) (pax);
36039                                                        else
36040                                                        ox = (float) (ix);
36041                                                        oaf32data[it.oIndex + j] = ox;
36042                                                }
36043                                        }
36044                                } else {
36045                                        while (it.hasNext()) {
36046                                                for (int j = 0; j < is; j++) {
36047                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
36048                                                        float ox;
36049                                                        if (ix > pax)
36050                                                        ox = (float) (pax);
36051                                                        else
36052                                                        ox = (ix);
36053                                                        oaf32data[it.oIndex + j] = ox;
36054                                                }
36055                                        }
36056                                }
36057                        }
36058                        break;
36059                case Dataset.ARRAYFLOAT64:
36060                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
36061                        if (is == 1) {
36062                                if (it.isOutputDouble()) {
36063                                        while (it.hasNext()) {
36064                                                final double ix = it.aDouble;
36065                                                double ox;
36066                                                if (ix > pax)
36067                                                ox = (pax);
36068                                                else
36069                                                ox = (ix);
36070                                                oaf64data[it.oIndex] = ox;
36071                                        }
36072                                } else {
36073                                        while (it.hasNext()) {
36074                                                final long ix = it.aLong;
36075                                                double ox;
36076                                                if (ix > pax)
36077                                                ox = (pax);
36078                                                else
36079                                                ox = (ix);
36080                                                oaf64data[it.oIndex] = ox;
36081                                        }
36082                                }
36083                        } else if (as == 1) {
36084                                if (it.isOutputDouble()) {
36085                                        while (it.hasNext()) {
36086                                                final double ix = it.aDouble;
36087                                                double ox;
36088                                                if (ix > pax)
36089                                                ox = (pax);
36090                                                else
36091                                                ox = (ix);
36092                                                for (int j = 0; j < is; j++) {
36093                                                        oaf64data[it.oIndex + j] = ox;
36094                                                }
36095                                        }
36096                                } else {
36097                                        while (it.hasNext()) {
36098                                                final long ix = it.aLong;
36099                                                double ox;
36100                                                if (ix > pax)
36101                                                ox = (pax);
36102                                                else
36103                                                ox = (ix);
36104                                                for (int j = 0; j < is; j++) {
36105                                                        oaf64data[it.oIndex + j] = ox;
36106                                                }
36107                                        }
36108                                }
36109                        } else {
36110                                if (it.isOutputDouble()) {
36111                                        while (it.hasNext()) {
36112                                                for (int j = 0; j < is; j++) {
36113                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
36114                                                        double ox;
36115                                                        if (ix > pax)
36116                                                        ox = (pax);
36117                                                        else
36118                                                        ox = (ix);
36119                                                        oaf64data[it.oIndex + j] = ox;
36120                                                }
36121                                        }
36122                                } else {
36123                                        while (it.hasNext()) {
36124                                                for (int j = 0; j < is; j++) {
36125                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
36126                                                        double ox;
36127                                                        if (ix > pax)
36128                                                        ox = (pax);
36129                                                        else
36130                                                        ox = (ix);
36131                                                        oaf64data[it.oIndex + j] = ox;
36132                                                }
36133                                        }
36134                                }
36135                        }
36136                        break;
36137                default:
36138                        throw new IllegalArgumentException("upperClip supports integer, compound integer, real, compound real datasets only");
36139                }
36140
36141                addFunctionName(result, "upperClip");
36142                return result;
36143        }
36144
36145        /**
36146         * clip - clip elements to limits
36147         * @param a
36148         * @param pa
36149         * @param pb
36150         * @return dataset
36151         */
36152        public static Dataset clip(final Object a, final Object pa, final Object pb) {
36153                return clip(a, null, pa, pb);
36154        }
36155
36156        /**
36157         * clip - clip elements to limits
36158         * @param a
36159         * @param o output can be null - in which case, a new dataset is created
36160         * @param pa
36161         * @param pb
36162         * @return dataset
36163         */
36164        public static Dataset clip(final Object a, final Dataset o, final Object pa, final Object pb) {
36165                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
36166                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
36167                final Dataset result = it.getOutput();
36168                if (!result.isComplex()) {
36169                        if (da.isComplex()) {
36170                                da = da.getRealView();
36171                                it = new SingleInputBroadcastIterator(da, result, true);
36172                        }
36173                }
36174                final int is = result.getElementsPerItem();
36175                final int as = da.getElementsPerItem();
36176                final int dt = result.getDType();
36177                final double pax = DTypeUtils.toReal(pa);
36178                final double pbx = DTypeUtils.toReal(pb);
36179
36180                switch(dt) {
36181                case Dataset.INT8:
36182                        final byte[] oi8data = ((ByteDataset) result).getData();
36183                        if (it.isOutputDouble()) {
36184                                while (it.hasNext()) {
36185                                        final double ix = it.aDouble;
36186                                        byte ox;
36187                                        if (ix < pax)
36188                                                ox = (byte) toLong(pax);
36189                                        else if (ix > pbx)
36190                                                ox = (byte) toLong(pbx);
36191                                        else
36192                                                ox = (byte) toLong(ix);
36193                                        oi8data[it.oIndex] = ox;
36194                                }
36195                        } else {
36196                                while (it.hasNext()) {
36197                                        final long ix = it.aLong;
36198                                        byte ox;
36199                                        if (ix < pax)
36200                                                ox = (byte) toLong(pax);
36201                                        else if (ix > pbx)
36202                                                ox = (byte) toLong(pbx);
36203                                        else
36204                                                ox = (byte) toLong(ix);
36205                                        oi8data[it.oIndex] = ox;
36206                                }
36207                        }
36208                        break;
36209                case Dataset.INT16:
36210                        final short[] oi16data = ((ShortDataset) result).getData();
36211                        if (it.isOutputDouble()) {
36212                                while (it.hasNext()) {
36213                                        final double ix = it.aDouble;
36214                                        short ox;
36215                                        if (ix < pax)
36216                                                ox = (short) toLong(pax);
36217                                        else if (ix > pbx)
36218                                                ox = (short) toLong(pbx);
36219                                        else
36220                                                ox = (short) toLong(ix);
36221                                        oi16data[it.oIndex] = ox;
36222                                }
36223                        } else {
36224                                while (it.hasNext()) {
36225                                        final long ix = it.aLong;
36226                                        short ox;
36227                                        if (ix < pax)
36228                                                ox = (short) toLong(pax);
36229                                        else if (ix > pbx)
36230                                                ox = (short) toLong(pbx);
36231                                        else
36232                                                ox = (short) toLong(ix);
36233                                        oi16data[it.oIndex] = ox;
36234                                }
36235                        }
36236                        break;
36237                case Dataset.INT64:
36238                        final long[] oi64data = ((LongDataset) result).getData();
36239                        if (it.isOutputDouble()) {
36240                                while (it.hasNext()) {
36241                                        final double ix = it.aDouble;
36242                                        long ox;
36243                                        if (ix < pax)
36244                                                ox = toLong(pax);
36245                                        else if (ix > pbx)
36246                                                ox = toLong(pbx);
36247                                        else
36248                                                ox = toLong(ix);
36249                                        oi64data[it.oIndex] = ox;
36250                                }
36251                        } else {
36252                                while (it.hasNext()) {
36253                                        final long ix = it.aLong;
36254                                        long ox;
36255                                        if (ix < pax)
36256                                                ox = toLong(pax);
36257                                        else if (ix > pbx)
36258                                                ox = toLong(pbx);
36259                                        else
36260                                                ox = toLong(ix);
36261                                        oi64data[it.oIndex] = ox;
36262                                }
36263                        }
36264                        break;
36265                case Dataset.INT32:
36266                        final int[] oi32data = ((IntegerDataset) result).getData();
36267                        if (it.isOutputDouble()) {
36268                                while (it.hasNext()) {
36269                                        final double ix = it.aDouble;
36270                                        int ox;
36271                                        if (ix < pax)
36272                                                ox = (int) toLong(pax);
36273                                        else if (ix > pbx)
36274                                                ox = (int) toLong(pbx);
36275                                        else
36276                                                ox = (int) toLong(ix);
36277                                        oi32data[it.oIndex] = ox;
36278                                }
36279                        } else {
36280                                while (it.hasNext()) {
36281                                        final long ix = it.aLong;
36282                                        int ox;
36283                                        if (ix < pax)
36284                                                ox = (int) toLong(pax);
36285                                        else if (ix > pbx)
36286                                                ox = (int) toLong(pbx);
36287                                        else
36288                                                ox = (int) toLong(ix);
36289                                        oi32data[it.oIndex] = ox;
36290                                }
36291                        }
36292                        break;
36293                case Dataset.ARRAYINT8:
36294                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
36295                        if (is == 1) {
36296                                if (it.isOutputDouble()) {
36297                                        while (it.hasNext()) {
36298                                                final double ix = it.aDouble;
36299                                                byte ox;
36300                                                if (ix < pax)
36301                                                        ox = (byte) toLong(pax);
36302                                                else if (ix > pbx)
36303                                                        ox = (byte) toLong(pbx);
36304                                                else
36305                                                        ox = (byte) toLong(ix);
36306                                                oai8data[it.oIndex] = ox;
36307                                        }
36308                                } else {
36309                                        while (it.hasNext()) {
36310                                                final long ix = it.aLong;
36311                                                byte ox;
36312                                                if (ix < pax)
36313                                                        ox = (byte) toLong(pax);
36314                                                else if (ix > pbx)
36315                                                        ox = (byte) toLong(pbx);
36316                                                else
36317                                                        ox = (byte) toLong(ix);
36318                                                oai8data[it.oIndex] = ox;
36319                                        }
36320                                }
36321                        } else if (as == 1) {
36322                                if (it.isOutputDouble()) {
36323                                        while (it.hasNext()) {
36324                                                final double ix = it.aDouble;
36325                                                byte ox;
36326                                                if (ix < pax)
36327                                                        ox = (byte) toLong(pax);
36328                                                else if (ix > pbx)
36329                                                        ox = (byte) toLong(pbx);
36330                                                else
36331                                                        ox = (byte) toLong(ix);
36332                                                for (int j = 0; j < is; j++) {
36333                                                        oai8data[it.oIndex + j] = ox;
36334                                                }
36335                                        }
36336                                } else {
36337                                        while (it.hasNext()) {
36338                                                final long ix = it.aLong;
36339                                                byte ox;
36340                                                if (ix < pax)
36341                                                        ox = (byte) toLong(pax);
36342                                                else if (ix > pbx)
36343                                                        ox = (byte) toLong(pbx);
36344                                                else
36345                                                        ox = (byte) toLong(ix);
36346                                                for (int j = 0; j < is; j++) {
36347                                                        oai8data[it.oIndex + j] = ox;
36348                                                }
36349                                        }
36350                                }
36351                        } else {
36352                                if (it.isOutputDouble()) {
36353                                        while (it.hasNext()) {
36354                                                for (int j = 0; j < is; j++) {
36355                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
36356                                                        byte ox;
36357                                                        if (ix < pax)
36358                                                                ox = (byte) toLong(pax);
36359                                                        else if (ix > pbx)
36360                                                                ox = (byte) toLong(pbx);
36361                                                        else
36362                                                                ox = (byte) toLong(ix);
36363                                                        oai8data[it.oIndex + j] = ox;
36364                                                }
36365                                        }
36366                                } else {
36367                                        while (it.hasNext()) {
36368                                                for (int j = 0; j < is; j++) {
36369                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
36370                                                        byte ox;
36371                                                        if (ix < pax)
36372                                                                ox = (byte) toLong(pax);
36373                                                        else if (ix > pbx)
36374                                                                ox = (byte) toLong(pbx);
36375                                                        else
36376                                                                ox = (byte) toLong(ix);
36377                                                        oai8data[it.oIndex + j] = ox;
36378                                                }
36379                                        }
36380                                }
36381                        }
36382                        break;
36383                case Dataset.ARRAYINT16:
36384                        final short[] oai16data = ((CompoundShortDataset) result).getData();
36385                        if (is == 1) {
36386                                if (it.isOutputDouble()) {
36387                                        while (it.hasNext()) {
36388                                                final double ix = it.aDouble;
36389                                                short ox;
36390                                                if (ix < pax)
36391                                                        ox = (short) toLong(pax);
36392                                                else if (ix > pbx)
36393                                                        ox = (short) toLong(pbx);
36394                                                else
36395                                                        ox = (short) toLong(ix);
36396                                                oai16data[it.oIndex] = ox;
36397                                        }
36398                                } else {
36399                                        while (it.hasNext()) {
36400                                                final long ix = it.aLong;
36401                                                short ox;
36402                                                if (ix < pax)
36403                                                        ox = (short) toLong(pax);
36404                                                else if (ix > pbx)
36405                                                        ox = (short) toLong(pbx);
36406                                                else
36407                                                        ox = (short) toLong(ix);
36408                                                oai16data[it.oIndex] = ox;
36409                                        }
36410                                }
36411                        } else if (as == 1) {
36412                                if (it.isOutputDouble()) {
36413                                        while (it.hasNext()) {
36414                                                final double ix = it.aDouble;
36415                                                short ox;
36416                                                if (ix < pax)
36417                                                        ox = (short) toLong(pax);
36418                                                else if (ix > pbx)
36419                                                        ox = (short) toLong(pbx);
36420                                                else
36421                                                        ox = (short) toLong(ix);
36422                                                for (int j = 0; j < is; j++) {
36423                                                        oai16data[it.oIndex + j] = ox;
36424                                                }
36425                                        }
36426                                } else {
36427                                        while (it.hasNext()) {
36428                                                final long ix = it.aLong;
36429                                                short ox;
36430                                                if (ix < pax)
36431                                                        ox = (short) toLong(pax);
36432                                                else if (ix > pbx)
36433                                                        ox = (short) toLong(pbx);
36434                                                else
36435                                                        ox = (short) toLong(ix);
36436                                                for (int j = 0; j < is; j++) {
36437                                                        oai16data[it.oIndex + j] = ox;
36438                                                }
36439                                        }
36440                                }
36441                        } else {
36442                                if (it.isOutputDouble()) {
36443                                        while (it.hasNext()) {
36444                                                for (int j = 0; j < is; j++) {
36445                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
36446                                                        short ox;
36447                                                        if (ix < pax)
36448                                                                ox = (short) toLong(pax);
36449                                                        else if (ix > pbx)
36450                                                                ox = (short) toLong(pbx);
36451                                                        else
36452                                                                ox = (short) toLong(ix);
36453                                                        oai16data[it.oIndex + j] = ox;
36454                                                }
36455                                        }
36456                                } else {
36457                                        while (it.hasNext()) {
36458                                                for (int j = 0; j < is; j++) {
36459                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
36460                                                        short ox;
36461                                                        if (ix < pax)
36462                                                                ox = (short) toLong(pax);
36463                                                        else if (ix > pbx)
36464                                                                ox = (short) toLong(pbx);
36465                                                        else
36466                                                                ox = (short) toLong(ix);
36467                                                        oai16data[it.oIndex + j] = ox;
36468                                                }
36469                                        }
36470                                }
36471                        }
36472                        break;
36473                case Dataset.ARRAYINT64:
36474                        final long[] oai64data = ((CompoundLongDataset) result).getData();
36475                        if (is == 1) {
36476                                if (it.isOutputDouble()) {
36477                                        while (it.hasNext()) {
36478                                                final double ix = it.aDouble;
36479                                                long ox;
36480                                                if (ix < pax)
36481                                                        ox = toLong(pax);
36482                                                else if (ix > pbx)
36483                                                        ox = toLong(pbx);
36484                                                else
36485                                                        ox = toLong(ix);
36486                                                oai64data[it.oIndex] = ox;
36487                                        }
36488                                } else {
36489                                        while (it.hasNext()) {
36490                                                final long ix = it.aLong;
36491                                                long ox;
36492                                                if (ix < pax)
36493                                                        ox = toLong(pax);
36494                                                else if (ix > pbx)
36495                                                        ox = toLong(pbx);
36496                                                else
36497                                                        ox = toLong(ix);
36498                                                oai64data[it.oIndex] = ox;
36499                                        }
36500                                }
36501                        } else if (as == 1) {
36502                                if (it.isOutputDouble()) {
36503                                        while (it.hasNext()) {
36504                                                final double ix = it.aDouble;
36505                                                long ox;
36506                                                if (ix < pax)
36507                                                        ox = toLong(pax);
36508                                                else if (ix > pbx)
36509                                                        ox = toLong(pbx);
36510                                                else
36511                                                        ox = toLong(ix);
36512                                                for (int j = 0; j < is; j++) {
36513                                                        oai64data[it.oIndex + j] = ox;
36514                                                }
36515                                        }
36516                                } else {
36517                                        while (it.hasNext()) {
36518                                                final long ix = it.aLong;
36519                                                long ox;
36520                                                if (ix < pax)
36521                                                        ox = toLong(pax);
36522                                                else if (ix > pbx)
36523                                                        ox = toLong(pbx);
36524                                                else
36525                                                        ox = toLong(ix);
36526                                                for (int j = 0; j < is; j++) {
36527                                                        oai64data[it.oIndex + j] = ox;
36528                                                }
36529                                        }
36530                                }
36531                        } else {
36532                                if (it.isOutputDouble()) {
36533                                        while (it.hasNext()) {
36534                                                for (int j = 0; j < is; j++) {
36535                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
36536                                                        long ox;
36537                                                        if (ix < pax)
36538                                                                ox = toLong(pax);
36539                                                        else if (ix > pbx)
36540                                                                ox = toLong(pbx);
36541                                                        else
36542                                                                ox = toLong(ix);
36543                                                        oai64data[it.oIndex + j] = ox;
36544                                                }
36545                                        }
36546                                } else {
36547                                        while (it.hasNext()) {
36548                                                for (int j = 0; j < is; j++) {
36549                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
36550                                                        long ox;
36551                                                        if (ix < pax)
36552                                                                ox = toLong(pax);
36553                                                        else if (ix > pbx)
36554                                                                ox = toLong(pbx);
36555                                                        else
36556                                                                ox = toLong(ix);
36557                                                        oai64data[it.oIndex + j] = ox;
36558                                                }
36559                                        }
36560                                }
36561                        }
36562                        break;
36563                case Dataset.ARRAYINT32:
36564                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
36565                        if (is == 1) {
36566                                if (it.isOutputDouble()) {
36567                                        while (it.hasNext()) {
36568                                                final double ix = it.aDouble;
36569                                                int ox;
36570                                                if (ix < pax)
36571                                                        ox = (int) toLong(pax);
36572                                                else if (ix > pbx)
36573                                                        ox = (int) toLong(pbx);
36574                                                else
36575                                                        ox = (int) toLong(ix);
36576                                                oai32data[it.oIndex] = ox;
36577                                        }
36578                                } else {
36579                                        while (it.hasNext()) {
36580                                                final long ix = it.aLong;
36581                                                int ox;
36582                                                if (ix < pax)
36583                                                        ox = (int) toLong(pax);
36584                                                else if (ix > pbx)
36585                                                        ox = (int) toLong(pbx);
36586                                                else
36587                                                        ox = (int) toLong(ix);
36588                                                oai32data[it.oIndex] = ox;
36589                                        }
36590                                }
36591                        } else if (as == 1) {
36592                                if (it.isOutputDouble()) {
36593                                        while (it.hasNext()) {
36594                                                final double ix = it.aDouble;
36595                                                int ox;
36596                                                if (ix < pax)
36597                                                        ox = (int) toLong(pax);
36598                                                else if (ix > pbx)
36599                                                        ox = (int) toLong(pbx);
36600                                                else
36601                                                        ox = (int) toLong(ix);
36602                                                for (int j = 0; j < is; j++) {
36603                                                        oai32data[it.oIndex + j] = ox;
36604                                                }
36605                                        }
36606                                } else {
36607                                        while (it.hasNext()) {
36608                                                final long ix = it.aLong;
36609                                                int ox;
36610                                                if (ix < pax)
36611                                                        ox = (int) toLong(pax);
36612                                                else if (ix > pbx)
36613                                                        ox = (int) toLong(pbx);
36614                                                else
36615                                                        ox = (int) toLong(ix);
36616                                                for (int j = 0; j < is; j++) {
36617                                                        oai32data[it.oIndex + j] = ox;
36618                                                }
36619                                        }
36620                                }
36621                        } else {
36622                                if (it.isOutputDouble()) {
36623                                        while (it.hasNext()) {
36624                                                for (int j = 0; j < is; j++) {
36625                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
36626                                                        int ox;
36627                                                        if (ix < pax)
36628                                                                ox = (int) toLong(pax);
36629                                                        else if (ix > pbx)
36630                                                                ox = (int) toLong(pbx);
36631                                                        else
36632                                                                ox = (int) toLong(ix);
36633                                                        oai32data[it.oIndex + j] = ox;
36634                                                }
36635                                        }
36636                                } else {
36637                                        while (it.hasNext()) {
36638                                                for (int j = 0; j < is; j++) {
36639                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
36640                                                        int ox;
36641                                                        if (ix < pax)
36642                                                                ox = (int) toLong(pax);
36643                                                        else if (ix > pbx)
36644                                                                ox = (int) toLong(pbx);
36645                                                        else
36646                                                                ox = (int) toLong(ix);
36647                                                        oai32data[it.oIndex + j] = ox;
36648                                                }
36649                                        }
36650                                }
36651                        }
36652                        break;
36653                case Dataset.FLOAT32:
36654                        final float[] of32data = ((FloatDataset) result).getData();
36655                        if (it.isOutputDouble()) {
36656                                while (it.hasNext()) {
36657                                        final double ix = it.aDouble;
36658                                        float ox;
36659                                        if (Double.isNaN(ix))
36660                                                ox = (float) ((pax+pbx)/2.);
36661                                        else if (ix < pax)
36662                                                ox = (float) (pax);
36663                                        else if (ix > pbx)
36664                                                ox = (float) (pbx);
36665                                        else
36666                                                ox = (float) (ix);
36667                                        of32data[it.oIndex] = ox;
36668                                }
36669                        } else {
36670                                while (it.hasNext()) {
36671                                        final long ix = it.aLong;
36672                                        float ox;
36673                                        if (Double.isNaN(ix))
36674                                                ox = (float) ((pax+pbx)/2.);
36675                                        else if (ix < pax)
36676                                                ox = (float) (pax);
36677                                        else if (ix > pbx)
36678                                                ox = (float) (pbx);
36679                                        else
36680                                                ox = (ix);
36681                                        of32data[it.oIndex] = ox;
36682                                }
36683                        }
36684                        break;
36685                case Dataset.FLOAT64:
36686                        final double[] of64data = ((DoubleDataset) result).getData();
36687                        if (it.isOutputDouble()) {
36688                                while (it.hasNext()) {
36689                                        final double ix = it.aDouble;
36690                                        double ox;
36691                                        if (Double.isNaN(ix))
36692                                                ox = ((pax+pbx)/2.);
36693                                        else if (ix < pax)
36694                                                ox = (pax);
36695                                        else if (ix > pbx)
36696                                                ox = (pbx);
36697                                        else
36698                                                ox = (ix);
36699                                        of64data[it.oIndex] = ox;
36700                                }
36701                        } else {
36702                                while (it.hasNext()) {
36703                                        final long ix = it.aLong;
36704                                        double ox;
36705                                        if (Double.isNaN(ix))
36706                                                ox = ((pax+pbx)/2.);
36707                                        else if (ix < pax)
36708                                                ox = (pax);
36709                                        else if (ix > pbx)
36710                                                ox = (pbx);
36711                                        else
36712                                                ox = (ix);
36713                                        of64data[it.oIndex] = ox;
36714                                }
36715                        }
36716                        break;
36717                case Dataset.ARRAYFLOAT32:
36718                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
36719                        if (is == 1) {
36720                                if (it.isOutputDouble()) {
36721                                        while (it.hasNext()) {
36722                                                final double ix = it.aDouble;
36723                                                float ox;
36724                                                if (Double.isNaN(ix))
36725                                                        ox = (float) ((pax+pbx)/2.);
36726                                                else if (ix < pax)
36727                                                        ox = (float) (pax);
36728                                                else if (ix > pbx)
36729                                                        ox = (float) (pbx);
36730                                                else
36731                                                        ox = (float) (ix);
36732                                                oaf32data[it.oIndex] = ox;
36733                                        }
36734                                } else {
36735                                        while (it.hasNext()) {
36736                                                final long ix = it.aLong;
36737                                                float ox;
36738                                                if (Double.isNaN(ix))
36739                                                        ox = (float) ((pax+pbx)/2.);
36740                                                else if (ix < pax)
36741                                                        ox = (float) (pax);
36742                                                else if (ix > pbx)
36743                                                        ox = (float) (pbx);
36744                                                else
36745                                                        ox = (ix);
36746                                                oaf32data[it.oIndex] = ox;
36747                                        }
36748                                }
36749                        } else if (as == 1) {
36750                                if (it.isOutputDouble()) {
36751                                        while (it.hasNext()) {
36752                                                final double ix = it.aDouble;
36753                                                float ox;
36754                                                if (Double.isNaN(ix))
36755                                                        ox = (float) ((pax+pbx)/2.);
36756                                                else if (ix < pax)
36757                                                        ox = (float) (pax);
36758                                                else if (ix > pbx)
36759                                                        ox = (float) (pbx);
36760                                                else
36761                                                        ox = (float) (ix);
36762                                                for (int j = 0; j < is; j++) {
36763                                                        oaf32data[it.oIndex + j] = ox;
36764                                                }
36765                                        }
36766                                } else {
36767                                        while (it.hasNext()) {
36768                                                final long ix = it.aLong;
36769                                                float ox;
36770                                                if (Double.isNaN(ix))
36771                                                        ox = (float) ((pax+pbx)/2.);
36772                                                else if (ix < pax)
36773                                                        ox = (float) (pax);
36774                                                else if (ix > pbx)
36775                                                        ox = (float) (pbx);
36776                                                else
36777                                                        ox = (ix);
36778                                                for (int j = 0; j < is; j++) {
36779                                                        oaf32data[it.oIndex + j] = ox;
36780                                                }
36781                                        }
36782                                }
36783                        } else {
36784                                if (it.isOutputDouble()) {
36785                                        while (it.hasNext()) {
36786                                                for (int j = 0; j < is; j++) {
36787                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
36788                                                        float ox;
36789                                                        if (Double.isNaN(ix))
36790                                                                ox = (float) ((pax+pbx)/2.);
36791                                                        else if (ix < pax)
36792                                                                ox = (float) (pax);
36793                                                        else if (ix > pbx)
36794                                                                ox = (float) (pbx);
36795                                                        else
36796                                                                ox = (float) (ix);
36797                                                        oaf32data[it.oIndex + j] = ox;
36798                                                }
36799                                        }
36800                                } else {
36801                                        while (it.hasNext()) {
36802                                                for (int j = 0; j < is; j++) {
36803                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
36804                                                        float ox;
36805                                                        if (Double.isNaN(ix))
36806                                                                ox = (float) ((pax+pbx)/2.);
36807                                                        else if (ix < pax)
36808                                                                ox = (float) (pax);
36809                                                        else if (ix > pbx)
36810                                                                ox = (float) (pbx);
36811                                                        else
36812                                                                ox = (ix);
36813                                                        oaf32data[it.oIndex + j] = ox;
36814                                                }
36815                                        }
36816                                }
36817                        }
36818                        break;
36819                case Dataset.ARRAYFLOAT64:
36820                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
36821                        if (is == 1) {
36822                                if (it.isOutputDouble()) {
36823                                        while (it.hasNext()) {
36824                                                final double ix = it.aDouble;
36825                                                double ox;
36826                                                if (Double.isNaN(ix))
36827                                                        ox = ((pax+pbx)/2.);
36828                                                else if (ix < pax)
36829                                                        ox = (pax);
36830                                                else if (ix > pbx)
36831                                                        ox = (pbx);
36832                                                else
36833                                                        ox = (ix);
36834                                                oaf64data[it.oIndex] = ox;
36835                                        }
36836                                } else {
36837                                        while (it.hasNext()) {
36838                                                final long ix = it.aLong;
36839                                                double ox;
36840                                                if (Double.isNaN(ix))
36841                                                        ox = ((pax+pbx)/2.);
36842                                                else if (ix < pax)
36843                                                        ox = (pax);
36844                                                else if (ix > pbx)
36845                                                        ox = (pbx);
36846                                                else
36847                                                        ox = (ix);
36848                                                oaf64data[it.oIndex] = ox;
36849                                        }
36850                                }
36851                        } else if (as == 1) {
36852                                if (it.isOutputDouble()) {
36853                                        while (it.hasNext()) {
36854                                                final double ix = it.aDouble;
36855                                                double ox;
36856                                                if (Double.isNaN(ix))
36857                                                        ox = ((pax+pbx)/2.);
36858                                                else if (ix < pax)
36859                                                        ox = (pax);
36860                                                else if (ix > pbx)
36861                                                        ox = (pbx);
36862                                                else
36863                                                        ox = (ix);
36864                                                for (int j = 0; j < is; j++) {
36865                                                        oaf64data[it.oIndex + j] = ox;
36866                                                }
36867                                        }
36868                                } else {
36869                                        while (it.hasNext()) {
36870                                                final long ix = it.aLong;
36871                                                double ox;
36872                                                if (Double.isNaN(ix))
36873                                                        ox = ((pax+pbx)/2.);
36874                                                else if (ix < pax)
36875                                                        ox = (pax);
36876                                                else if (ix > pbx)
36877                                                        ox = (pbx);
36878                                                else
36879                                                        ox = (ix);
36880                                                for (int j = 0; j < is; j++) {
36881                                                        oaf64data[it.oIndex + j] = ox;
36882                                                }
36883                                        }
36884                                }
36885                        } else {
36886                                if (it.isOutputDouble()) {
36887                                        while (it.hasNext()) {
36888                                                for (int j = 0; j < is; j++) {
36889                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
36890                                                        double ox;
36891                                                        if (Double.isNaN(ix))
36892                                                                ox = ((pax+pbx)/2.);
36893                                                        else if (ix < pax)
36894                                                                ox = (pax);
36895                                                        else if (ix > pbx)
36896                                                                ox = (pbx);
36897                                                        else
36898                                                                ox = (ix);
36899                                                        oaf64data[it.oIndex + j] = ox;
36900                                                }
36901                                        }
36902                                } else {
36903                                        while (it.hasNext()) {
36904                                                for (int j = 0; j < is; j++) {
36905                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
36906                                                        double ox;
36907                                                        if (Double.isNaN(ix))
36908                                                                ox = ((pax+pbx)/2.);
36909                                                        else if (ix < pax)
36910                                                                ox = (pax);
36911                                                        else if (ix > pbx)
36912                                                                ox = (pbx);
36913                                                        else
36914                                                                ox = (ix);
36915                                                        oaf64data[it.oIndex + j] = ox;
36916                                                }
36917                                        }
36918                                }
36919                        }
36920                        break;
36921                default:
36922                        throw new IllegalArgumentException("clip supports integer, compound integer, real, compound real datasets only");
36923                }
36924
36925                addFunctionName(result, "clip");
36926                return result;
36927        }
36928
36929// End of generated code
36930
36931}