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.Comparisons.Monotonicity;
023
024/**
025 * Mathematics class
026 */
027public class Maths {
028
029        // DO NOT EDIT THIS FILE, EDIT internal/template/MathsPreface.java INSTEAD
030
031        /**
032         * Unwrap result from mathematical methods if necessary
033         * 
034         * @param o dataset
035         * @param a input
036         * @return a dataset if a is a dataset or an object of the same class as o
037         */
038        public static Object unwrap(final Dataset o, final Object a) {
039                return a instanceof Dataset ? o : o.getObject();
040        }
041
042        /**
043         * Unwrap result from mathematical methods if necessary
044         * 
045         * @param o dataset
046         * @param a first input
047         * @param b second input
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.getObject();
053        }
054
055        /**
056         * Unwrap result from mathematical methods if necessary
057         * 
058         * @param o dataset
059         * @param a inputs
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.getObject();
072        }
073
074        /**
075         * @param a first operand
076         * @param b second operand
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 first operand
085         * @param b second operand
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 first operand
096         * @param b second operand
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 first operand
105         * @param b second operand
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 single operand
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 single operand
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 single operand
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 single operand
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 single operand
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 single operand
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 single operand
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 single operand
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 single operand
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 single operand
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 single operand
1336         * @param keepZeros
1337         *            if true then zero items are returned as zero rather than NaNs
1338         * @return complex dataset where items have unit amplitude
1339         */
1340        public static Dataset phaseAsComplexNumber(final Object a, final boolean keepZeros) {
1341                return phaseAsComplexNumber(a, null, keepZeros);
1342        }
1343
1344        /**
1345         * Create a phase only dataset. NB it will contain NaNs if there are any
1346         * items with zero amplitude
1347         * 
1348         * @param a single operand
1349         * @param o
1350         *            output can be null - in which case, a new dataset is created
1351         * @param keepZeros
1352         *            if true then zero items are returned as zero rather than NaNs
1353         * @return complex dataset where items have unit amplitude
1354         */
1355        public static Dataset phaseAsComplexNumber(final Object a, final Dataset o, final boolean keepZeros) {
1356                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
1357
1358                if (!da.isComplex()) {
1359                        throw new IllegalArgumentException("Input dataset is not of complex type");
1360                }
1361                Dataset result = o == null ? DatasetFactory.zeros(da) : o;
1362                if (!result.isComplex()) {
1363                        throw new IllegalArgumentException("Output dataset is not of complex type");
1364                }
1365                final int dt = result.getDType();
1366                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, result);
1367
1368                switch (dt) {
1369                case Dataset.COMPLEX64:
1370                        float[] z64data = ((ComplexFloatDataset) result).getData();
1371
1372                        if (keepZeros) {
1373                                while (it.hasNext()) {
1374                                        double rr = it.aDouble;
1375                                        double ri = da.getElementDoubleAbs(it.aIndex + 1);
1376                                        double am = Math.hypot(rr, ri);
1377                                        if (am == 0) {
1378                                                z64data[it.oIndex] = 0;
1379                                                z64data[it.oIndex + 1] = 0;
1380                                        } else {
1381                                                z64data[it.oIndex] = (float) (rr / am);
1382                                                z64data[it.oIndex + 1] = (float) (ri / am);
1383                                        }
1384                                }
1385                        } else {
1386                                while (it.hasNext()) {
1387                                        double rr = it.aDouble;
1388                                        double ri = da.getElementDoubleAbs(it.aIndex + 1);
1389                                        double am = Math.hypot(rr, ri);
1390                                        z64data[it.oIndex] = (float) (rr / am);
1391                                        z64data[it.oIndex + 1] = (float) (ri / am);
1392                                }
1393                        }
1394                        break;
1395                case Dataset.COMPLEX128:
1396                        double[] z128data = ((ComplexDoubleDataset) result).getData();
1397
1398                        if (keepZeros) {
1399                                while (it.hasNext()) {
1400                                        double rr = it.aDouble;
1401                                        double ri = da.getElementDoubleAbs(it.aIndex + 1);
1402                                        double am = Math.hypot(rr, ri);
1403                                        if (am == 0) {
1404                                                z128data[it.oIndex] = 0;
1405                                                z128data[it.oIndex + 1] = 0;
1406                                        } else {
1407                                                z128data[it.oIndex] = rr / am;
1408                                                z128data[it.oIndex + 1] = ri / am;
1409                                        }
1410                                }
1411                        } else {
1412                                while (it.hasNext()) {
1413                                        double rr = it.aDouble;
1414                                        double ri = da.getElementDoubleAbs(it.aIndex + 1);
1415                                        double am = Math.hypot(rr, ri);
1416                                        z128data[it.oIndex] = rr / am;
1417                                        z128data[it.oIndex + 1] = ri / am;
1418                                }
1419                        }
1420                        break;
1421                }
1422
1423                addFunctionName(result, "phase");
1424
1425                return result;
1426        }
1427
1428        /**
1429         * Adds all sets passed in together
1430         * 
1431         * The first IDataset must cast to Dataset
1432         * 
1433         * For memory efficiency sake if add(...) is called with a set of size one,
1434         * no clone is done, the original object is returned directly. Otherwise a
1435         * new data set is returned, the sum of those passed in.
1436         * 
1437         * @param sets datasets
1438         * @param requireClone if true, clone destination to hold sum
1439         * @return sum of collection
1440         */
1441        public static Dataset add(final Collection<IDataset> sets, boolean requireClone) {
1442                if (sets.isEmpty())
1443                        return null;
1444                final Iterator<IDataset> it = sets.iterator();
1445                if (sets.size() == 1)
1446                        return DatasetUtils.convertToDataset(it.next());
1447
1448                Dataset sum = requireClone ? ((Dataset) it.next()).clone() : (Dataset) it.next();
1449
1450                while (it.hasNext()) {
1451                        Maths.add(sum, it.next(), sum);
1452                }
1453
1454                return sum;
1455        }
1456
1457        /**
1458         * Multiplies all sets passed in together
1459         * 
1460         * The first IDataset must cast to Dataset
1461         * 
1462         * @param sets datasets
1463         * @param requireClone if true, clone destination to hold product
1464         * @return product of collection
1465         */
1466        public static Dataset multiply(final Collection<IDataset> sets, boolean requireClone) {
1467                if (sets.isEmpty())
1468                        return null;
1469                final Iterator<IDataset> it = sets.iterator();
1470                if (sets.size() == 1)
1471                        return DatasetUtils.convertToDataset(it.next());
1472                Dataset product = requireClone ? ((Dataset) it.next()).clone() : (Dataset) it.next();
1473
1474                while (it.hasNext()) {
1475                        Maths.multiply(product, it.next(), product);
1476                }
1477
1478                return product;
1479        }
1480
1481        /**
1482         * Linearly interpolate values at points in a 1D dataset corresponding to
1483         * given coordinates.
1484         * 
1485         * @param x
1486         *            input 1-D coordinate dataset (must be ordered)
1487         * @param d
1488         *            input 1-D dataset
1489         * @param x0
1490         *            coordinate values
1491         * @param left
1492         *            value to use when x0 lies left of domain. If null, then
1493         *            interpolate to zero by using leftmost interval
1494         * @param right
1495         *            value to use when x0 lies right of domain. If null, then
1496         *            interpolate to zero by using rightmost interval
1497         * @return interpolated values
1498         */
1499        public static Dataset interpolate(final Dataset x, final Dataset d, final IDataset x0, Number left, Number right) {
1500                assert x.getRank() == 1;
1501                assert d.getRank() == 1;
1502
1503                Monotonicity mono = Comparisons.findMonotonicity(x);
1504                if (mono == Monotonicity.NOT_ORDERED) {
1505                        throw new IllegalArgumentException("Dataset x must be ordered");
1506                }
1507                DoubleDataset dx = DatasetUtils.cast(DoubleDataset.class, x);
1508                Dataset dx0 = DatasetUtils.convertToDataset(x0);
1509                if (x == dx) {
1510                        dx = (DoubleDataset) x.flatten();
1511                }
1512                double[] xa = dx.getData();
1513                final int s = xa.length - 1;
1514                final boolean isReversed = mono == Monotonicity.STRICTLY_DECREASING || mono == Monotonicity.NONINCREASING;
1515                if (isReversed) {
1516                        double[] txa = xa.clone();
1517                        for (int i = 0; i <= s; i++) { // reverse order
1518                                txa[s - i] = xa[i];
1519                        }
1520                        xa = txa;
1521                }
1522
1523                DoubleDataset r = DatasetFactory.zeros(dx0, DoubleDataset.class);
1524                IndexIterator it = dx0.getIterator();
1525                int k = -1;
1526                while (it.hasNext()) {
1527                        k++;
1528                        double v = dx0.getElementDoubleAbs(it.index);
1529                        int i = Arrays.binarySearch(xa, v);
1530                        if (i < 0) {
1531                                // i = -(insertion point) - 1
1532                                if (i == -1) {
1533                                        if (left != null) {
1534                                                r.setAbs(k, left.doubleValue());
1535                                                continue;
1536                                        }
1537                                        final double xa0 = xa[0];
1538                                        final double d1 = xa0 - xa[1];
1539                                        double t = d1 - v + xa0;
1540                                        if (t >= 0) {
1541                                                continue; // sets to zero
1542                                        }
1543                                        t /= d1;
1544                                        r.setAbs(k, t * d.getDouble(isReversed ? s : 0));
1545                                } else if (i == -s - 2) {
1546                                        if (right != null) {
1547                                                r.setAbs(k, right.doubleValue());
1548                                                continue;
1549                                        }
1550                                        final double xas = xa[s];
1551                                        final double d1 = xas - xa[s - 1];
1552                                        double t = d1 - v + xas;
1553                                        if (t <= 0) {
1554                                                continue; // sets to zero
1555                                        }
1556                                        t /= d1;
1557                                        r.setAbs(k, t * d.getDouble(isReversed ? 0 : s));
1558                                } else {
1559                                        i = -i - 1;
1560                                        final double xai = xa[i];
1561                                        double t = (xai - v) / (xai - 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         *            input dataset
1837         * @param x0
1838         *            coordinate
1839         * @param x1
1840         *            coordinate
1841         */
1842        public static void interpolate(final double[] values, final CompoundDataset d, final double x0, final double x1) {
1843                final int[] s = d.getShapeRef();
1844                assert s.length == 2;
1845
1846                final int is = d.getElementsPerItem();
1847                if (is != values.length) {
1848                        throw new IllegalArgumentException("Output array length must match elements in item");
1849                }
1850
1851                final int e0 = s[0] - 1;
1852                final int e1 = s[1] - 1;
1853                final int i0 = (int) Math.floor(x0);
1854                final int i1 = (int) Math.floor(x1);
1855                final double u0 = x0 - i0;
1856                final double u1 = x1 - i1;
1857                if (i0 < -1 || i0 > e0 || i1 < -1 || i1 > e1) {
1858                        Arrays.fill(values, 0);
1859                        return;
1860                }
1861                // use bilinear interpolation
1862                double[] f1 = new double[is];
1863                if (i0 >= 0 && i1 >= 0) {
1864                        d.getDoubleArray(f1, i0, i1);
1865                }
1866
1867                if (u1 > 0) {
1868                        if (u0 > 0) {
1869                                double[] f2 = new double[is];
1870                                double[] f3 = new double[is];
1871                                double[] f4 = new double[is];
1872                                if (i0 != e0) {
1873                                        if (i1 != e1) {
1874                                                d.getDoubleArray(f3, i0 + 1, i1 + 1);
1875                                        }
1876                                        if (i1 >= 0) {
1877                                                d.getDoubleArray(f4, i0 + 1, i1);
1878                                        }
1879                                }
1880                                if (i0 >= 0 && i1 != e1) {
1881                                        d.getDoubleArray(f2, i0, i1 + 1);
1882                                }
1883                                final double t0 = 1 - u0;
1884                                final double t1 = 1 - u1;
1885                                final double w1 = t0 * t1;
1886                                final double w2 = t0 * u1;
1887                                final double w3 = u0 * u1;
1888                                final double w4 = u0 * t1;
1889                                for (int j = 0; j < is; j++) {
1890                                        values[j] = w1 * f1[j] + w2 * f2[j] + w3 * f3[j] + w4 * f4[j];
1891                                }
1892                        } else {
1893                                double[] f2 = new double[is];
1894                                if (i0 >= 0 && i1 != e1) {
1895                                        d.getDoubleArray(f2, i0, i1 + 1);
1896                                }
1897                                final double t1 = 1 - u1;
1898                                for (int j = 0; j < is; j++) {
1899                                        values[j] = t1 * f1[j] + u1 * f2[j];
1900                                }
1901                        }
1902                } else { // exactly on axis 1
1903                        if (u0 > 0) {
1904                                double[] f4 = new double[is];
1905                                if (i0 != e0 && i1 >= 0) {
1906                                        d.getDoubleArray(f4, i0 + 1, i1);
1907                                }
1908                                final double t0 = 1 - u0;
1909                                for (int j = 0; j < is; j++) {
1910                                        values[j] = t0 * f1[j] + u0 * f4[j];
1911                                }
1912                        } else { // exactly on axis 0
1913                                if (i0 >= 0 && i1 >= 0) {
1914                                        d.getDoubleArray(values, i0, i1);
1915                                } else {
1916                                        Arrays.fill(values, 0);
1917                                }
1918                        }
1919                }
1920        }
1921
1922        /**
1923         * Linearly interpolate a value at a point in an n-D dataset. The dataset is
1924         * considered to have zero support outside its bounds. Thus points just
1925         * outside are interpolated from the boundary value to zero. The number of
1926         * coordinates must match the rank of the dataset.
1927         * 
1928         * @param d
1929         *            input dataset
1930         * @param x
1931         *            coordinates
1932         * @return interpolated value
1933         */
1934        public static double interpolate(final Dataset d, final double... x) {
1935                return interpolate(d, null, x);
1936        }
1937
1938        /**
1939         * Linearly interpolate a value at a point in an n-D dataset with a mask. The
1940         * dataset is considered to have zero support outside its bounds. Thus
1941         * points just outside are interpolated from the boundary value to zero. The
1942         * number of coordinates must match the rank of the dataset.
1943         * 
1944         * @param d
1945         *            input dataset
1946         * @param m
1947         *            mask dataset (can be null)
1948         * @param x
1949         *            coordinates
1950         * @return interpolated value
1951         */
1952        public static double interpolate(final Dataset d, final Dataset m, final double... x) {
1953                int r = d.getRank();
1954                if (r != x.length) {
1955                        throw new IllegalArgumentException("Number of coordinates must be equal to rank of dataset");
1956                }
1957
1958                switch (r) {
1959                case 1:
1960                        return m == null ? interpolate(d, x[0]) : interpolate(d, m, x[0]);
1961                case 2:
1962                        return m == null ? interpolate(d, x[0], x[1]) : interpolate(d, m, x[0], x[1]);
1963                }
1964
1965                if (m != null && r != m.getRank()) {
1966                        throw new IllegalArgumentException("Rank of mask dataset must be equal to rank of dataset");
1967                }
1968
1969                // now do it iteratively
1970                int[] l = new int[r]; // lower indexes
1971                double[] f = new double[r]; // fractions
1972                for (int i = 0; i < r; i++) {
1973                        double xi = x[i];
1974                        l[i] = (int) Math.floor(xi);
1975                        f[i] = xi - l[i];
1976                }
1977
1978                int[] s = d.getShape();
1979
1980                int n = 1 << r;
1981                double[] results = new double[n];
1982
1983                // iterate over permutations {l} and {l+1}
1984                int[] twos = new int[r];
1985                Arrays.fill(twos, 2);
1986                PositionIterator it = new PositionIterator(twos);
1987                int[] ip = it.getPos();
1988                int j = 0;
1989                if (m == null) {
1990                        while (it.hasNext()) {
1991                                int[] p = l.clone();
1992                                boolean omit = false;
1993                                for (int i = 0; i < r; i++) {
1994                                        int pi = p[i] + ip[i];
1995                                        if (pi < 0 || pi >= s[i]) {
1996                                                omit = true;
1997                                                break;
1998                                        }
1999                                        p[i] = pi;
2000                                }
2001                                results[j++] = omit ? 0 : d.getDouble(p);
2002                        }
2003                } else {
2004                        while (it.hasNext()) {
2005                                int[] p = l.clone();
2006                                boolean omit = false;
2007                                for (int i = 0; i < r; i++) {
2008                                        int pi = p[i] + ip[i];
2009                                        if (pi < 0 || pi >= s[i]) {
2010                                                omit = true;
2011                                                break;
2012                                        }
2013                                        p[i] = pi;
2014                                }
2015                                results[j++] = omit ? 0 : d.getDouble(p) * m.getDouble(p);
2016                        }
2017                }
2018
2019                // reduce recursively
2020                for (int i = r - 1; i >= 0; i--) {
2021                        results = combine(results, f[i], 1 << i);
2022                }
2023                return results[0];
2024        }
2025
2026        private static double[] combine(double[] values, double f, int n) {
2027                double g = 1 - f;
2028                double[] results = new double[n];
2029                for (int j = 0; j < n; j++) {
2030                        int tj = 2 * j;
2031                        results[j] = g * values[tj] + f * values[tj + 1];
2032                }
2033
2034                return results;
2035        }
2036
2037        /**
2038         * Linearly interpolate an array of values at a point in a compound n-D
2039         * dataset. The dataset is considered to have zero support outside its
2040         * bounds. Thus points just outside are interpolated from the boundary value
2041         * to zero.
2042         * 
2043         * @param values
2044         *            linearly interpolated array
2045         * @param d
2046         *            input dataset
2047         * @param x
2048         *            coordinates
2049         */
2050        public static void interpolate(final double[] values, final CompoundDataset d, final double... x) {
2051                int r = d.getRank();
2052                if (r != x.length) {
2053                        throw new IllegalArgumentException("Number of coordinates must be equal to rank of dataset");
2054                }
2055
2056                switch (r) {
2057                case 1:
2058                        interpolate(values, d, x[0]);
2059                        return;
2060                case 2:
2061                        interpolate(values, d, x[0], x[1]);
2062                        return;
2063                }
2064
2065                final int is = d.getElementsPerItem();
2066                if (is != values.length) {
2067                        throw new IllegalArgumentException("Output array length must match elements in item");
2068                }
2069
2070                // now do it iteratively
2071                int[] l = new int[r]; // lower indexes
2072                double[] f = new double[r]; // fractions
2073                for (int i = 0; i < r; i++) {
2074                        double xi = x[i];
2075                        l[i] = (int) Math.floor(xi);
2076                        f[i] = xi - l[i];
2077                }
2078
2079                int[] s = d.getShape();
2080
2081                int n = 1 << r;
2082                double[][] results = new double[n][is];
2083
2084                // iterate over permutations {l} and {l+1}
2085                int[] twos = new int[r];
2086                Arrays.fill(twos, 2);
2087                PositionIterator it = new PositionIterator(twos);
2088                int[] ip = it.getPos();
2089                int j = 0;
2090                while (it.hasNext()) {
2091                        int[] p = l.clone();
2092                        boolean omit = false;
2093                        for (int i = 0; i < r; i++) {
2094                                int pi = p[i] + ip[i];
2095                                if (pi < 0 || pi >= s[i]) {
2096                                        omit = true;
2097                                        break;
2098                                }
2099                                p[i] = pi;
2100                        }
2101                        if (!omit) {
2102                                d.getDoubleArray(results[j++], p);
2103                        }
2104                }
2105
2106                // reduce recursively
2107                for (int i = r - 1; i >= 0; i--) {
2108                        results = combineArray(is, results, f[i], 1 << i);
2109                }
2110                for (int k = 0; k < is; k++) {
2111                        values[k] = results[0][k];
2112                }
2113        }
2114
2115        private static double[][] combineArray(int is, double[][] values, double f, int n) {
2116                double g = 1 - f;
2117                double[][] results = new double[n][is];
2118                for (int j = 0; j < n; j++) {
2119                        int tj = 2 * j;
2120                        for (int k = 0; k < is; k++) {
2121                                results[j][k] = g * values[tj][k] + f * values[tj + 1][k];
2122                        }
2123                }
2124
2125                return results;
2126        }
2127
2128        /**
2129         * Linearly interpolate a value at a point in a 1D dataset. The dataset is
2130         * considered to have zero support outside its bounds. Thus points just
2131         * outside are interpolated from the boundary value to zero.
2132         * 
2133         * @param d
2134         *            input dataset
2135         * @param x0
2136         *            coordinate
2137         * @return interpolated value
2138         * @deprecated Use {@link #interpolate(Dataset, double)}
2139         */
2140        @Deprecated
2141        public static double getLinear(final IDataset d, final double x0) {
2142                return interpolate(DatasetUtils.convertToDataset(d), x0);
2143        }
2144
2145        /**
2146         * Linearly interpolate a value at a point in a compound 1D dataset. The
2147         * dataset is considered to have zero support outside its bounds. Thus
2148         * points just outside are interpolated from the boundary value to zero.
2149         * 
2150         * @param values
2151         *            interpolated array
2152         * @param d
2153         *            input dataset
2154         * @param x0
2155         *            coordinate
2156         * @deprecated Use {@link #interpolate(double[], CompoundDataset, double)}
2157         */
2158        @Deprecated
2159        public static void getLinear(final double[] values, final CompoundDataset d, final double x0) {
2160                interpolate(values, d, x0);
2161        }
2162
2163        /**
2164         * Interpolated a value from 2D dataset
2165         * 
2166         * @param d
2167         *            input dataset
2168         * @param x0
2169         *            coordinate
2170         * @param x1
2171         *            coordinate
2172         * @return bilinear interpolation
2173         * @deprecated Use {@link #interpolate(Dataset, double, double)}
2174         */
2175        @Deprecated
2176        public static double getBilinear(final IDataset d, final double x0, final double x1) {
2177                return interpolate(DatasetUtils.convertToDataset(d), x0, x1);
2178        }
2179
2180        /**
2181         * Interpolated a value from 2D dataset with mask
2182         * 
2183         * @param d
2184         *            input dataset
2185         * @param m
2186         *            mask dataset
2187         * @param x0
2188         *            coordinate
2189         * @param x1
2190         *            coordinate
2191         * @return bilinear interpolation
2192         * @deprecated Use {@link #interpolate(Dataset, Dataset, double, double)}
2193         */
2194        @Deprecated
2195        public static double getBilinear(final IDataset d, final IDataset m, final double x0, final double x1) {
2196                return interpolate(DatasetUtils.convertToDataset(d), DatasetUtils.convertToDataset(m), x0, x1);
2197        }
2198
2199        /**
2200         * Interpolated a value from 2D compound dataset
2201         * 
2202         * @param values
2203         *            bilinear interpolated array
2204         * @param d
2205         *            input dataset
2206         * @param x0
2207         *            coordinate
2208         * @param x1
2209         *            coordinate
2210         * @deprecated Use
2211         *             {@link #interpolate(double[], CompoundDataset, double, double)}
2212         */
2213        @Deprecated
2214        public static void getBilinear(final double[] values, final CompoundDataset d, final double x0, final double x1) {
2215                interpolate(values, d, x0, x1);
2216        }
2217
2218        /**
2219         * generate binomial coefficients with negative sign:
2220         * <p>
2221         * 
2222         * <pre>
2223         *  (-1)^i n! / ( i! (n-i)! )
2224         * </pre>
2225         * 
2226         * @param n
2227         * @return array of coefficients
2228         */
2229        private static int[] bincoeff(final int n) {
2230                final int[] b = new int[n + 1];
2231                final int hn = n / 2;
2232
2233                int bc = 1;
2234                b[0] = bc;
2235                for (int i = 1; i <= hn; i++) {
2236                        bc = -(bc * (n - i + 1)) / i;
2237                        b[i] = bc;
2238                }
2239                if (n % 2 != 0) {
2240                        for (int i = hn + 1; i <= n; i++) {
2241                                b[i] = -b[n - i];
2242                        }
2243                } else {
2244                        for (int i = hn + 1; i <= n; i++) {
2245                                b[i] = b[n - i];
2246                        }
2247                }
2248                return b;
2249        }
2250
2251        /**
2252         * 1st order discrete difference of dataset along flattened dataset using
2253         * finite difference
2254         * 
2255         * @param a
2256         *            is 1d dataset
2257         * @param out
2258         *            is 1d dataset
2259         */
2260        private static void difference(final Dataset a, final Dataset out) {
2261                final int isize = a.getElementsPerItem();
2262
2263                final IndexIterator it = a.getIterator();
2264                if (!it.hasNext())
2265                        return;
2266                int oi = it.index;
2267
2268                switch (a.getDType()) {
2269                case Dataset.INT8:
2270                        final byte[] i8data = ((ByteDataset) a).getData();
2271                        final byte[] oi8data = ((ByteDataset) out).getData();
2272                        for (int i = 0; it.hasNext();) {
2273                                oi8data[i++] = (byte) (i8data[it.index] - i8data[oi]);
2274                                oi = it.index;
2275                        }
2276                        break;
2277                case Dataset.INT16:
2278                        final short[] i16data = ((ShortDataset) a).getData();
2279                        final short[] oi16data = ((ShortDataset) out).getData();
2280                        for (int i = 0; it.hasNext();) {
2281                                oi16data[i++] = (short) (i16data[it.index] - i16data[oi]);
2282                                oi = it.index;
2283                        }
2284                        break;
2285                case Dataset.INT32:
2286                        final int[] i32data = ((IntegerDataset) a).getData();
2287                        final int[] oi32data = ((IntegerDataset) out).getData();
2288                        for (int i = 0; it.hasNext();) {
2289                                oi32data[i++] = i32data[it.index] - i32data[oi];
2290                                oi = it.index;
2291                        }
2292                        break;
2293                case Dataset.INT64:
2294                        final long[] i64data = ((LongDataset) a).getData();
2295                        final long[] oi64data = ((LongDataset) out).getData();
2296                        for (int i = 0; it.hasNext();) {
2297                                oi64data[i++] = i64data[it.index] - i64data[oi];
2298                                oi = it.index;
2299                        }
2300                        break;
2301                case Dataset.ARRAYINT8:
2302                        final byte[] ai8data = ((CompoundByteDataset) a).getData();
2303                        final byte[] oai8data = ((CompoundByteDataset) out).getData();
2304                        for (int i = 0; it.hasNext();) {
2305                                for (int k = 0; k < isize; k++) {
2306                                        oai8data[i++] = (byte) (ai8data[it.index + k] - ai8data[oi++]);
2307                                }
2308                                oi = it.index;
2309                        }
2310                        break;
2311                case Dataset.ARRAYINT16:
2312                        final short[] ai16data = ((CompoundShortDataset) a).getData();
2313                        final short[] oai16data = ((CompoundShortDataset) out).getData();
2314                        for (int i = 0; it.hasNext();) {
2315                                for (int k = 0; k < isize; k++) {
2316                                        oai16data[i++] = (short) (ai16data[it.index + k] - ai16data[oi++]);
2317                                }
2318                                oi = it.index;
2319                        }
2320                        break;
2321                case Dataset.ARRAYINT32:
2322                        final int[] ai32data = ((CompoundIntegerDataset) a).getData();
2323                        final int[] oai32data = ((CompoundIntegerDataset) out).getData();
2324                        for (int i = 0; it.hasNext();) {
2325                                for (int k = 0; k < isize; k++) {
2326                                        oai32data[i++] = ai32data[it.index + k] - ai32data[oi++];
2327                                }
2328                                oi = it.index;
2329                        }
2330                        break;
2331                case Dataset.ARRAYINT64:
2332                        final long[] ai64data = ((CompoundLongDataset) a).getData();
2333                        final long[] oai64data = ((CompoundLongDataset) out).getData();
2334                        for (int i = 0; it.hasNext();) {
2335                                for (int k = 0; k < isize; k++) {
2336                                        oai64data[i++] = ai64data[it.index + k] - ai64data[oi++];
2337                                }
2338                                oi = it.index;
2339                        }
2340                        break;
2341                case Dataset.FLOAT32:
2342                        final float[] f32data = ((FloatDataset) a).getData();
2343                        final float[] of32data = ((FloatDataset) out).getData();
2344                        for (int i = 0; it.hasNext();) {
2345                                of32data[i++] = f32data[it.index] - f32data[oi];
2346                                oi = it.index;
2347                        }
2348                        break;
2349                case Dataset.FLOAT64:
2350                        final double[] f64data = ((DoubleDataset) a).getData();
2351                        final double[] of64data = ((DoubleDataset) out).getData();
2352                        for (int i = 0; it.hasNext();) {
2353                                of64data[i++] = f64data[it.index] - f64data[oi];
2354                                oi = it.index;
2355                        }
2356                        break;
2357                case Dataset.COMPLEX64:
2358                        final float[] c64data = ((ComplexFloatDataset) a).getData();
2359                        final float[] oc64data = ((ComplexFloatDataset) out).getData();
2360                        for (int i = 0; it.hasNext();) {
2361                                oc64data[i++] = c64data[it.index] - c64data[oi];
2362                                oc64data[i++] = c64data[it.index + 1] - c64data[oi + 1];
2363                                oi = it.index;
2364                        }
2365                        break;
2366                case Dataset.COMPLEX128:
2367                        final double[] c128data = ((ComplexDoubleDataset) a).getData();
2368                        final double[] oc128data = ((ComplexDoubleDataset) out).getData();
2369                        for (int i = 0; it.hasNext();) {
2370                                oc128data[i++] = c128data[it.index] - c128data[oi];
2371                                oc128data[i++] = c128data[it.index + 1] - c128data[oi + 1];
2372                                oi = it.index;
2373                        }
2374                        break;
2375                case Dataset.ARRAYFLOAT32:
2376                        final float[] af32data = ((CompoundFloatDataset) a).getData();
2377                        final float[] oaf32data = ((CompoundFloatDataset) out).getData();
2378                        for (int i = 0; it.hasNext();) {
2379                                for (int k = 0; k < isize; k++) {
2380                                        oaf32data[i++] = af32data[it.index + k] - af32data[oi++];
2381                                }
2382                                oi = it.index;
2383                        }
2384                        break;
2385                case Dataset.ARRAYFLOAT64:
2386                        final double[] af64data = ((CompoundDoubleDataset) a).getData();
2387                        final double[] oaf64data = ((CompoundDoubleDataset) out).getData();
2388                        for (int i = 0; it.hasNext();) {
2389                                for (int k = 0; k < isize; k++) {
2390                                        oaf64data[i++] = af64data[it.index + k] - af64data[oi++];
2391                                }
2392                                oi = it.index;
2393                        }
2394                        break;
2395                default:
2396                        throw new UnsupportedOperationException("difference does not support this dataset type");
2397                }
2398        }
2399
2400        /**
2401         * Get next set of indexes
2402         * 
2403         * @param it
2404         * @param indexes
2405         * @return true if there is more
2406         */
2407        private static boolean nextIndexes(IndexIterator it, int[] indexes) {
2408                if (!it.hasNext())
2409                        return false;
2410                int m = indexes.length;
2411                int i = 0;
2412                for (i = 0; i < m - 1; i++) {
2413                        indexes[i] = indexes[i + 1];
2414                }
2415                indexes[i] = it.index;
2416                return true;
2417        }
2418
2419        /**
2420         * General order discrete difference of dataset along flattened dataset
2421         * using finite difference
2422         * 
2423         * @param a
2424         *            is 1d dataset
2425         * @param out
2426         *            is 1d dataset
2427         * @param n
2428         *            order of difference
2429         */
2430        private static void difference(final Dataset a, final Dataset out, final int n) {
2431                if (n == 1) {
2432                        difference(a, out);
2433                        return;
2434                }
2435
2436                final int isize = a.getElementsPerItem();
2437
2438                final int[] coeff = bincoeff(n);
2439                final int m = n + 1;
2440                final int[] indexes = new int[m]; // store for index values
2441
2442                final IndexIterator it = a.getIterator();
2443                for (int i = 0; i < n; i++) {
2444                        indexes[i] = it.index;
2445                        it.hasNext();
2446                }
2447                indexes[n] = it.index;
2448
2449                switch (a.getDType()) {
2450                case Dataset.INT8:
2451                        final byte[] i8data = ((ByteDataset) a).getData();
2452                        final byte[] oi8data = ((ByteDataset) out).getData();
2453                        for (int i = 0; nextIndexes(it, indexes);) {
2454                                int ox = 0;
2455                                for (int j = 0; j < m; j++) {
2456                                        ox += i8data[indexes[j]] * coeff[j];
2457                                }
2458                                oi8data[i++] = (byte) ox;
2459                        }
2460                        break;
2461                case Dataset.INT16:
2462                        final short[] i16data = ((ShortDataset) a).getData();
2463                        final short[] oi16data = ((ShortDataset) out).getData();
2464                        for (int i = 0; nextIndexes(it, indexes);) {
2465                                int ox = 0;
2466                                for (int j = 0; j < m; j++) {
2467                                        ox += i16data[indexes[j]] * coeff[j];
2468                                }
2469                                oi16data[i++] = (short) ox;
2470                        }
2471                        break;
2472                case Dataset.INT32:
2473                        final int[] i32data = ((IntegerDataset) a).getData();
2474                        final int[] oi32data = ((IntegerDataset) out).getData();
2475                        for (int i = 0; nextIndexes(it, indexes);) {
2476                                int ox = 0;
2477                                for (int j = 0; j < m; j++) {
2478                                        ox += i32data[indexes[j]] * coeff[j];
2479                                }
2480                                oi32data[i++] = ox;
2481                        }
2482                        break;
2483                case Dataset.INT64:
2484                        final long[] i64data = ((LongDataset) a).getData();
2485                        final long[] oi64data = ((LongDataset) out).getData();
2486                        for (int i = 0; nextIndexes(it, indexes);) {
2487                                long ox = 0;
2488                                for (int j = 0; j < m; j++) {
2489                                        ox += i64data[indexes[j]] * coeff[j];
2490                                }
2491                                oi64data[i++] = ox;
2492                        }
2493                        break;
2494                case Dataset.ARRAYINT8:
2495                        final byte[] ai8data = ((CompoundByteDataset) a).getData();
2496                        final byte[] oai8data = ((CompoundByteDataset) out).getData();
2497                        int[] box = new int[isize];
2498                        for (int i = 0; nextIndexes(it, indexes);) {
2499                                Arrays.fill(box, 0);
2500                                for (int j = 0; j < m; j++) {
2501                                        double c = coeff[j];
2502                                        int l = indexes[j];
2503                                        for (int k = 0; k < isize; k++) {
2504                                                box[k] += ai8data[l++] * c;
2505                                        }
2506                                }
2507                                for (int k = 0; k < isize; k++) {
2508                                        oai8data[i++] = (byte) box[k];
2509                                }
2510                        }
2511                        break;
2512                case Dataset.ARRAYINT16:
2513                        final short[] ai16data = ((CompoundShortDataset) a).getData();
2514                        final short[] oai16data = ((CompoundShortDataset) out).getData();
2515                        int[] sox = new int[isize];
2516                        for (int i = 0; nextIndexes(it, indexes);) {
2517                                Arrays.fill(sox, 0);
2518                                for (int j = 0; j < m; j++) {
2519                                        double c = coeff[j];
2520                                        int l = indexes[j];
2521                                        for (int k = 0; k < isize; k++) {
2522                                                sox[k] += ai16data[l++] * c;
2523                                        }
2524                                }
2525                                for (int k = 0; k < isize; k++) {
2526                                        oai16data[i++] = (short) sox[k];
2527                                }
2528                        }
2529                        break;
2530                case Dataset.ARRAYINT32:
2531                        final int[] ai32data = ((CompoundIntegerDataset) a).getData();
2532                        final int[] oai32data = ((CompoundIntegerDataset) out).getData();
2533                        int[] iox = new int[isize];
2534                        for (int i = 0; nextIndexes(it, indexes);) {
2535                                Arrays.fill(iox, 0);
2536                                for (int j = 0; j < m; j++) {
2537                                        double c = coeff[j];
2538                                        int l = indexes[j];
2539                                        for (int k = 0; k < isize; k++) {
2540                                                iox[k] += ai32data[l++] * c;
2541                                        }
2542                                }
2543                                for (int k = 0; k < isize; k++) {
2544                                        oai32data[i++] = iox[k];
2545                                }
2546                        }
2547                        break;
2548                case Dataset.ARRAYINT64:
2549                        final long[] ai64data = ((CompoundLongDataset) a).getData();
2550                        final long[] oai64data = ((CompoundLongDataset) out).getData();
2551                        long[] lox = new long[isize];
2552                        for (int i = 0; nextIndexes(it, indexes);) {
2553                                Arrays.fill(lox, 0);
2554                                for (int j = 0; j < m; j++) {
2555                                        double c = coeff[j];
2556                                        int l = indexes[j];
2557                                        for (int k = 0; k < isize; k++) {
2558                                                lox[k] += ai64data[l++] * c;
2559                                        }
2560                                }
2561                                for (int k = 0; k < isize; k++) {
2562                                        oai64data[i++] = lox[k];
2563                                }
2564                        }
2565                        break;
2566                case Dataset.FLOAT32:
2567                        final float[] f32data = ((FloatDataset) a).getData();
2568                        final float[] of32data = ((FloatDataset) out).getData();
2569                        for (int i = 0; nextIndexes(it, indexes);) {
2570                                float ox = 0;
2571                                for (int j = 0; j < m; j++) {
2572                                        ox += f32data[indexes[j]] * coeff[j];
2573                                }
2574                                of32data[i++] = ox;
2575                        }
2576                        break;
2577                case Dataset.FLOAT64:
2578                        final double[] f64data = ((DoubleDataset) a).getData();
2579                        final double[] of64data = ((DoubleDataset) out).getData();
2580                        for (int i = 0; nextIndexes(it, indexes);) {
2581                                double ox = 0;
2582                                for (int j = 0; j < m; j++) {
2583                                        ox += f64data[indexes[j]] * coeff[j];
2584                                }
2585                                of64data[i++] = ox;
2586                        }
2587                        break;
2588                case Dataset.COMPLEX64:
2589                        final float[] c64data = ((ComplexFloatDataset) a).getData();
2590                        final float[] oc64data = ((ComplexFloatDataset) out).getData();
2591                        for (int i = 0; nextIndexes(it, indexes);) {
2592                                float ox = 0;
2593                                float oy = 0;
2594                                for (int j = 0; j < m; j++) {
2595                                        int l = indexes[j];
2596                                        ox += c64data[l++] * coeff[j];
2597                                        oy += c64data[l] * coeff[j];
2598                                }
2599                                oc64data[i++] = ox;
2600                                oc64data[i++] = oy;
2601                        }
2602                        break;
2603                case Dataset.COMPLEX128:
2604                        final double[] c128data = ((ComplexDoubleDataset) a).getData();
2605                        final double[] oc128data = ((ComplexDoubleDataset) out).getData();
2606                        for (int i = 0; nextIndexes(it, indexes);) {
2607                                double ox = 0;
2608                                double oy = 0;
2609                                for (int j = 0; j < m; j++) {
2610                                        int l = indexes[j];
2611                                        ox += c128data[l++] * coeff[j];
2612                                        oy += c128data[l] * coeff[j];
2613                                }
2614                                oc128data[i++] = ox;
2615                                oc128data[i++] = oy;
2616                        }
2617                        break;
2618                case Dataset.ARRAYFLOAT32:
2619                        final float[] af32data = ((CompoundFloatDataset) a).getData();
2620                        final float[] oaf32data = ((CompoundFloatDataset) out).getData();
2621                        float[] fox = new float[isize];
2622                        for (int i = 0; nextIndexes(it, indexes);) {
2623                                Arrays.fill(fox, 0);
2624                                for (int j = 0; j < m; j++) {
2625                                        double c = coeff[j];
2626                                        int l = indexes[j];
2627                                        for (int k = 0; k < isize; k++) {
2628                                                fox[k] += af32data[l++] * c;
2629                                        }
2630                                }
2631                                for (int k = 0; k < isize; k++) {
2632                                        oaf32data[i++] = fox[k];
2633                                }
2634                        }
2635                        break;
2636                case Dataset.ARRAYFLOAT64:
2637                        final double[] af64data = ((CompoundDoubleDataset) a).getData();
2638                        final double[] oaf64data = ((CompoundDoubleDataset) out).getData();
2639                        double[] dox = new double[isize];
2640                        for (int i = 0; nextIndexes(it, indexes);) {
2641                                Arrays.fill(dox, 0);
2642                                for (int j = 0; j < m; j++) {
2643                                        double c = coeff[j];
2644                                        int l = indexes[j];
2645                                        for (int k = 0; k < isize; k++) {
2646                                                dox[k] += af64data[l++] * c;
2647                                        }
2648                                }
2649                                for (int k = 0; k < isize; k++) {
2650                                        oaf64data[i++] = dox[k];
2651                                }
2652                        }
2653                        break;
2654                default:
2655                        throw new UnsupportedOperationException("difference does not support multiple-element dataset");
2656                }
2657        }
2658
2659        /**
2660         * Discrete difference of dataset along axis using finite difference
2661         * 
2662         * @param a dataset
2663         * @param n
2664         *            order of difference
2665         * @param axis to take difference along
2666         * @return difference
2667         */
2668        public static Dataset difference(Dataset a, final int n, int axis) {
2669                Dataset ds;
2670                final Class<? extends Dataset> clazz = a.getClass();
2671                final int rank = a.getRank();
2672                final int is = a.getElementsPerItem();
2673
2674                if (axis < 0) {
2675                        axis += rank;
2676                }
2677                if (axis < 0 || axis >= rank) {
2678                        throw new IllegalArgumentException("Axis is out of range");
2679                }
2680
2681                int[] nshape = a.getShape();
2682                if (nshape[axis] <= n) {
2683                        nshape[axis] = 0;
2684                        return DatasetFactory.zeros(is, clazz, nshape);
2685                }
2686
2687                nshape[axis] -= n;
2688                ds = DatasetFactory.zeros(is, clazz, nshape);
2689                if (rank == 1) {
2690                        difference(a, ds, n);
2691                } else {
2692                        final Dataset src = DatasetFactory.zeros(is, clazz, a.getShapeRef()[axis]);
2693                        final Dataset dest = DatasetFactory.zeros(is, clazz, nshape[axis]);
2694                        final PositionIterator pi = a.getPositionIterator(axis);
2695                        final int[] pos = pi.getPos();
2696                        final boolean[] hit = pi.getOmit();
2697                        while (pi.hasNext()) {
2698                                a.copyItemsFromAxes(pos, hit, src);
2699                                difference(src, dest, n);
2700                                ds.setItemsOnAxes(pos, hit, dest.getBuffer());
2701                        }
2702                }
2703
2704                return ds;
2705        }
2706
2707        private static double selectedMean(Dataset data, int min, int max) {
2708                double result = 0.0;
2709                for (int i = min, end = data.getSize() - 1; i <= max; i++) {
2710                        // clip i appropriately, imagine that effectively the two ends
2711                        // continue straight out.
2712                        int pos = Math.min(Math.max(0, i), end);
2713                        result += data.getDouble(pos);
2714                }
2715
2716                // now the sum is complete, average the values.
2717                result /= (max - min) + 1;
2718                return result;
2719        }
2720
2721        private static void selectedMeanArray(double[] out, Dataset data, int min, int max) {
2722                Arrays.fill(out, 0);
2723                final int isize = out.length;
2724                for (int i = min, end = data.getSize() - 1; i <= max; i++) {
2725                        // clip i appropriately, imagine that effectively the two ends
2726                        // continue straight out.
2727                        int off = data.get1DIndex(Math.min(Math.max(0, i), end));
2728                        for (int j = 0; j < isize; j++) {
2729                                out[j] += data.getElementDoubleAbs(off++);
2730                        }
2731                }
2732
2733                // now the sum is complete, average the values.
2734                double norm = 1. / (max - min + 1.);
2735                for (int j = 0; j < isize; j++) {
2736                        out[j] *= norm;
2737                }
2738        }
2739
2740        /**
2741         * Calculates the derivative of a line described by two datasets (x,y) given
2742         * a spread of n either side of the point
2743         * 
2744         * @param x
2745         *            The x values of the function to take the derivative of.
2746         * @param y
2747         *            The y values of the function to take the derivative of.
2748         * @param n
2749         *            The spread the derivative is calculated from, i.e. the
2750         *            smoothing, the higher the value, the more smoothing occurs.
2751         * @return A dataset which contains all the derivative point for point.
2752         */
2753        public static Dataset derivative(Dataset x, Dataset y, int n) {
2754                if (x.getRank() != 1 || y.getRank() != 1) {
2755                        throw new IllegalArgumentException("Only one dimensional dataset supported");
2756                }
2757                if (y.getSize() > x.getSize()) {
2758                        throw new IllegalArgumentException("Length of x dataset should be greater than or equal to y's");
2759                }
2760                int dtype = y.getDType();
2761                Dataset result;
2762                switch (dtype) {
2763                case Dataset.BOOL:
2764                case Dataset.INT8:
2765                case Dataset.INT16:
2766                case Dataset.ARRAYINT8:
2767                case Dataset.ARRAYINT16:
2768                        result = DatasetFactory.zeros(y, FloatDataset.class);
2769                        break;
2770                case Dataset.INT32:
2771                case Dataset.INT64:
2772                case Dataset.ARRAYINT32:
2773                case Dataset.ARRAYINT64:
2774                        result = DatasetFactory.zeros(y, DoubleDataset.class);
2775                        break;
2776                case Dataset.FLOAT32:
2777                case Dataset.FLOAT64:
2778                case Dataset.COMPLEX64:
2779                case Dataset.COMPLEX128:
2780                case Dataset.ARRAYFLOAT32:
2781                case Dataset.ARRAYFLOAT64:
2782                        result = DatasetFactory.zeros(y);
2783                        break;
2784                default:
2785                        throw new UnsupportedOperationException("derivative does not support multiple-element dataset");
2786                }
2787
2788                final int isize = y.getElementsPerItem();
2789                if (isize == 1) {
2790                        for (int i = 0, imax = x.getSize(); i < imax; i++) {
2791                                double LeftValue = selectedMean(y, i - n, i - 1);
2792                                double RightValue = selectedMean(y, i + 1, i + n);
2793                                double LeftPosition = selectedMean(x, i - n, i - 1);
2794                                double RightPosition = selectedMean(x, i + 1, i + n);
2795
2796                                // now the values and positions are calculated, the derivative
2797                                // can be
2798                                // calculated.
2799                                result.set(((RightValue - LeftValue) / (RightPosition - LeftPosition)), i);
2800                        }
2801                } else {
2802                        double[] leftValues = new double[isize];
2803                        double[] rightValues = new double[isize];
2804                        for (int i = 0, imax = x.getSize(); i < imax; i++) {
2805                                selectedMeanArray(leftValues, y, i - n, i - 1);
2806                                selectedMeanArray(rightValues, y, i + 1, i + n);
2807                                double delta = selectedMean(x, i - n, i - 1);
2808                                delta = 1. / (selectedMean(x, i + 1, i + n) - delta);
2809                                for (int j = 0; j < isize; j++) {
2810                                        rightValues[j] -= leftValues[j];
2811                                        rightValues[j] *= delta;
2812                                }
2813                                result.set(rightValues, i);
2814                        }
2815                }
2816
2817                // set the name based on the changes made
2818                result.setName(y.getName() + "'");
2819
2820                return result;
2821        }
2822
2823        /**
2824         * Discrete difference of dataset along axis using finite central difference
2825         * 
2826         * @param a dataset
2827         * @param axis to take difference along
2828         * @return difference
2829         */
2830        public static Dataset centralDifference(Dataset a, int axis) {
2831                Dataset ds;
2832                final Class<? extends Dataset> clazz = a.getClass();
2833                final int rank = a.getRank();
2834                final int is = a.getElementsPerItem();
2835
2836                if (axis < 0) {
2837                        axis += rank;
2838                }
2839                if (axis < 0 || axis >= rank) {
2840                        throw new IllegalArgumentException("Axis is out of range");
2841                }
2842
2843                final int len = a.getShapeRef()[axis];
2844                if (len < 2) {
2845                        throw new IllegalArgumentException("Dataset should have a size > 1 along given axis");
2846                }
2847                ds = DatasetFactory.zeros(is, clazz, a.getShapeRef());
2848                if (rank == 1) {
2849                        centralDifference(a, ds);
2850                } else {
2851                        final Dataset src = DatasetFactory.zeros(is, clazz, len);
2852                        final Dataset dest = DatasetFactory.zeros(is, clazz, len);
2853                        final PositionIterator pi = a.getPositionIterator(axis);
2854                        final int[] pos = pi.getPos();
2855                        final boolean[] hit = pi.getOmit();
2856                        while (pi.hasNext()) {
2857                                a.copyItemsFromAxes(pos, hit, src);
2858                                centralDifference(src, dest);
2859                                ds.setItemsOnAxes(pos, hit, dest.getBuffer());
2860                        }
2861                }
2862
2863                return ds;
2864        }
2865
2866        /**
2867         * 1st order discrete difference of dataset along flattened dataset using
2868         * central difference
2869         * 
2870         * @param a
2871         *            is 1d dataset
2872         * @param out
2873         *            is 1d dataset
2874         */
2875        private static void centralDifference(final Dataset a, final Dataset out) {
2876                final int isize = a.getElementsPerItem();
2877                final int dt = a.getDType();
2878
2879                final int nlen = (out.getShapeRef()[0] - 1) * isize;
2880                if (nlen < 1) {
2881                        throw new IllegalArgumentException("Dataset should have a size > 1 along given axis");
2882                }
2883                final IndexIterator it = a.getIterator();
2884                if (!it.hasNext())
2885                        return;
2886                int oi = it.index;
2887                if (!it.hasNext())
2888                        return;
2889                int pi = it.index;
2890
2891                switch (dt) {
2892                case Dataset.INT8:
2893                        final byte[] i8data = ((ByteDataset) a).getData();
2894                        final byte[] oi8data = ((ByteDataset) out).getData();
2895                        oi8data[0] = (byte) (i8data[pi] - i8data[oi]);
2896                        for (int i = 1; it.hasNext(); i++) {
2897                                oi8data[i] = (byte) ((i8data[it.index] - i8data[oi]) / 2);
2898                                oi = pi;
2899                                pi = it.index;
2900                        }
2901                        oi8data[nlen] = (byte) (i8data[pi] - i8data[oi]);
2902                        break;
2903                case Dataset.INT16:
2904                        final short[] i16data = ((ShortDataset) a).getData();
2905                        final short[] oi16data = ((ShortDataset) out).getData();
2906                        oi16data[0] = (short) (i16data[pi] - i16data[oi]);
2907                        for (int i = 1; it.hasNext(); i++) {
2908                                oi16data[i] = (short) ((i16data[it.index] - i16data[oi]) / 2);
2909                                oi = pi;
2910                                pi = it.index;
2911                        }
2912                        oi16data[nlen] = (short) (i16data[pi] - i16data[oi]);
2913                        break;
2914                case Dataset.INT32:
2915                        final int[] i32data = ((IntegerDataset) a).getData();
2916                        final int[] oi32data = ((IntegerDataset) out).getData();
2917                        oi32data[0] = i32data[pi] - i32data[oi];
2918                        for (int i = 1; it.hasNext(); i++) {
2919                                oi32data[i] = (i32data[it.index] - i32data[oi]) / 2;
2920                                oi = pi;
2921                                pi = it.index;
2922                        }
2923                        oi32data[nlen] = i32data[pi] - i32data[oi];
2924                        break;
2925                case Dataset.INT64:
2926                        final long[] i64data = ((LongDataset) a).getData();
2927                        final long[] oi64data = ((LongDataset) out).getData();
2928                        oi64data[0] = i64data[pi] - i64data[oi];
2929                        for (int i = 1; it.hasNext(); i++) {
2930                                oi64data[i] = (i64data[it.index] - i64data[oi]) / 2;
2931                                oi = pi;
2932                                pi = it.index;
2933                        }
2934                        oi64data[nlen] = i64data[pi] - i64data[oi];
2935                        break;
2936                case Dataset.ARRAYINT8:
2937                        final byte[] ai8data = ((CompoundByteDataset) a).getData();
2938                        final byte[] oai8data = ((CompoundByteDataset) out).getData();
2939                        for (int k = 0; k < isize; k++) {
2940                                oai8data[k] = (byte) (ai8data[pi + k] - ai8data[oi + k]);
2941                        }
2942                        for (int i = isize; it.hasNext();) {
2943                                int l = it.index;
2944                                for (int k = 0; k < isize; k++) {
2945                                        oai8data[i++] = (byte) ((ai8data[l++] - ai8data[oi++]) / 2);
2946                                }
2947                                oi = pi;
2948                                pi = it.index;
2949                        }
2950                        for (int k = 0; k < isize; k++) {
2951                                oai8data[nlen + k] = (byte) (ai8data[pi + k] - ai8data[oi + k]);
2952                        }
2953                        break;
2954                case Dataset.ARRAYINT16:
2955                        final short[] ai16data = ((CompoundShortDataset) a).getData();
2956                        final short[] oai16data = ((CompoundShortDataset) out).getData();
2957                        for (int k = 0; k < isize; k++) {
2958                                oai16data[k] = (short) (ai16data[pi + k] - ai16data[oi + k]);
2959                        }
2960                        for (int i = isize; it.hasNext();) {
2961                                int l = it.index;
2962                                for (int k = 0; k < isize; k++) {
2963                                        oai16data[i++] = (short) ((ai16data[l++] - ai16data[oi++]) / 2);
2964                                }
2965                                oi = pi;
2966                                pi = it.index;
2967                        }
2968                        for (int k = 0; k < isize; k++) {
2969                                oai16data[nlen + k] = (short) (ai16data[pi + k] - ai16data[oi + k]);
2970                        }
2971                        break;
2972                case Dataset.ARRAYINT32:
2973                        final int[] ai32data = ((CompoundIntegerDataset) a).getData();
2974                        final int[] oai32data = ((CompoundIntegerDataset) out).getData();
2975                        for (int k = 0; k < isize; k++) {
2976                                oai32data[k] = ai32data[pi + k] - ai32data[oi + k];
2977                        }
2978                        for (int i = isize; it.hasNext();) {
2979                                int l = it.index;
2980                                for (int k = 0; k < isize; k++) {
2981                                        oai32data[i++] = (ai32data[l++] - ai32data[oi++]) / 2;
2982                                }
2983                                oi = pi;
2984                                pi = it.index;
2985                        }
2986                        for (int k = 0; k < isize; k++) {
2987                                oai32data[nlen + k] = ai32data[pi + k] - ai32data[oi + k];
2988                        }
2989                        break;
2990                case Dataset.ARRAYINT64:
2991                        final long[] ai64data = ((CompoundLongDataset) a).getData();
2992                        final long[] oai64data = ((CompoundLongDataset) out).getData();
2993                        for (int k = 0; k < isize; k++) {
2994                                oai64data[k] = ai64data[pi + k] - ai64data[oi + k];
2995                        }
2996                        for (int i = isize; it.hasNext();) {
2997                                int l = it.index;
2998                                for (int k = 0; k < isize; k++) {
2999                                        oai64data[i++] = (ai64data[l++] - ai64data[oi++]) / 2;
3000                                }
3001                                oi = pi;
3002                                pi = it.index;
3003                        }
3004                        for (int k = 0; k < isize; k++) {
3005                                oai64data[nlen + k] = ai64data[pi + k] - ai64data[oi + k];
3006                        }
3007                        break;
3008                case Dataset.FLOAT32:
3009                        final float[] f32data = ((FloatDataset) a).getData();
3010                        final float[] of32data = ((FloatDataset) out).getData();
3011                        of32data[0] = f32data[pi] - f32data[oi];
3012                        for (int i = 1; it.hasNext(); i++) {
3013                                of32data[i] = (f32data[it.index] - f32data[oi]) * 0.5f;
3014                                oi = pi;
3015                                pi = it.index;
3016                        }
3017                        of32data[nlen] = f32data[pi] - f32data[oi];
3018                        break;
3019                case Dataset.FLOAT64:
3020                        final double[] f64data = ((DoubleDataset) a).getData();
3021                        final double[] of64data = ((DoubleDataset) out).getData();
3022                        of64data[0] = f64data[pi] - f64data[oi];
3023                        for (int i = 1; it.hasNext(); i++) {
3024                                of64data[i] = (f64data[it.index] - f64data[oi]) * 0.5f;
3025                                oi = pi;
3026                                pi = it.index;
3027                        }
3028                        of64data[nlen] = f64data[pi] - f64data[oi];
3029                        break;
3030                case Dataset.COMPLEX64:
3031                        final float[] c64data = ((ComplexFloatDataset) a).getData();
3032                        final float[] oc64data = ((ComplexFloatDataset) out).getData();
3033                        oc64data[0] = c64data[pi] - c64data[oi];
3034                        oc64data[1] = c64data[pi + 1] - c64data[oi + 1];
3035                        for (int i = 2; it.hasNext();) {
3036                                oc64data[i++] = (c64data[it.index] - c64data[oi++]) * 0.5f;
3037                                oc64data[i++] = (c64data[it.index + 1] - c64data[oi]) * 0.5f;
3038                                oi = pi;
3039                                pi = it.index;
3040                        }
3041                        oc64data[nlen] = c64data[pi] - c64data[oi];
3042                        oc64data[nlen + 1] = c64data[pi + 1] - c64data[oi + 1];
3043                        break;
3044                case Dataset.COMPLEX128:
3045                        final double[] c128data = ((ComplexDoubleDataset) a).getData();
3046                        final double[] oc128data = ((ComplexDoubleDataset) out).getData();
3047                        oc128data[0] = c128data[pi] - c128data[oi];
3048                        oc128data[1] = c128data[pi + 1] - c128data[oi + 1];
3049                        for (int i = 2; it.hasNext();) {
3050                                oc128data[i++] = (c128data[it.index] - c128data[oi++]) * 0.5f;
3051                                oc128data[i++] = (c128data[it.index + 1] - c128data[oi]) * 0.5f;
3052                                oi = pi;
3053                                pi = it.index;
3054                        }
3055                        oc128data[nlen] = c128data[pi] - c128data[oi];
3056                        oc128data[nlen + 1] = c128data[pi + 1] - c128data[oi + 1];
3057                        break;
3058                case Dataset.ARRAYFLOAT32:
3059                        final float[] af32data = ((CompoundFloatDataset) a).getData();
3060                        final float[] oaf32data = ((CompoundFloatDataset) out).getData();
3061                        for (int k = 0; k < isize; k++) {
3062                                oaf32data[k] = af32data[pi + k] - af32data[oi + k];
3063                        }
3064                        for (int i = isize; it.hasNext();) {
3065                                int l = it.index;
3066                                for (int k = 0; k < isize; k++) {
3067                                        oaf32data[i++] = (af32data[l++] - af32data[oi++]) * 0.5f;
3068                                }
3069                                oi = pi;
3070                                pi = it.index;
3071                        }
3072                        for (int k = 0; k < isize; k++) {
3073                                oaf32data[nlen + k] = af32data[pi + k] - af32data[oi + k];
3074                        }
3075                        break;
3076                case Dataset.ARRAYFLOAT64:
3077                        final double[] af64data = ((CompoundDoubleDataset) a).getData();
3078                        final double[] oaf64data = ((CompoundDoubleDataset) out).getData();
3079                        for (int k = 0; k < isize; k++) {
3080                                oaf64data[k] = af64data[pi + k] - af64data[oi + k];
3081                        }
3082                        for (int i = isize; it.hasNext();) {
3083                                int l = it.index;
3084                                for (int k = 0; k < isize; k++) {
3085                                        oaf64data[i++] = (af64data[l++] - af64data[oi++]) * 0.5;
3086                                }
3087                                oi = pi;
3088                                pi = it.index;
3089                        }
3090                        for (int k = 0; k < isize; k++) {
3091                                oaf64data[nlen + k] = af64data[pi + k] - af64data[oi + k];
3092                        }
3093                        break;
3094                default:
3095                        throw new UnsupportedOperationException("difference does not support this dataset type");
3096                }
3097        }
3098
3099        /**
3100         * Calculate gradient (or partial derivatives) by central difference
3101         * 
3102         * @param y dataset
3103         * @param x
3104         *            one or more datasets for dependent variables
3105         * @return a list of datasets (one for each dimension in y)
3106         */
3107        public static List<Dataset> gradient(Dataset y, Dataset... x) {
3108                final int rank = y.getRank();
3109
3110                if (x.length > 0) {
3111                        if (x.length != rank) {
3112                                throw new IllegalArgumentException(
3113                                                "Number of dependent datasets must be equal to rank of first argument");
3114                        }
3115                        for (int a = 0; a < rank; a++) {
3116                                int rx = x[a].getRank();
3117                                if (rx != rank && rx != 1) {
3118                                        throw new IllegalArgumentException(
3119                                                        "Dependent datasets must be 1-D or match rank of first argument");
3120                                }
3121                                if (rx == 1) {
3122                                        if (y.getShapeRef()[a] != x[a].getShapeRef()[0]) {
3123                                                throw new IllegalArgumentException("Length of dependent dataset must match axis length");
3124                                        }
3125                                } else {
3126                                        y.checkCompatibility(x[a]);
3127                                }
3128                        }
3129                }
3130
3131                List<Dataset> grad = new ArrayList<Dataset>(rank);
3132
3133                for (int a = 0; a < rank; a++) {
3134                        Dataset g = centralDifference(y, a);
3135                        grad.add(g);
3136                }
3137
3138                if (x.length > 0) {
3139                        for (int a = 0; a < rank; a++) {
3140                                Dataset g = grad.get(a);
3141                                Dataset dx = x[a];
3142                                int r = dx.getRank();
3143                                if (r == rank) {
3144                                        g.idivide(centralDifference(dx, a));
3145                                } else {
3146                                        final int is = dx.getElementsPerItem();
3147                                        final Dataset bdx = DatasetFactory.zeros(is, dx.getClass(), y.getShapeRef());
3148                                        final PositionIterator pi = y.getPositionIterator(a);
3149                                        final int[] pos = pi.getPos();
3150                                        final boolean[] hit = pi.getOmit();
3151                                        dx = centralDifference(dx, 0);
3152
3153                                        while (pi.hasNext()) {
3154                                                bdx.setItemsOnAxes(pos, hit, dx.getBuffer());
3155                                        }
3156                                        g.idivide(bdx);
3157                                }
3158                        }
3159                }
3160                return grad;
3161        }
3162
3163        protected static void addFunctionName(final Dataset a, final Dataset b, final Dataset dataset, final String fname) {
3164                dataset.setName(Operations.createFunctionName(fname, a.getName(), b.getName()));
3165        }
3166
3167        protected static void addFunctionName(final Dataset dataset, final String fname) {
3168                dataset.setName(Operations.createFunctionName(fname, dataset.getName()));
3169        }
3170
3171        protected static void addBinaryOperatorName(final Dataset a, final Dataset b, final Dataset dataset, final String oname) {
3172                dataset.setName(Operations.createBinaryOperationName(oname, a.getName(), b.getName()));
3173        }
3174
3175        protected static final long toLong(double d) {
3176                if (Double.isInfinite(d) || Double.isNaN(d))
3177                        return 0l;
3178                return (long) d;
3179        }
3180
3181// Start of generated code
3182        /**
3183         * add operator
3184         * @param a first operand
3185         * @param b second operand
3186         * @return {@code a + b}, addition of a and b
3187         */
3188        public static Dataset add(final Object a, final Object b) {
3189                return add(a, b, null);
3190        }
3191
3192        /**
3193         * add operator
3194         * @param a first operand
3195         * @param b second operand
3196         * @param o output can be null - in which case, a new dataset is created
3197         * @return {@code a + b}, addition of a and b
3198         */
3199        public static Dataset add(final Object a, final Object b, final Dataset o) {
3200                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
3201                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
3202                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
3203                final Dataset result = it.getOutput();
3204                if (!result.isComplex()) {
3205                        boolean change = false;
3206                        if (da.isComplex()) {
3207                                da = da.getRealView();
3208                                change = true;
3209                        }
3210                        if (db.isComplex()) {
3211                                db = db.getRealView();
3212                                change = true;
3213                        }
3214                        if (change) {
3215                                it = BroadcastIterator.createIterator(da, db, result, true);
3216                        }
3217                }
3218                final int is = result.getElementsPerItem();
3219                final int as = da.getElementsPerItem();
3220                final int bs = db.getElementsPerItem();
3221                final int dt = result.getDType();
3222
3223                switch(dt) {
3224                case Dataset.INT8:
3225                        final byte[] oi8data = ((ByteDataset) result).getData();
3226                        if (it.isOutputDouble()) {
3227                                while (it.hasNext()) {
3228                                        final double iax = it.aDouble;
3229                                        final double ibx = it.bDouble;
3230                                        byte ox;
3231                                        ox = (byte) toLong(iax + ibx);
3232                                        oi8data[it.oIndex] = ox;
3233                                }
3234                        } else {
3235                                while (it.hasNext()) {
3236                                        final long iax = it.aLong;
3237                                        final long ibx = it.bLong;
3238                                        byte ox;
3239                                        ox = (byte) (iax + ibx);
3240                                        oi8data[it.oIndex] = ox;
3241                                }
3242                        }
3243                        break;
3244                case Dataset.INT16:
3245                        final short[] oi16data = ((ShortDataset) result).getData();
3246                        if (it.isOutputDouble()) {
3247                                while (it.hasNext()) {
3248                                        final double iax = it.aDouble;
3249                                        final double ibx = it.bDouble;
3250                                        short ox;
3251                                        ox = (short) toLong(iax + ibx);
3252                                        oi16data[it.oIndex] = ox;
3253                                }
3254                        } else {
3255                                while (it.hasNext()) {
3256                                        final long iax = it.aLong;
3257                                        final long ibx = it.bLong;
3258                                        short ox;
3259                                        ox = (short) (iax + ibx);
3260                                        oi16data[it.oIndex] = ox;
3261                                }
3262                        }
3263                        break;
3264                case Dataset.INT64:
3265                        final long[] oi64data = ((LongDataset) result).getData();
3266                        if (it.isOutputDouble()) {
3267                                while (it.hasNext()) {
3268                                        final double iax = it.aDouble;
3269                                        final double ibx = it.bDouble;
3270                                        long ox;
3271                                        ox = toLong(iax + ibx);
3272                                        oi64data[it.oIndex] = ox;
3273                                }
3274                        } else {
3275                                while (it.hasNext()) {
3276                                        final long iax = it.aLong;
3277                                        final long ibx = it.bLong;
3278                                        long ox;
3279                                        ox = (iax + ibx);
3280                                        oi64data[it.oIndex] = ox;
3281                                }
3282                        }
3283                        break;
3284                case Dataset.INT32:
3285                        final int[] oi32data = ((IntegerDataset) result).getData();
3286                        if (it.isOutputDouble()) {
3287                                while (it.hasNext()) {
3288                                        final double iax = it.aDouble;
3289                                        final double ibx = it.bDouble;
3290                                        int ox;
3291                                        ox = (int) toLong(iax + ibx);
3292                                        oi32data[it.oIndex] = ox;
3293                                }
3294                        } else {
3295                                while (it.hasNext()) {
3296                                        final long iax = it.aLong;
3297                                        final long ibx = it.bLong;
3298                                        int ox;
3299                                        ox = (int) (iax + ibx);
3300                                        oi32data[it.oIndex] = ox;
3301                                }
3302                        }
3303                        break;
3304                case Dataset.ARRAYINT8:
3305                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
3306                        if (is == 1) {
3307                                if (it.isOutputDouble()) {
3308                                        while (it.hasNext()) {
3309                                                final double iax = it.aDouble;
3310                                                final double ibx = it.bDouble;
3311                                                byte ox;
3312                                                ox = (byte) toLong(iax + ibx);
3313                                                oai8data[it.oIndex] = ox;
3314                                        }
3315                                } else {
3316                                        while (it.hasNext()) {
3317                                                final long iax = it.aLong;
3318                                                final long ibx = it.bLong;
3319                                                byte ox;
3320                                                ox = (byte) (iax + ibx);
3321                                                oai8data[it.oIndex] = ox;
3322                                        }
3323                                }
3324                        } else if (as < bs) {
3325                                if (it.isOutputDouble()) {
3326                                        while (it.hasNext()) {
3327                                                final double iax = it.aDouble;
3328                                                double ibx = it.bDouble;
3329                                                byte ox;
3330                                                ox = (byte) toLong(iax + ibx);
3331                                                oai8data[it.oIndex] = ox;
3332                                                for (int j = 1; j < is; j++) {
3333                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3334                                                        ox = (byte) toLong(iax + ibx);
3335                                                        oai8data[it.oIndex + j] = ox;
3336                                                }
3337                                        }
3338                                } else {
3339                                        while (it.hasNext()) {
3340                                                final long iax = it.aLong;
3341                                                long ibx = it.bLong;
3342                                                byte ox;
3343                                                ox = (byte) (iax + ibx);
3344                                                oai8data[it.oIndex] = ox;
3345                                                for (int j = 1; j < is; j++) {
3346                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3347                                                        ox = (byte) (iax + ibx);
3348                                                        oai8data[it.oIndex + j] = ox;
3349                                                }
3350                                        }
3351                                }
3352                        } else if (as > bs) {
3353                                if (it.isOutputDouble()) {
3354                                        while (it.hasNext()) {
3355                                                double iax = it.aDouble;
3356                                                final double ibx = it.bDouble;
3357                                                byte ox;
3358                                                ox = (byte) toLong(iax + ibx);
3359                                                oai8data[it.oIndex] = ox;
3360                                                for (int j = 1; j < is; j++) {
3361                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3362                                                        ox = (byte) toLong(iax + ibx);
3363                                                        oai8data[it.oIndex + j] = ox;
3364                                                }
3365                                        }
3366                                } else {
3367                                        while (it.hasNext()) {
3368                                                long iax = it.aLong;
3369                                                final long ibx = it.bLong;
3370                                                byte ox;
3371                                                ox = (byte) (iax + ibx);
3372                                                oai8data[it.oIndex] = ox;
3373                                                for (int j = 1; j < is; j++) {
3374                                                        iax = da.getElementLongAbs(it.aIndex + j);
3375                                                        ox = (byte) (iax + ibx);
3376                                                        oai8data[it.oIndex + j] = ox;
3377                                                }
3378                                        }
3379                                }
3380                        } else if (as == 1) {
3381                                if (it.isOutputDouble()) {
3382                                        while (it.hasNext()) {
3383                                                final double iax = it.aDouble;
3384                                                final double ibx = it.bDouble;
3385                                                byte ox;
3386                                                ox = (byte) toLong(iax + ibx);
3387                                                for (int j = 0; j < is; j++) {
3388                                                        oai8data[it.oIndex + j] = ox;
3389                                                }
3390                                        }
3391                                } else {
3392                                        while (it.hasNext()) {
3393                                                final long iax = it.aLong;
3394                                                final long ibx = it.bLong;
3395                                                byte ox;
3396                                                ox = (byte) (iax + ibx);
3397                                                for (int j = 0; j < is; j++) {
3398                                                        oai8data[it.oIndex + j] = ox;
3399                                                }
3400                                        }
3401                                }
3402                        } else {
3403                                if (it.isOutputDouble()) {
3404                                        while (it.hasNext()) {
3405                                                double iax = it.aDouble;
3406                                                double ibx = it.bDouble;
3407                                                byte ox;
3408                                                ox = (byte) toLong(iax + ibx);
3409                                                oai8data[it.oIndex] = ox;
3410                                                for (int j = 1; j < is; j++) {
3411                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3412                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3413                                                        ox = (byte) toLong(iax + ibx);
3414                                                        oai8data[it.oIndex + j] = ox;
3415                                                }
3416                                        }
3417                                } else {
3418                                        while (it.hasNext()) {
3419                                                long iax = it.aLong;
3420                                                long ibx = it.bLong;
3421                                                byte ox;
3422                                                ox = (byte) (iax + ibx);
3423                                                oai8data[it.oIndex] = ox;
3424                                                for (int j = 1; j < is; j++) {
3425                                                        iax = da.getElementLongAbs(it.aIndex + j);
3426                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3427                                                        ox = (byte) (iax + ibx);
3428                                                        oai8data[it.oIndex + j] = ox;
3429                                                }
3430                                        }
3431                                }
3432                        }
3433                        break;
3434                case Dataset.ARRAYINT16:
3435                        final short[] oai16data = ((CompoundShortDataset) result).getData();
3436                        if (is == 1) {
3437                                if (it.isOutputDouble()) {
3438                                        while (it.hasNext()) {
3439                                                final double iax = it.aDouble;
3440                                                final double ibx = it.bDouble;
3441                                                short ox;
3442                                                ox = (short) toLong(iax + ibx);
3443                                                oai16data[it.oIndex] = ox;
3444                                        }
3445                                } else {
3446                                        while (it.hasNext()) {
3447                                                final long iax = it.aLong;
3448                                                final long ibx = it.bLong;
3449                                                short ox;
3450                                                ox = (short) (iax + ibx);
3451                                                oai16data[it.oIndex] = ox;
3452                                        }
3453                                }
3454                        } else if (as < bs) {
3455                                if (it.isOutputDouble()) {
3456                                        while (it.hasNext()) {
3457                                                final double iax = it.aDouble;
3458                                                double ibx = it.bDouble;
3459                                                short ox;
3460                                                ox = (short) toLong(iax + ibx);
3461                                                oai16data[it.oIndex] = ox;
3462                                                for (int j = 1; j < is; j++) {
3463                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3464                                                        ox = (short) toLong(iax + ibx);
3465                                                        oai16data[it.oIndex + j] = ox;
3466                                                }
3467                                        }
3468                                } else {
3469                                        while (it.hasNext()) {
3470                                                final long iax = it.aLong;
3471                                                long ibx = it.bLong;
3472                                                short ox;
3473                                                ox = (short) (iax + ibx);
3474                                                oai16data[it.oIndex] = ox;
3475                                                for (int j = 1; j < is; j++) {
3476                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3477                                                        ox = (short) (iax + ibx);
3478                                                        oai16data[it.oIndex + j] = ox;
3479                                                }
3480                                        }
3481                                }
3482                        } else if (as > bs) {
3483                                if (it.isOutputDouble()) {
3484                                        while (it.hasNext()) {
3485                                                double iax = it.aDouble;
3486                                                final double ibx = it.bDouble;
3487                                                short ox;
3488                                                ox = (short) toLong(iax + ibx);
3489                                                oai16data[it.oIndex] = ox;
3490                                                for (int j = 1; j < is; j++) {
3491                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3492                                                        ox = (short) toLong(iax + ibx);
3493                                                        oai16data[it.oIndex + j] = ox;
3494                                                }
3495                                        }
3496                                } else {
3497                                        while (it.hasNext()) {
3498                                                long iax = it.aLong;
3499                                                final long ibx = it.bLong;
3500                                                short ox;
3501                                                ox = (short) (iax + ibx);
3502                                                oai16data[it.oIndex] = ox;
3503                                                for (int j = 1; j < is; j++) {
3504                                                        iax = da.getElementLongAbs(it.aIndex + j);
3505                                                        ox = (short) (iax + ibx);
3506                                                        oai16data[it.oIndex + j] = ox;
3507                                                }
3508                                        }
3509                                }
3510                        } else if (as == 1) {
3511                                if (it.isOutputDouble()) {
3512                                        while (it.hasNext()) {
3513                                                final double iax = it.aDouble;
3514                                                final double ibx = it.bDouble;
3515                                                short ox;
3516                                                ox = (short) toLong(iax + ibx);
3517                                                for (int j = 0; j < is; j++) {
3518                                                        oai16data[it.oIndex + j] = ox;
3519                                                }
3520                                        }
3521                                } else {
3522                                        while (it.hasNext()) {
3523                                                final long iax = it.aLong;
3524                                                final long ibx = it.bLong;
3525                                                short ox;
3526                                                ox = (short) (iax + ibx);
3527                                                for (int j = 0; j < is; j++) {
3528                                                        oai16data[it.oIndex + j] = ox;
3529                                                }
3530                                        }
3531                                }
3532                        } else {
3533                                if (it.isOutputDouble()) {
3534                                        while (it.hasNext()) {
3535                                                double iax = it.aDouble;
3536                                                double ibx = it.bDouble;
3537                                                short ox;
3538                                                ox = (short) toLong(iax + ibx);
3539                                                oai16data[it.oIndex] = ox;
3540                                                for (int j = 1; j < is; j++) {
3541                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3542                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3543                                                        ox = (short) toLong(iax + ibx);
3544                                                        oai16data[it.oIndex + j] = ox;
3545                                                }
3546                                        }
3547                                } else {
3548                                        while (it.hasNext()) {
3549                                                long iax = it.aLong;
3550                                                long ibx = it.bLong;
3551                                                short ox;
3552                                                ox = (short) (iax + ibx);
3553                                                oai16data[it.oIndex] = ox;
3554                                                for (int j = 1; j < is; j++) {
3555                                                        iax = da.getElementLongAbs(it.aIndex + j);
3556                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3557                                                        ox = (short) (iax + ibx);
3558                                                        oai16data[it.oIndex + j] = ox;
3559                                                }
3560                                        }
3561                                }
3562                        }
3563                        break;
3564                case Dataset.ARRAYINT64:
3565                        final long[] oai64data = ((CompoundLongDataset) result).getData();
3566                        if (is == 1) {
3567                                if (it.isOutputDouble()) {
3568                                        while (it.hasNext()) {
3569                                                final double iax = it.aDouble;
3570                                                final double ibx = it.bDouble;
3571                                                long ox;
3572                                                ox = toLong(iax + ibx);
3573                                                oai64data[it.oIndex] = ox;
3574                                        }
3575                                } else {
3576                                        while (it.hasNext()) {
3577                                                final long iax = it.aLong;
3578                                                final long ibx = it.bLong;
3579                                                long ox;
3580                                                ox = (iax + ibx);
3581                                                oai64data[it.oIndex] = ox;
3582                                        }
3583                                }
3584                        } else if (as < bs) {
3585                                if (it.isOutputDouble()) {
3586                                        while (it.hasNext()) {
3587                                                final double iax = it.aDouble;
3588                                                double ibx = it.bDouble;
3589                                                long ox;
3590                                                ox = toLong(iax + ibx);
3591                                                oai64data[it.oIndex] = ox;
3592                                                for (int j = 1; j < is; j++) {
3593                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3594                                                        ox = toLong(iax + ibx);
3595                                                        oai64data[it.oIndex + j] = ox;
3596                                                }
3597                                        }
3598                                } else {
3599                                        while (it.hasNext()) {
3600                                                final long iax = it.aLong;
3601                                                long ibx = it.bLong;
3602                                                long ox;
3603                                                ox = (iax + ibx);
3604                                                oai64data[it.oIndex] = ox;
3605                                                for (int j = 1; j < is; j++) {
3606                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3607                                                        ox = (iax + ibx);
3608                                                        oai64data[it.oIndex + j] = ox;
3609                                                }
3610                                        }
3611                                }
3612                        } else if (as > bs) {
3613                                if (it.isOutputDouble()) {
3614                                        while (it.hasNext()) {
3615                                                double iax = it.aDouble;
3616                                                final double ibx = it.bDouble;
3617                                                long ox;
3618                                                ox = toLong(iax + ibx);
3619                                                oai64data[it.oIndex] = ox;
3620                                                for (int j = 1; j < is; j++) {
3621                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3622                                                        ox = toLong(iax + ibx);
3623                                                        oai64data[it.oIndex + j] = ox;
3624                                                }
3625                                        }
3626                                } else {
3627                                        while (it.hasNext()) {
3628                                                long iax = it.aLong;
3629                                                final long ibx = it.bLong;
3630                                                long ox;
3631                                                ox = (iax + ibx);
3632                                                oai64data[it.oIndex] = ox;
3633                                                for (int j = 1; j < is; j++) {
3634                                                        iax = da.getElementLongAbs(it.aIndex + j);
3635                                                        ox = (iax + ibx);
3636                                                        oai64data[it.oIndex + j] = ox;
3637                                                }
3638                                        }
3639                                }
3640                        } else if (as == 1) {
3641                                if (it.isOutputDouble()) {
3642                                        while (it.hasNext()) {
3643                                                final double iax = it.aDouble;
3644                                                final double ibx = it.bDouble;
3645                                                long ox;
3646                                                ox = toLong(iax + ibx);
3647                                                for (int j = 0; j < is; j++) {
3648                                                        oai64data[it.oIndex + j] = ox;
3649                                                }
3650                                        }
3651                                } else {
3652                                        while (it.hasNext()) {
3653                                                final long iax = it.aLong;
3654                                                final long ibx = it.bLong;
3655                                                long ox;
3656                                                ox = (iax + ibx);
3657                                                for (int j = 0; j < is; j++) {
3658                                                        oai64data[it.oIndex + j] = ox;
3659                                                }
3660                                        }
3661                                }
3662                        } else {
3663                                if (it.isOutputDouble()) {
3664                                        while (it.hasNext()) {
3665                                                double iax = it.aDouble;
3666                                                double ibx = it.bDouble;
3667                                                long ox;
3668                                                ox = toLong(iax + ibx);
3669                                                oai64data[it.oIndex] = ox;
3670                                                for (int j = 1; j < is; j++) {
3671                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3672                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3673                                                        ox = toLong(iax + ibx);
3674                                                        oai64data[it.oIndex + j] = ox;
3675                                                }
3676                                        }
3677                                } else {
3678                                        while (it.hasNext()) {
3679                                                long iax = it.aLong;
3680                                                long ibx = it.bLong;
3681                                                long ox;
3682                                                ox = (iax + ibx);
3683                                                oai64data[it.oIndex] = ox;
3684                                                for (int j = 1; j < is; j++) {
3685                                                        iax = da.getElementLongAbs(it.aIndex + j);
3686                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3687                                                        ox = (iax + ibx);
3688                                                        oai64data[it.oIndex + j] = ox;
3689                                                }
3690                                        }
3691                                }
3692                        }
3693                        break;
3694                case Dataset.ARRAYINT32:
3695                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
3696                        if (is == 1) {
3697                                if (it.isOutputDouble()) {
3698                                        while (it.hasNext()) {
3699                                                final double iax = it.aDouble;
3700                                                final double ibx = it.bDouble;
3701                                                int ox;
3702                                                ox = (int) toLong(iax + ibx);
3703                                                oai32data[it.oIndex] = ox;
3704                                        }
3705                                } else {
3706                                        while (it.hasNext()) {
3707                                                final long iax = it.aLong;
3708                                                final long ibx = it.bLong;
3709                                                int ox;
3710                                                ox = (int) (iax + ibx);
3711                                                oai32data[it.oIndex] = ox;
3712                                        }
3713                                }
3714                        } else if (as < bs) {
3715                                if (it.isOutputDouble()) {
3716                                        while (it.hasNext()) {
3717                                                final double iax = it.aDouble;
3718                                                double ibx = it.bDouble;
3719                                                int ox;
3720                                                ox = (int) toLong(iax + ibx);
3721                                                oai32data[it.oIndex] = ox;
3722                                                for (int j = 1; j < is; j++) {
3723                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3724                                                        ox = (int) toLong(iax + ibx);
3725                                                        oai32data[it.oIndex + j] = ox;
3726                                                }
3727                                        }
3728                                } else {
3729                                        while (it.hasNext()) {
3730                                                final long iax = it.aLong;
3731                                                long ibx = it.bLong;
3732                                                int ox;
3733                                                ox = (int) (iax + ibx);
3734                                                oai32data[it.oIndex] = ox;
3735                                                for (int j = 1; j < is; j++) {
3736                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3737                                                        ox = (int) (iax + ibx);
3738                                                        oai32data[it.oIndex + j] = ox;
3739                                                }
3740                                        }
3741                                }
3742                        } else if (as > bs) {
3743                                if (it.isOutputDouble()) {
3744                                        while (it.hasNext()) {
3745                                                double iax = it.aDouble;
3746                                                final double ibx = it.bDouble;
3747                                                int ox;
3748                                                ox = (int) toLong(iax + ibx);
3749                                                oai32data[it.oIndex] = ox;
3750                                                for (int j = 1; j < is; j++) {
3751                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3752                                                        ox = (int) toLong(iax + ibx);
3753                                                        oai32data[it.oIndex + j] = ox;
3754                                                }
3755                                        }
3756                                } else {
3757                                        while (it.hasNext()) {
3758                                                long iax = it.aLong;
3759                                                final long ibx = it.bLong;
3760                                                int ox;
3761                                                ox = (int) (iax + ibx);
3762                                                oai32data[it.oIndex] = ox;
3763                                                for (int j = 1; j < is; j++) {
3764                                                        iax = da.getElementLongAbs(it.aIndex + j);
3765                                                        ox = (int) (iax + ibx);
3766                                                        oai32data[it.oIndex + j] = ox;
3767                                                }
3768                                        }
3769                                }
3770                        } else if (as == 1) {
3771                                if (it.isOutputDouble()) {
3772                                        while (it.hasNext()) {
3773                                                final double iax = it.aDouble;
3774                                                final double ibx = it.bDouble;
3775                                                int ox;
3776                                                ox = (int) toLong(iax + ibx);
3777                                                for (int j = 0; j < is; j++) {
3778                                                        oai32data[it.oIndex + j] = ox;
3779                                                }
3780                                        }
3781                                } else {
3782                                        while (it.hasNext()) {
3783                                                final long iax = it.aLong;
3784                                                final long ibx = it.bLong;
3785                                                int ox;
3786                                                ox = (int) (iax + ibx);
3787                                                for (int j = 0; j < is; j++) {
3788                                                        oai32data[it.oIndex + j] = ox;
3789                                                }
3790                                        }
3791                                }
3792                        } else {
3793                                if (it.isOutputDouble()) {
3794                                        while (it.hasNext()) {
3795                                                double iax = it.aDouble;
3796                                                double ibx = it.bDouble;
3797                                                int ox;
3798                                                ox = (int) toLong(iax + ibx);
3799                                                oai32data[it.oIndex] = ox;
3800                                                for (int j = 1; j < is; j++) {
3801                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3802                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3803                                                        ox = (int) toLong(iax + ibx);
3804                                                        oai32data[it.oIndex + j] = ox;
3805                                                }
3806                                        }
3807                                } else {
3808                                        while (it.hasNext()) {
3809                                                long iax = it.aLong;
3810                                                long ibx = it.bLong;
3811                                                int ox;
3812                                                ox = (int) (iax + ibx);
3813                                                oai32data[it.oIndex] = ox;
3814                                                for (int j = 1; j < is; j++) {
3815                                                        iax = da.getElementLongAbs(it.aIndex + j);
3816                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3817                                                        ox = (int) (iax + ibx);
3818                                                        oai32data[it.oIndex + j] = ox;
3819                                                }
3820                                        }
3821                                }
3822                        }
3823                        break;
3824                case Dataset.FLOAT32:
3825                        final float[] of32data = ((FloatDataset) result).getData();
3826                        if (it.isOutputDouble()) {
3827                                while (it.hasNext()) {
3828                                        final double iax = it.aDouble;
3829                                        final double ibx = it.bDouble;
3830                                        float ox;
3831                                        ox = (float) (iax + ibx);
3832                                        of32data[it.oIndex] = ox;
3833                                }
3834                        } else {
3835                                while (it.hasNext()) {
3836                                        final long iax = it.aLong;
3837                                        final long ibx = it.bLong;
3838                                        float ox;
3839                                        ox = (iax + ibx);
3840                                        of32data[it.oIndex] = ox;
3841                                }
3842                        }
3843                        break;
3844                case Dataset.FLOAT64:
3845                        final double[] of64data = ((DoubleDataset) result).getData();
3846                        if (it.isOutputDouble()) {
3847                                while (it.hasNext()) {
3848                                        final double iax = it.aDouble;
3849                                        final double ibx = it.bDouble;
3850                                        double ox;
3851                                        ox = (iax + ibx);
3852                                        of64data[it.oIndex] = ox;
3853                                }
3854                        } else {
3855                                while (it.hasNext()) {
3856                                        final long iax = it.aLong;
3857                                        final long ibx = it.bLong;
3858                                        double ox;
3859                                        ox = (iax + ibx);
3860                                        of64data[it.oIndex] = ox;
3861                                }
3862                        }
3863                        break;
3864                case Dataset.ARRAYFLOAT32:
3865                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
3866                        if (is == 1) {
3867                                if (it.isOutputDouble()) {
3868                                        while (it.hasNext()) {
3869                                                final double iax = it.aDouble;
3870                                                final double ibx = it.bDouble;
3871                                                float ox;
3872                                                ox = (float) (iax + ibx);
3873                                                oaf32data[it.oIndex] = ox;
3874                                        }
3875                                } else {
3876                                        while (it.hasNext()) {
3877                                                final long iax = it.aLong;
3878                                                final long ibx = it.bLong;
3879                                                float ox;
3880                                                ox = (iax + ibx);
3881                                                oaf32data[it.oIndex] = ox;
3882                                        }
3883                                }
3884                        } else if (as < bs) {
3885                                if (it.isOutputDouble()) {
3886                                        while (it.hasNext()) {
3887                                                final double iax = it.aDouble;
3888                                                double ibx = it.bDouble;
3889                                                float ox;
3890                                                ox = (float) (iax + ibx);
3891                                                oaf32data[it.oIndex] = ox;
3892                                                for (int j = 1; j < is; j++) {
3893                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3894                                                        ox = (float) (iax + ibx);
3895                                                        oaf32data[it.oIndex + j] = ox;
3896                                                }
3897                                        }
3898                                } else {
3899                                        while (it.hasNext()) {
3900                                                final long iax = it.aLong;
3901                                                long ibx = it.bLong;
3902                                                float ox;
3903                                                ox = (iax + ibx);
3904                                                oaf32data[it.oIndex] = ox;
3905                                                for (int j = 1; j < is; j++) {
3906                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3907                                                        ox = (iax + ibx);
3908                                                        oaf32data[it.oIndex + j] = ox;
3909                                                }
3910                                        }
3911                                }
3912                        } else if (as > bs) {
3913                                if (it.isOutputDouble()) {
3914                                        while (it.hasNext()) {
3915                                                double iax = it.aDouble;
3916                                                final double ibx = it.bDouble;
3917                                                float ox;
3918                                                ox = (float) (iax + ibx);
3919                                                oaf32data[it.oIndex] = ox;
3920                                                for (int j = 1; j < is; j++) {
3921                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3922                                                        ox = (float) (iax + ibx);
3923                                                        oaf32data[it.oIndex + j] = ox;
3924                                                }
3925                                        }
3926                                } else {
3927                                        while (it.hasNext()) {
3928                                                long iax = it.aLong;
3929                                                final long ibx = it.bLong;
3930                                                float ox;
3931                                                ox = (iax + ibx);
3932                                                oaf32data[it.oIndex] = ox;
3933                                                for (int j = 1; j < is; j++) {
3934                                                        iax = da.getElementLongAbs(it.aIndex + j);
3935                                                        ox = (iax + ibx);
3936                                                        oaf32data[it.oIndex + j] = ox;
3937                                                }
3938                                        }
3939                                }
3940                        } else if (as == 1) {
3941                                if (it.isOutputDouble()) {
3942                                        while (it.hasNext()) {
3943                                                final double iax = it.aDouble;
3944                                                final double ibx = it.bDouble;
3945                                                float ox;
3946                                                ox = (float) (iax + ibx);
3947                                                for (int j = 0; j < is; j++) {
3948                                                        oaf32data[it.oIndex + j] = ox;
3949                                                }
3950                                        }
3951                                } else {
3952                                        while (it.hasNext()) {
3953                                                final long iax = it.aLong;
3954                                                final long ibx = it.bLong;
3955                                                float ox;
3956                                                ox = (iax + ibx);
3957                                                for (int j = 0; j < is; j++) {
3958                                                        oaf32data[it.oIndex + j] = ox;
3959                                                }
3960                                        }
3961                                }
3962                        } else {
3963                                if (it.isOutputDouble()) {
3964                                        while (it.hasNext()) {
3965                                                double iax = it.aDouble;
3966                                                double ibx = it.bDouble;
3967                                                float ox;
3968                                                ox = (float) (iax + ibx);
3969                                                oaf32data[it.oIndex] = ox;
3970                                                for (int j = 1; j < is; j++) {
3971                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
3972                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
3973                                                        ox = (float) (iax + ibx);
3974                                                        oaf32data[it.oIndex + j] = ox;
3975                                                }
3976                                        }
3977                                } else {
3978                                        while (it.hasNext()) {
3979                                                long iax = it.aLong;
3980                                                long ibx = it.bLong;
3981                                                float ox;
3982                                                ox = (iax + ibx);
3983                                                oaf32data[it.oIndex] = ox;
3984                                                for (int j = 1; j < is; j++) {
3985                                                        iax = da.getElementLongAbs(it.aIndex + j);
3986                                                        ibx = db.getElementLongAbs(it.bIndex + j);
3987                                                        ox = (iax + ibx);
3988                                                        oaf32data[it.oIndex + j] = ox;
3989                                                }
3990                                        }
3991                                }
3992                        }
3993                        break;
3994                case Dataset.ARRAYFLOAT64:
3995                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
3996                        if (is == 1) {
3997                                if (it.isOutputDouble()) {
3998                                        while (it.hasNext()) {
3999                                                final double iax = it.aDouble;
4000                                                final double ibx = it.bDouble;
4001                                                double ox;
4002                                                ox = (iax + ibx);
4003                                                oaf64data[it.oIndex] = ox;
4004                                        }
4005                                } else {
4006                                        while (it.hasNext()) {
4007                                                final long iax = it.aLong;
4008                                                final long ibx = it.bLong;
4009                                                double ox;
4010                                                ox = (iax + ibx);
4011                                                oaf64data[it.oIndex] = ox;
4012                                        }
4013                                }
4014                        } else if (as < bs) {
4015                                if (it.isOutputDouble()) {
4016                                        while (it.hasNext()) {
4017                                                final double iax = it.aDouble;
4018                                                double ibx = it.bDouble;
4019                                                double ox;
4020                                                ox = (iax + ibx);
4021                                                oaf64data[it.oIndex] = ox;
4022                                                for (int j = 1; j < is; j++) {
4023                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4024                                                        ox = (iax + ibx);
4025                                                        oaf64data[it.oIndex + j] = ox;
4026                                                }
4027                                        }
4028                                } else {
4029                                        while (it.hasNext()) {
4030                                                final long iax = it.aLong;
4031                                                long ibx = it.bLong;
4032                                                double ox;
4033                                                ox = (iax + ibx);
4034                                                oaf64data[it.oIndex] = ox;
4035                                                for (int j = 1; j < is; j++) {
4036                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4037                                                        ox = (iax + ibx);
4038                                                        oaf64data[it.oIndex + j] = ox;
4039                                                }
4040                                        }
4041                                }
4042                        } else if (as > bs) {
4043                                if (it.isOutputDouble()) {
4044                                        while (it.hasNext()) {
4045                                                double iax = it.aDouble;
4046                                                final double ibx = it.bDouble;
4047                                                double ox;
4048                                                ox = (iax + ibx);
4049                                                oaf64data[it.oIndex] = ox;
4050                                                for (int j = 1; j < is; j++) {
4051                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4052                                                        ox = (iax + ibx);
4053                                                        oaf64data[it.oIndex + j] = ox;
4054                                                }
4055                                        }
4056                                } else {
4057                                        while (it.hasNext()) {
4058                                                long iax = it.aLong;
4059                                                final long ibx = it.bLong;
4060                                                double ox;
4061                                                ox = (iax + ibx);
4062                                                oaf64data[it.oIndex] = ox;
4063                                                for (int j = 1; j < is; j++) {
4064                                                        iax = da.getElementLongAbs(it.aIndex + j);
4065                                                        ox = (iax + ibx);
4066                                                        oaf64data[it.oIndex + j] = ox;
4067                                                }
4068                                        }
4069                                }
4070                        } else if (as == 1) {
4071                                if (it.isOutputDouble()) {
4072                                        while (it.hasNext()) {
4073                                                final double iax = it.aDouble;
4074                                                final double ibx = it.bDouble;
4075                                                double ox;
4076                                                ox = (iax + ibx);
4077                                                for (int j = 0; j < is; j++) {
4078                                                        oaf64data[it.oIndex + j] = ox;
4079                                                }
4080                                        }
4081                                } else {
4082                                        while (it.hasNext()) {
4083                                                final long iax = it.aLong;
4084                                                final long ibx = it.bLong;
4085                                                double ox;
4086                                                ox = (iax + ibx);
4087                                                for (int j = 0; j < is; j++) {
4088                                                        oaf64data[it.oIndex + j] = ox;
4089                                                }
4090                                        }
4091                                }
4092                        } else {
4093                                if (it.isOutputDouble()) {
4094                                        while (it.hasNext()) {
4095                                                double iax = it.aDouble;
4096                                                double ibx = it.bDouble;
4097                                                double ox;
4098                                                ox = (iax + ibx);
4099                                                oaf64data[it.oIndex] = ox;
4100                                                for (int j = 1; j < is; j++) {
4101                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4102                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4103                                                        ox = (iax + ibx);
4104                                                        oaf64data[it.oIndex + j] = ox;
4105                                                }
4106                                        }
4107                                } else {
4108                                        while (it.hasNext()) {
4109                                                long iax = it.aLong;
4110                                                long ibx = it.bLong;
4111                                                double ox;
4112                                                ox = (iax + ibx);
4113                                                oaf64data[it.oIndex] = ox;
4114                                                for (int j = 1; j < is; j++) {
4115                                                        iax = da.getElementLongAbs(it.aIndex + j);
4116                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4117                                                        ox = (iax + ibx);
4118                                                        oaf64data[it.oIndex + j] = ox;
4119                                                }
4120                                        }
4121                                }
4122                        }
4123                        break;
4124                case Dataset.COMPLEX64:
4125                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
4126                        if (!da.isComplex()) {
4127                                if (it.isOutputDouble()) {
4128                                        final double iay = 0;
4129                                        if (db.isComplex()) {
4130                                                while (it.hasNext()) {
4131                                                        final double iax = it.aDouble;
4132                                                        final double ibx = it.bDouble;
4133                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
4134                                                        float ox;
4135                                                        float oy;
4136                                                        ox = (float) (iax + ibx);
4137                                                        oy = (float) (iay + iby);
4138                                                        oc64data[it.oIndex] = ox;
4139                                                        oc64data[it.oIndex + 1] = oy;
4140                                                }
4141                                        } else {
4142                                                while (it.hasNext()) {
4143                                                        final double iax = it.aDouble;
4144                                                        final double ibx = it.bDouble;
4145                                                        final double iby = 0;
4146                                                        float ox;
4147                                                        float oy;
4148                                                        ox = (float) (iax + ibx);
4149                                                        oy = (float) (iay + iby);
4150                                                        oc64data[it.oIndex] = ox;
4151                                                        oc64data[it.oIndex + 1] = oy;
4152                                                }
4153                                        }
4154                                } else {
4155                                        final long iay = 0;
4156                                        while (it.hasNext()) {
4157                                                final long iax = it.aLong;
4158                                                final long ibx = it.bLong;
4159                                                final long iby = 0;
4160                                                float ox;
4161                                                float oy;
4162                                                ox = (float) (iax + ibx);
4163                                                oy = (float) (iay + iby);
4164                                                oc64data[it.oIndex] = ox;
4165                                                oc64data[it.oIndex + 1] = oy;
4166                                        }
4167                                }
4168                        } else if (!db.isComplex()) {
4169                                final double iby = 0;
4170                                while (it.hasNext()) {
4171                                        final double iax = it.aDouble;
4172                                        final double ibx = it.bDouble;
4173                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
4174                                        float ox;
4175                                        float oy;
4176                                        ox = (float) (iax + ibx);
4177                                        oy = (float) (iay + iby);
4178                                        oc64data[it.oIndex] = ox;
4179                                        oc64data[it.oIndex + 1] = oy;
4180                                }
4181                        } else {
4182                                while (it.hasNext()) {
4183                                        final double iax = it.aDouble;
4184                                        final double ibx = it.bDouble;
4185                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
4186                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
4187                                        float ox;
4188                                        float oy;
4189                                        ox = (float) (iax + ibx);
4190                                        oy = (float) (iay + iby);
4191                                        oc64data[it.oIndex] = ox;
4192                                        oc64data[it.oIndex + 1] = oy;
4193                                }
4194                        }
4195                        break;
4196                case Dataset.COMPLEX128:
4197                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
4198                        if (!da.isComplex()) {
4199                                if (it.isOutputDouble()) {
4200                                        final double iay = 0;
4201                                        if (db.isComplex()) {
4202                                                while (it.hasNext()) {
4203                                                        final double iax = it.aDouble;
4204                                                        final double ibx = it.bDouble;
4205                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
4206                                                        double ox;
4207                                                        double oy;
4208                                                        ox = (iax + ibx);
4209                                                        oy = (iay + iby);
4210                                                        oc128data[it.oIndex] = ox;
4211                                                        oc128data[it.oIndex + 1] = oy;
4212                                                }
4213                                        } else {
4214                                                while (it.hasNext()) {
4215                                                        final double iax = it.aDouble;
4216                                                        final double ibx = it.bDouble;
4217                                                        final double iby = 0;
4218                                                        double ox;
4219                                                        double oy;
4220                                                        ox = (iax + ibx);
4221                                                        oy = (iay + iby);
4222                                                        oc128data[it.oIndex] = ox;
4223                                                        oc128data[it.oIndex + 1] = oy;
4224                                                }
4225                                        }
4226                                } else {
4227                                        final long iay = 0;
4228                                        while (it.hasNext()) {
4229                                                final long iax = it.aLong;
4230                                                final long ibx = it.bLong;
4231                                                final long iby = 0;
4232                                                double ox;
4233                                                double oy;
4234                                                ox = (iax + ibx);
4235                                                oy = (iay + iby);
4236                                                oc128data[it.oIndex] = ox;
4237                                                oc128data[it.oIndex + 1] = oy;
4238                                        }
4239                                }
4240                        } else if (!db.isComplex()) {
4241                                final double iby = 0;
4242                                while (it.hasNext()) {
4243                                        final double iax = it.aDouble;
4244                                        final double ibx = it.bDouble;
4245                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
4246                                        double ox;
4247                                        double oy;
4248                                        ox = (iax + ibx);
4249                                        oy = (iay + iby);
4250                                        oc128data[it.oIndex] = ox;
4251                                        oc128data[it.oIndex + 1] = oy;
4252                                }
4253                        } else {
4254                                while (it.hasNext()) {
4255                                        final double iax = it.aDouble;
4256                                        final double ibx = it.bDouble;
4257                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
4258                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
4259                                        double ox;
4260                                        double oy;
4261                                        ox = (iax + ibx);
4262                                        oy = (iay + iby);
4263                                        oc128data[it.oIndex] = ox;
4264                                        oc128data[it.oIndex + 1] = oy;
4265                                }
4266                        }
4267                        break;
4268                default:
4269                        throw new IllegalArgumentException("add supports integer, compound integer, real, compound real, complex datasets only");
4270                }
4271
4272                addBinaryOperatorName(da, db, result, "+");
4273                return result;
4274        }
4275
4276        /**
4277         * subtract operator
4278         * @param a first operand
4279         * @param b second operand
4280         * @return {@code a - b}, subtraction of a by b
4281         */
4282        public static Dataset subtract(final Object a, final Object b) {
4283                return subtract(a, b, null);
4284        }
4285
4286        /**
4287         * subtract operator
4288         * @param a first operand
4289         * @param b second operand
4290         * @param o output can be null - in which case, a new dataset is created
4291         * @return {@code a - b}, subtraction of a by b
4292         */
4293        public static Dataset subtract(final Object a, final Object b, final Dataset o) {
4294                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
4295                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
4296                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
4297                final Dataset result = it.getOutput();
4298                if (!result.isComplex()) {
4299                        boolean change = false;
4300                        if (da.isComplex()) {
4301                                da = da.getRealView();
4302                                change = true;
4303                        }
4304                        if (db.isComplex()) {
4305                                db = db.getRealView();
4306                                change = true;
4307                        }
4308                        if (change) {
4309                                it = BroadcastIterator.createIterator(da, db, result, true);
4310                        }
4311                }
4312                final int is = result.getElementsPerItem();
4313                final int as = da.getElementsPerItem();
4314                final int bs = db.getElementsPerItem();
4315                final int dt = result.getDType();
4316
4317                switch(dt) {
4318                case Dataset.INT8:
4319                        final byte[] oi8data = ((ByteDataset) result).getData();
4320                        if (it.isOutputDouble()) {
4321                                while (it.hasNext()) {
4322                                        final double iax = it.aDouble;
4323                                        final double ibx = it.bDouble;
4324                                        byte ox;
4325                                        ox = (byte) toLong(iax - ibx);
4326                                        oi8data[it.oIndex] = ox;
4327                                }
4328                        } else {
4329                                while (it.hasNext()) {
4330                                        final long iax = it.aLong;
4331                                        final long ibx = it.bLong;
4332                                        byte ox;
4333                                        ox = (byte) (iax - ibx);
4334                                        oi8data[it.oIndex] = ox;
4335                                }
4336                        }
4337                        break;
4338                case Dataset.INT16:
4339                        final short[] oi16data = ((ShortDataset) result).getData();
4340                        if (it.isOutputDouble()) {
4341                                while (it.hasNext()) {
4342                                        final double iax = it.aDouble;
4343                                        final double ibx = it.bDouble;
4344                                        short ox;
4345                                        ox = (short) toLong(iax - ibx);
4346                                        oi16data[it.oIndex] = ox;
4347                                }
4348                        } else {
4349                                while (it.hasNext()) {
4350                                        final long iax = it.aLong;
4351                                        final long ibx = it.bLong;
4352                                        short ox;
4353                                        ox = (short) (iax - ibx);
4354                                        oi16data[it.oIndex] = ox;
4355                                }
4356                        }
4357                        break;
4358                case Dataset.INT64:
4359                        final long[] oi64data = ((LongDataset) result).getData();
4360                        if (it.isOutputDouble()) {
4361                                while (it.hasNext()) {
4362                                        final double iax = it.aDouble;
4363                                        final double ibx = it.bDouble;
4364                                        long ox;
4365                                        ox = toLong(iax - ibx);
4366                                        oi64data[it.oIndex] = ox;
4367                                }
4368                        } else {
4369                                while (it.hasNext()) {
4370                                        final long iax = it.aLong;
4371                                        final long ibx = it.bLong;
4372                                        long ox;
4373                                        ox = (iax - ibx);
4374                                        oi64data[it.oIndex] = ox;
4375                                }
4376                        }
4377                        break;
4378                case Dataset.INT32:
4379                        final int[] oi32data = ((IntegerDataset) result).getData();
4380                        if (it.isOutputDouble()) {
4381                                while (it.hasNext()) {
4382                                        final double iax = it.aDouble;
4383                                        final double ibx = it.bDouble;
4384                                        int ox;
4385                                        ox = (int) toLong(iax - ibx);
4386                                        oi32data[it.oIndex] = ox;
4387                                }
4388                        } else {
4389                                while (it.hasNext()) {
4390                                        final long iax = it.aLong;
4391                                        final long ibx = it.bLong;
4392                                        int ox;
4393                                        ox = (int) (iax - ibx);
4394                                        oi32data[it.oIndex] = ox;
4395                                }
4396                        }
4397                        break;
4398                case Dataset.ARRAYINT8:
4399                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
4400                        if (is == 1) {
4401                                if (it.isOutputDouble()) {
4402                                        while (it.hasNext()) {
4403                                                final double iax = it.aDouble;
4404                                                final double ibx = it.bDouble;
4405                                                byte ox;
4406                                                ox = (byte) toLong(iax - ibx);
4407                                                oai8data[it.oIndex] = ox;
4408                                        }
4409                                } else {
4410                                        while (it.hasNext()) {
4411                                                final long iax = it.aLong;
4412                                                final long ibx = it.bLong;
4413                                                byte ox;
4414                                                ox = (byte) (iax - ibx);
4415                                                oai8data[it.oIndex] = ox;
4416                                        }
4417                                }
4418                        } else if (as < bs) {
4419                                if (it.isOutputDouble()) {
4420                                        while (it.hasNext()) {
4421                                                final double iax = it.aDouble;
4422                                                double ibx = it.bDouble;
4423                                                byte ox;
4424                                                ox = (byte) toLong(iax - ibx);
4425                                                oai8data[it.oIndex] = ox;
4426                                                for (int j = 1; j < is; j++) {
4427                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4428                                                        ox = (byte) toLong(iax - ibx);
4429                                                        oai8data[it.oIndex + j] = ox;
4430                                                }
4431                                        }
4432                                } else {
4433                                        while (it.hasNext()) {
4434                                                final long iax = it.aLong;
4435                                                long ibx = it.bLong;
4436                                                byte ox;
4437                                                ox = (byte) (iax - ibx);
4438                                                oai8data[it.oIndex] = ox;
4439                                                for (int j = 1; j < is; j++) {
4440                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4441                                                        ox = (byte) (iax - ibx);
4442                                                        oai8data[it.oIndex + j] = ox;
4443                                                }
4444                                        }
4445                                }
4446                        } else if (as > bs) {
4447                                if (it.isOutputDouble()) {
4448                                        while (it.hasNext()) {
4449                                                double iax = it.aDouble;
4450                                                final double ibx = it.bDouble;
4451                                                byte ox;
4452                                                ox = (byte) toLong(iax - ibx);
4453                                                oai8data[it.oIndex] = ox;
4454                                                for (int j = 1; j < is; j++) {
4455                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4456                                                        ox = (byte) toLong(iax - ibx);
4457                                                        oai8data[it.oIndex + j] = ox;
4458                                                }
4459                                        }
4460                                } else {
4461                                        while (it.hasNext()) {
4462                                                long iax = it.aLong;
4463                                                final long ibx = it.bLong;
4464                                                byte ox;
4465                                                ox = (byte) (iax - ibx);
4466                                                oai8data[it.oIndex] = ox;
4467                                                for (int j = 1; j < is; j++) {
4468                                                        iax = da.getElementLongAbs(it.aIndex + j);
4469                                                        ox = (byte) (iax - ibx);
4470                                                        oai8data[it.oIndex + j] = ox;
4471                                                }
4472                                        }
4473                                }
4474                        } else if (as == 1) {
4475                                if (it.isOutputDouble()) {
4476                                        while (it.hasNext()) {
4477                                                final double iax = it.aDouble;
4478                                                final double ibx = it.bDouble;
4479                                                byte ox;
4480                                                ox = (byte) toLong(iax - ibx);
4481                                                for (int j = 0; j < is; j++) {
4482                                                        oai8data[it.oIndex + j] = ox;
4483                                                }
4484                                        }
4485                                } else {
4486                                        while (it.hasNext()) {
4487                                                final long iax = it.aLong;
4488                                                final long ibx = it.bLong;
4489                                                byte ox;
4490                                                ox = (byte) (iax - ibx);
4491                                                for (int j = 0; j < is; j++) {
4492                                                        oai8data[it.oIndex + j] = ox;
4493                                                }
4494                                        }
4495                                }
4496                        } else {
4497                                if (it.isOutputDouble()) {
4498                                        while (it.hasNext()) {
4499                                                double iax = it.aDouble;
4500                                                double ibx = it.bDouble;
4501                                                byte ox;
4502                                                ox = (byte) toLong(iax - ibx);
4503                                                oai8data[it.oIndex] = ox;
4504                                                for (int j = 1; j < is; j++) {
4505                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4506                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4507                                                        ox = (byte) toLong(iax - ibx);
4508                                                        oai8data[it.oIndex + j] = ox;
4509                                                }
4510                                        }
4511                                } else {
4512                                        while (it.hasNext()) {
4513                                                long iax = it.aLong;
4514                                                long ibx = it.bLong;
4515                                                byte ox;
4516                                                ox = (byte) (iax - ibx);
4517                                                oai8data[it.oIndex] = ox;
4518                                                for (int j = 1; j < is; j++) {
4519                                                        iax = da.getElementLongAbs(it.aIndex + j);
4520                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4521                                                        ox = (byte) (iax - ibx);
4522                                                        oai8data[it.oIndex + j] = ox;
4523                                                }
4524                                        }
4525                                }
4526                        }
4527                        break;
4528                case Dataset.ARRAYINT16:
4529                        final short[] oai16data = ((CompoundShortDataset) result).getData();
4530                        if (is == 1) {
4531                                if (it.isOutputDouble()) {
4532                                        while (it.hasNext()) {
4533                                                final double iax = it.aDouble;
4534                                                final double ibx = it.bDouble;
4535                                                short ox;
4536                                                ox = (short) toLong(iax - ibx);
4537                                                oai16data[it.oIndex] = ox;
4538                                        }
4539                                } else {
4540                                        while (it.hasNext()) {
4541                                                final long iax = it.aLong;
4542                                                final long ibx = it.bLong;
4543                                                short ox;
4544                                                ox = (short) (iax - ibx);
4545                                                oai16data[it.oIndex] = ox;
4546                                        }
4547                                }
4548                        } else if (as < bs) {
4549                                if (it.isOutputDouble()) {
4550                                        while (it.hasNext()) {
4551                                                final double iax = it.aDouble;
4552                                                double ibx = it.bDouble;
4553                                                short ox;
4554                                                ox = (short) toLong(iax - ibx);
4555                                                oai16data[it.oIndex] = ox;
4556                                                for (int j = 1; j < is; j++) {
4557                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4558                                                        ox = (short) toLong(iax - ibx);
4559                                                        oai16data[it.oIndex + j] = ox;
4560                                                }
4561                                        }
4562                                } else {
4563                                        while (it.hasNext()) {
4564                                                final long iax = it.aLong;
4565                                                long ibx = it.bLong;
4566                                                short ox;
4567                                                ox = (short) (iax - ibx);
4568                                                oai16data[it.oIndex] = ox;
4569                                                for (int j = 1; j < is; j++) {
4570                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4571                                                        ox = (short) (iax - ibx);
4572                                                        oai16data[it.oIndex + j] = ox;
4573                                                }
4574                                        }
4575                                }
4576                        } else if (as > bs) {
4577                                if (it.isOutputDouble()) {
4578                                        while (it.hasNext()) {
4579                                                double iax = it.aDouble;
4580                                                final double ibx = it.bDouble;
4581                                                short ox;
4582                                                ox = (short) toLong(iax - ibx);
4583                                                oai16data[it.oIndex] = ox;
4584                                                for (int j = 1; j < is; j++) {
4585                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4586                                                        ox = (short) toLong(iax - ibx);
4587                                                        oai16data[it.oIndex + j] = ox;
4588                                                }
4589                                        }
4590                                } else {
4591                                        while (it.hasNext()) {
4592                                                long iax = it.aLong;
4593                                                final long ibx = it.bLong;
4594                                                short ox;
4595                                                ox = (short) (iax - ibx);
4596                                                oai16data[it.oIndex] = ox;
4597                                                for (int j = 1; j < is; j++) {
4598                                                        iax = da.getElementLongAbs(it.aIndex + j);
4599                                                        ox = (short) (iax - ibx);
4600                                                        oai16data[it.oIndex + j] = ox;
4601                                                }
4602                                        }
4603                                }
4604                        } else if (as == 1) {
4605                                if (it.isOutputDouble()) {
4606                                        while (it.hasNext()) {
4607                                                final double iax = it.aDouble;
4608                                                final double ibx = it.bDouble;
4609                                                short ox;
4610                                                ox = (short) toLong(iax - ibx);
4611                                                for (int j = 0; j < is; j++) {
4612                                                        oai16data[it.oIndex + j] = ox;
4613                                                }
4614                                        }
4615                                } else {
4616                                        while (it.hasNext()) {
4617                                                final long iax = it.aLong;
4618                                                final long ibx = it.bLong;
4619                                                short ox;
4620                                                ox = (short) (iax - ibx);
4621                                                for (int j = 0; j < is; j++) {
4622                                                        oai16data[it.oIndex + j] = ox;
4623                                                }
4624                                        }
4625                                }
4626                        } else {
4627                                if (it.isOutputDouble()) {
4628                                        while (it.hasNext()) {
4629                                                double iax = it.aDouble;
4630                                                double ibx = it.bDouble;
4631                                                short ox;
4632                                                ox = (short) toLong(iax - ibx);
4633                                                oai16data[it.oIndex] = ox;
4634                                                for (int j = 1; j < is; j++) {
4635                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4636                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4637                                                        ox = (short) toLong(iax - ibx);
4638                                                        oai16data[it.oIndex + j] = ox;
4639                                                }
4640                                        }
4641                                } else {
4642                                        while (it.hasNext()) {
4643                                                long iax = it.aLong;
4644                                                long ibx = it.bLong;
4645                                                short ox;
4646                                                ox = (short) (iax - ibx);
4647                                                oai16data[it.oIndex] = ox;
4648                                                for (int j = 1; j < is; j++) {
4649                                                        iax = da.getElementLongAbs(it.aIndex + j);
4650                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4651                                                        ox = (short) (iax - ibx);
4652                                                        oai16data[it.oIndex + j] = ox;
4653                                                }
4654                                        }
4655                                }
4656                        }
4657                        break;
4658                case Dataset.ARRAYINT64:
4659                        final long[] oai64data = ((CompoundLongDataset) result).getData();
4660                        if (is == 1) {
4661                                if (it.isOutputDouble()) {
4662                                        while (it.hasNext()) {
4663                                                final double iax = it.aDouble;
4664                                                final double ibx = it.bDouble;
4665                                                long ox;
4666                                                ox = toLong(iax - ibx);
4667                                                oai64data[it.oIndex] = ox;
4668                                        }
4669                                } else {
4670                                        while (it.hasNext()) {
4671                                                final long iax = it.aLong;
4672                                                final long ibx = it.bLong;
4673                                                long ox;
4674                                                ox = (iax - ibx);
4675                                                oai64data[it.oIndex] = ox;
4676                                        }
4677                                }
4678                        } else if (as < bs) {
4679                                if (it.isOutputDouble()) {
4680                                        while (it.hasNext()) {
4681                                                final double iax = it.aDouble;
4682                                                double ibx = it.bDouble;
4683                                                long ox;
4684                                                ox = toLong(iax - ibx);
4685                                                oai64data[it.oIndex] = ox;
4686                                                for (int j = 1; j < is; j++) {
4687                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4688                                                        ox = toLong(iax - ibx);
4689                                                        oai64data[it.oIndex + j] = ox;
4690                                                }
4691                                        }
4692                                } else {
4693                                        while (it.hasNext()) {
4694                                                final long iax = it.aLong;
4695                                                long ibx = it.bLong;
4696                                                long ox;
4697                                                ox = (iax - ibx);
4698                                                oai64data[it.oIndex] = ox;
4699                                                for (int j = 1; j < is; j++) {
4700                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4701                                                        ox = (iax - ibx);
4702                                                        oai64data[it.oIndex + j] = ox;
4703                                                }
4704                                        }
4705                                }
4706                        } else if (as > bs) {
4707                                if (it.isOutputDouble()) {
4708                                        while (it.hasNext()) {
4709                                                double iax = it.aDouble;
4710                                                final double ibx = it.bDouble;
4711                                                long ox;
4712                                                ox = toLong(iax - ibx);
4713                                                oai64data[it.oIndex] = ox;
4714                                                for (int j = 1; j < is; j++) {
4715                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4716                                                        ox = toLong(iax - ibx);
4717                                                        oai64data[it.oIndex + j] = ox;
4718                                                }
4719                                        }
4720                                } else {
4721                                        while (it.hasNext()) {
4722                                                long iax = it.aLong;
4723                                                final long ibx = it.bLong;
4724                                                long ox;
4725                                                ox = (iax - ibx);
4726                                                oai64data[it.oIndex] = ox;
4727                                                for (int j = 1; j < is; j++) {
4728                                                        iax = da.getElementLongAbs(it.aIndex + j);
4729                                                        ox = (iax - ibx);
4730                                                        oai64data[it.oIndex + j] = ox;
4731                                                }
4732                                        }
4733                                }
4734                        } else if (as == 1) {
4735                                if (it.isOutputDouble()) {
4736                                        while (it.hasNext()) {
4737                                                final double iax = it.aDouble;
4738                                                final double ibx = it.bDouble;
4739                                                long ox;
4740                                                ox = toLong(iax - ibx);
4741                                                for (int j = 0; j < is; j++) {
4742                                                        oai64data[it.oIndex + j] = ox;
4743                                                }
4744                                        }
4745                                } else {
4746                                        while (it.hasNext()) {
4747                                                final long iax = it.aLong;
4748                                                final long ibx = it.bLong;
4749                                                long ox;
4750                                                ox = (iax - ibx);
4751                                                for (int j = 0; j < is; j++) {
4752                                                        oai64data[it.oIndex + j] = ox;
4753                                                }
4754                                        }
4755                                }
4756                        } else {
4757                                if (it.isOutputDouble()) {
4758                                        while (it.hasNext()) {
4759                                                double iax = it.aDouble;
4760                                                double ibx = it.bDouble;
4761                                                long ox;
4762                                                ox = toLong(iax - ibx);
4763                                                oai64data[it.oIndex] = ox;
4764                                                for (int j = 1; j < is; j++) {
4765                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4766                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4767                                                        ox = toLong(iax - ibx);
4768                                                        oai64data[it.oIndex + j] = ox;
4769                                                }
4770                                        }
4771                                } else {
4772                                        while (it.hasNext()) {
4773                                                long iax = it.aLong;
4774                                                long ibx = it.bLong;
4775                                                long ox;
4776                                                ox = (iax - ibx);
4777                                                oai64data[it.oIndex] = ox;
4778                                                for (int j = 1; j < is; j++) {
4779                                                        iax = da.getElementLongAbs(it.aIndex + j);
4780                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4781                                                        ox = (iax - ibx);
4782                                                        oai64data[it.oIndex + j] = ox;
4783                                                }
4784                                        }
4785                                }
4786                        }
4787                        break;
4788                case Dataset.ARRAYINT32:
4789                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
4790                        if (is == 1) {
4791                                if (it.isOutputDouble()) {
4792                                        while (it.hasNext()) {
4793                                                final double iax = it.aDouble;
4794                                                final double ibx = it.bDouble;
4795                                                int ox;
4796                                                ox = (int) toLong(iax - ibx);
4797                                                oai32data[it.oIndex] = ox;
4798                                        }
4799                                } else {
4800                                        while (it.hasNext()) {
4801                                                final long iax = it.aLong;
4802                                                final long ibx = it.bLong;
4803                                                int ox;
4804                                                ox = (int) (iax - ibx);
4805                                                oai32data[it.oIndex] = ox;
4806                                        }
4807                                }
4808                        } else if (as < bs) {
4809                                if (it.isOutputDouble()) {
4810                                        while (it.hasNext()) {
4811                                                final double iax = it.aDouble;
4812                                                double ibx = it.bDouble;
4813                                                int ox;
4814                                                ox = (int) toLong(iax - ibx);
4815                                                oai32data[it.oIndex] = ox;
4816                                                for (int j = 1; j < is; j++) {
4817                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4818                                                        ox = (int) toLong(iax - ibx);
4819                                                        oai32data[it.oIndex + j] = ox;
4820                                                }
4821                                        }
4822                                } else {
4823                                        while (it.hasNext()) {
4824                                                final long iax = it.aLong;
4825                                                long ibx = it.bLong;
4826                                                int ox;
4827                                                ox = (int) (iax - ibx);
4828                                                oai32data[it.oIndex] = ox;
4829                                                for (int j = 1; j < is; j++) {
4830                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4831                                                        ox = (int) (iax - ibx);
4832                                                        oai32data[it.oIndex + j] = ox;
4833                                                }
4834                                        }
4835                                }
4836                        } else if (as > bs) {
4837                                if (it.isOutputDouble()) {
4838                                        while (it.hasNext()) {
4839                                                double iax = it.aDouble;
4840                                                final double ibx = it.bDouble;
4841                                                int ox;
4842                                                ox = (int) toLong(iax - ibx);
4843                                                oai32data[it.oIndex] = ox;
4844                                                for (int j = 1; j < is; j++) {
4845                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4846                                                        ox = (int) toLong(iax - ibx);
4847                                                        oai32data[it.oIndex + j] = ox;
4848                                                }
4849                                        }
4850                                } else {
4851                                        while (it.hasNext()) {
4852                                                long iax = it.aLong;
4853                                                final long ibx = it.bLong;
4854                                                int ox;
4855                                                ox = (int) (iax - ibx);
4856                                                oai32data[it.oIndex] = ox;
4857                                                for (int j = 1; j < is; j++) {
4858                                                        iax = da.getElementLongAbs(it.aIndex + j);
4859                                                        ox = (int) (iax - ibx);
4860                                                        oai32data[it.oIndex + j] = ox;
4861                                                }
4862                                        }
4863                                }
4864                        } else if (as == 1) {
4865                                if (it.isOutputDouble()) {
4866                                        while (it.hasNext()) {
4867                                                final double iax = it.aDouble;
4868                                                final double ibx = it.bDouble;
4869                                                int ox;
4870                                                ox = (int) toLong(iax - ibx);
4871                                                for (int j = 0; j < is; j++) {
4872                                                        oai32data[it.oIndex + j] = ox;
4873                                                }
4874                                        }
4875                                } else {
4876                                        while (it.hasNext()) {
4877                                                final long iax = it.aLong;
4878                                                final long ibx = it.bLong;
4879                                                int ox;
4880                                                ox = (int) (iax - ibx);
4881                                                for (int j = 0; j < is; j++) {
4882                                                        oai32data[it.oIndex + j] = ox;
4883                                                }
4884                                        }
4885                                }
4886                        } else {
4887                                if (it.isOutputDouble()) {
4888                                        while (it.hasNext()) {
4889                                                double iax = it.aDouble;
4890                                                double ibx = it.bDouble;
4891                                                int ox;
4892                                                ox = (int) toLong(iax - ibx);
4893                                                oai32data[it.oIndex] = ox;
4894                                                for (int j = 1; j < is; j++) {
4895                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
4896                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4897                                                        ox = (int) toLong(iax - ibx);
4898                                                        oai32data[it.oIndex + j] = ox;
4899                                                }
4900                                        }
4901                                } else {
4902                                        while (it.hasNext()) {
4903                                                long iax = it.aLong;
4904                                                long ibx = it.bLong;
4905                                                int ox;
4906                                                ox = (int) (iax - ibx);
4907                                                oai32data[it.oIndex] = ox;
4908                                                for (int j = 1; j < is; j++) {
4909                                                        iax = da.getElementLongAbs(it.aIndex + j);
4910                                                        ibx = db.getElementLongAbs(it.bIndex + j);
4911                                                        ox = (int) (iax - ibx);
4912                                                        oai32data[it.oIndex + j] = ox;
4913                                                }
4914                                        }
4915                                }
4916                        }
4917                        break;
4918                case Dataset.FLOAT32:
4919                        final float[] of32data = ((FloatDataset) result).getData();
4920                        if (it.isOutputDouble()) {
4921                                while (it.hasNext()) {
4922                                        final double iax = it.aDouble;
4923                                        final double ibx = it.bDouble;
4924                                        float ox;
4925                                        ox = (float) (iax - ibx);
4926                                        of32data[it.oIndex] = ox;
4927                                }
4928                        } else {
4929                                while (it.hasNext()) {
4930                                        final long iax = it.aLong;
4931                                        final long ibx = it.bLong;
4932                                        float ox;
4933                                        ox = (iax - ibx);
4934                                        of32data[it.oIndex] = ox;
4935                                }
4936                        }
4937                        break;
4938                case Dataset.FLOAT64:
4939                        final double[] of64data = ((DoubleDataset) result).getData();
4940                        if (it.isOutputDouble()) {
4941                                while (it.hasNext()) {
4942                                        final double iax = it.aDouble;
4943                                        final double ibx = it.bDouble;
4944                                        double ox;
4945                                        ox = (iax - ibx);
4946                                        of64data[it.oIndex] = ox;
4947                                }
4948                        } else {
4949                                while (it.hasNext()) {
4950                                        final long iax = it.aLong;
4951                                        final long ibx = it.bLong;
4952                                        double ox;
4953                                        ox = (iax - ibx);
4954                                        of64data[it.oIndex] = ox;
4955                                }
4956                        }
4957                        break;
4958                case Dataset.ARRAYFLOAT32:
4959                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
4960                        if (is == 1) {
4961                                if (it.isOutputDouble()) {
4962                                        while (it.hasNext()) {
4963                                                final double iax = it.aDouble;
4964                                                final double ibx = it.bDouble;
4965                                                float ox;
4966                                                ox = (float) (iax - ibx);
4967                                                oaf32data[it.oIndex] = ox;
4968                                        }
4969                                } else {
4970                                        while (it.hasNext()) {
4971                                                final long iax = it.aLong;
4972                                                final long ibx = it.bLong;
4973                                                float ox;
4974                                                ox = (iax - ibx);
4975                                                oaf32data[it.oIndex] = ox;
4976                                        }
4977                                }
4978                        } else if (as < bs) {
4979                                if (it.isOutputDouble()) {
4980                                        while (it.hasNext()) {
4981                                                final double iax = it.aDouble;
4982                                                double ibx = it.bDouble;
4983                                                float ox;
4984                                                ox = (float) (iax - ibx);
4985                                                oaf32data[it.oIndex] = ox;
4986                                                for (int j = 1; j < is; j++) {
4987                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
4988                                                        ox = (float) (iax - ibx);
4989                                                        oaf32data[it.oIndex + j] = ox;
4990                                                }
4991                                        }
4992                                } else {
4993                                        while (it.hasNext()) {
4994                                                final long iax = it.aLong;
4995                                                long ibx = it.bLong;
4996                                                float ox;
4997                                                ox = (iax - ibx);
4998                                                oaf32data[it.oIndex] = ox;
4999                                                for (int j = 1; j < is; j++) {
5000                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5001                                                        ox = (iax - ibx);
5002                                                        oaf32data[it.oIndex + j] = ox;
5003                                                }
5004                                        }
5005                                }
5006                        } else if (as > bs) {
5007                                if (it.isOutputDouble()) {
5008                                        while (it.hasNext()) {
5009                                                double iax = it.aDouble;
5010                                                final double ibx = it.bDouble;
5011                                                float ox;
5012                                                ox = (float) (iax - ibx);
5013                                                oaf32data[it.oIndex] = ox;
5014                                                for (int j = 1; j < is; j++) {
5015                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5016                                                        ox = (float) (iax - ibx);
5017                                                        oaf32data[it.oIndex + j] = ox;
5018                                                }
5019                                        }
5020                                } else {
5021                                        while (it.hasNext()) {
5022                                                long iax = it.aLong;
5023                                                final long ibx = it.bLong;
5024                                                float ox;
5025                                                ox = (iax - ibx);
5026                                                oaf32data[it.oIndex] = ox;
5027                                                for (int j = 1; j < is; j++) {
5028                                                        iax = da.getElementLongAbs(it.aIndex + j);
5029                                                        ox = (iax - ibx);
5030                                                        oaf32data[it.oIndex + j] = ox;
5031                                                }
5032                                        }
5033                                }
5034                        } else if (as == 1) {
5035                                if (it.isOutputDouble()) {
5036                                        while (it.hasNext()) {
5037                                                final double iax = it.aDouble;
5038                                                final double ibx = it.bDouble;
5039                                                float ox;
5040                                                ox = (float) (iax - ibx);
5041                                                for (int j = 0; j < is; j++) {
5042                                                        oaf32data[it.oIndex + j] = ox;
5043                                                }
5044                                        }
5045                                } else {
5046                                        while (it.hasNext()) {
5047                                                final long iax = it.aLong;
5048                                                final long ibx = it.bLong;
5049                                                float ox;
5050                                                ox = (iax - ibx);
5051                                                for (int j = 0; j < is; j++) {
5052                                                        oaf32data[it.oIndex + j] = ox;
5053                                                }
5054                                        }
5055                                }
5056                        } else {
5057                                if (it.isOutputDouble()) {
5058                                        while (it.hasNext()) {
5059                                                double iax = it.aDouble;
5060                                                double ibx = it.bDouble;
5061                                                float ox;
5062                                                ox = (float) (iax - ibx);
5063                                                oaf32data[it.oIndex] = ox;
5064                                                for (int j = 1; j < is; j++) {
5065                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5066                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5067                                                        ox = (float) (iax - ibx);
5068                                                        oaf32data[it.oIndex + j] = ox;
5069                                                }
5070                                        }
5071                                } else {
5072                                        while (it.hasNext()) {
5073                                                long iax = it.aLong;
5074                                                long ibx = it.bLong;
5075                                                float ox;
5076                                                ox = (iax - ibx);
5077                                                oaf32data[it.oIndex] = ox;
5078                                                for (int j = 1; j < is; j++) {
5079                                                        iax = da.getElementLongAbs(it.aIndex + j);
5080                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5081                                                        ox = (iax - ibx);
5082                                                        oaf32data[it.oIndex + j] = ox;
5083                                                }
5084                                        }
5085                                }
5086                        }
5087                        break;
5088                case Dataset.ARRAYFLOAT64:
5089                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
5090                        if (is == 1) {
5091                                if (it.isOutputDouble()) {
5092                                        while (it.hasNext()) {
5093                                                final double iax = it.aDouble;
5094                                                final double ibx = it.bDouble;
5095                                                double ox;
5096                                                ox = (iax - ibx);
5097                                                oaf64data[it.oIndex] = ox;
5098                                        }
5099                                } else {
5100                                        while (it.hasNext()) {
5101                                                final long iax = it.aLong;
5102                                                final long ibx = it.bLong;
5103                                                double ox;
5104                                                ox = (iax - ibx);
5105                                                oaf64data[it.oIndex] = ox;
5106                                        }
5107                                }
5108                        } else if (as < bs) {
5109                                if (it.isOutputDouble()) {
5110                                        while (it.hasNext()) {
5111                                                final double iax = it.aDouble;
5112                                                double ibx = it.bDouble;
5113                                                double ox;
5114                                                ox = (iax - ibx);
5115                                                oaf64data[it.oIndex] = ox;
5116                                                for (int j = 1; j < is; j++) {
5117                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5118                                                        ox = (iax - ibx);
5119                                                        oaf64data[it.oIndex + j] = ox;
5120                                                }
5121                                        }
5122                                } else {
5123                                        while (it.hasNext()) {
5124                                                final long iax = it.aLong;
5125                                                long ibx = it.bLong;
5126                                                double ox;
5127                                                ox = (iax - ibx);
5128                                                oaf64data[it.oIndex] = ox;
5129                                                for (int j = 1; j < is; j++) {
5130                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5131                                                        ox = (iax - ibx);
5132                                                        oaf64data[it.oIndex + j] = ox;
5133                                                }
5134                                        }
5135                                }
5136                        } else if (as > bs) {
5137                                if (it.isOutputDouble()) {
5138                                        while (it.hasNext()) {
5139                                                double iax = it.aDouble;
5140                                                final double ibx = it.bDouble;
5141                                                double ox;
5142                                                ox = (iax - ibx);
5143                                                oaf64data[it.oIndex] = ox;
5144                                                for (int j = 1; j < is; j++) {
5145                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5146                                                        ox = (iax - ibx);
5147                                                        oaf64data[it.oIndex + j] = ox;
5148                                                }
5149                                        }
5150                                } else {
5151                                        while (it.hasNext()) {
5152                                                long iax = it.aLong;
5153                                                final long ibx = it.bLong;
5154                                                double ox;
5155                                                ox = (iax - ibx);
5156                                                oaf64data[it.oIndex] = ox;
5157                                                for (int j = 1; j < is; j++) {
5158                                                        iax = da.getElementLongAbs(it.aIndex + j);
5159                                                        ox = (iax - ibx);
5160                                                        oaf64data[it.oIndex + j] = ox;
5161                                                }
5162                                        }
5163                                }
5164                        } else if (as == 1) {
5165                                if (it.isOutputDouble()) {
5166                                        while (it.hasNext()) {
5167                                                final double iax = it.aDouble;
5168                                                final double ibx = it.bDouble;
5169                                                double ox;
5170                                                ox = (iax - ibx);
5171                                                for (int j = 0; j < is; j++) {
5172                                                        oaf64data[it.oIndex + j] = ox;
5173                                                }
5174                                        }
5175                                } else {
5176                                        while (it.hasNext()) {
5177                                                final long iax = it.aLong;
5178                                                final long ibx = it.bLong;
5179                                                double ox;
5180                                                ox = (iax - ibx);
5181                                                for (int j = 0; j < is; j++) {
5182                                                        oaf64data[it.oIndex + j] = ox;
5183                                                }
5184                                        }
5185                                }
5186                        } else {
5187                                if (it.isOutputDouble()) {
5188                                        while (it.hasNext()) {
5189                                                double iax = it.aDouble;
5190                                                double ibx = it.bDouble;
5191                                                double ox;
5192                                                ox = (iax - ibx);
5193                                                oaf64data[it.oIndex] = ox;
5194                                                for (int j = 1; j < is; j++) {
5195                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5196                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5197                                                        ox = (iax - ibx);
5198                                                        oaf64data[it.oIndex + j] = ox;
5199                                                }
5200                                        }
5201                                } else {
5202                                        while (it.hasNext()) {
5203                                                long iax = it.aLong;
5204                                                long ibx = it.bLong;
5205                                                double ox;
5206                                                ox = (iax - ibx);
5207                                                oaf64data[it.oIndex] = ox;
5208                                                for (int j = 1; j < is; j++) {
5209                                                        iax = da.getElementLongAbs(it.aIndex + j);
5210                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5211                                                        ox = (iax - ibx);
5212                                                        oaf64data[it.oIndex + j] = ox;
5213                                                }
5214                                        }
5215                                }
5216                        }
5217                        break;
5218                case Dataset.COMPLEX64:
5219                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
5220                        if (!da.isComplex()) {
5221                                if (it.isOutputDouble()) {
5222                                        final double iay = 0;
5223                                        if (db.isComplex()) {
5224                                                while (it.hasNext()) {
5225                                                        final double iax = it.aDouble;
5226                                                        final double ibx = it.bDouble;
5227                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
5228                                                        float ox;
5229                                                        float oy;
5230                                                        ox = (float) (iax - ibx);
5231                                                        oy = (float) (iay - iby);
5232                                                        oc64data[it.oIndex] = ox;
5233                                                        oc64data[it.oIndex + 1] = oy;
5234                                                }
5235                                        } else {
5236                                                while (it.hasNext()) {
5237                                                        final double iax = it.aDouble;
5238                                                        final double ibx = it.bDouble;
5239                                                        final double iby = 0;
5240                                                        float ox;
5241                                                        float oy;
5242                                                        ox = (float) (iax - ibx);
5243                                                        oy = (float) (iay - iby);
5244                                                        oc64data[it.oIndex] = ox;
5245                                                        oc64data[it.oIndex + 1] = oy;
5246                                                }
5247                                        }
5248                                } else {
5249                                        final long iay = 0;
5250                                        while (it.hasNext()) {
5251                                                final long iax = it.aLong;
5252                                                final long ibx = it.bLong;
5253                                                final long iby = 0;
5254                                                float ox;
5255                                                float oy;
5256                                                ox = (float) (iax - ibx);
5257                                                oy = (float) (iay - iby);
5258                                                oc64data[it.oIndex] = ox;
5259                                                oc64data[it.oIndex + 1] = oy;
5260                                        }
5261                                }
5262                        } else if (!db.isComplex()) {
5263                                final double iby = 0;
5264                                while (it.hasNext()) {
5265                                        final double iax = it.aDouble;
5266                                        final double ibx = it.bDouble;
5267                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
5268                                        float ox;
5269                                        float oy;
5270                                        ox = (float) (iax - ibx);
5271                                        oy = (float) (iay - iby);
5272                                        oc64data[it.oIndex] = ox;
5273                                        oc64data[it.oIndex + 1] = oy;
5274                                }
5275                        } else {
5276                                while (it.hasNext()) {
5277                                        final double iax = it.aDouble;
5278                                        final double ibx = it.bDouble;
5279                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
5280                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
5281                                        float ox;
5282                                        float oy;
5283                                        ox = (float) (iax - ibx);
5284                                        oy = (float) (iay - iby);
5285                                        oc64data[it.oIndex] = ox;
5286                                        oc64data[it.oIndex + 1] = oy;
5287                                }
5288                        }
5289                        break;
5290                case Dataset.COMPLEX128:
5291                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
5292                        if (!da.isComplex()) {
5293                                if (it.isOutputDouble()) {
5294                                        final double iay = 0;
5295                                        if (db.isComplex()) {
5296                                                while (it.hasNext()) {
5297                                                        final double iax = it.aDouble;
5298                                                        final double ibx = it.bDouble;
5299                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
5300                                                        double ox;
5301                                                        double oy;
5302                                                        ox = (iax - ibx);
5303                                                        oy = (iay - iby);
5304                                                        oc128data[it.oIndex] = ox;
5305                                                        oc128data[it.oIndex + 1] = oy;
5306                                                }
5307                                        } else {
5308                                                while (it.hasNext()) {
5309                                                        final double iax = it.aDouble;
5310                                                        final double ibx = it.bDouble;
5311                                                        final double iby = 0;
5312                                                        double ox;
5313                                                        double oy;
5314                                                        ox = (iax - ibx);
5315                                                        oy = (iay - iby);
5316                                                        oc128data[it.oIndex] = ox;
5317                                                        oc128data[it.oIndex + 1] = oy;
5318                                                }
5319                                        }
5320                                } else {
5321                                        final long iay = 0;
5322                                        while (it.hasNext()) {
5323                                                final long iax = it.aLong;
5324                                                final long ibx = it.bLong;
5325                                                final long iby = 0;
5326                                                double ox;
5327                                                double oy;
5328                                                ox = (iax - ibx);
5329                                                oy = (iay - iby);
5330                                                oc128data[it.oIndex] = ox;
5331                                                oc128data[it.oIndex + 1] = oy;
5332                                        }
5333                                }
5334                        } else if (!db.isComplex()) {
5335                                final double iby = 0;
5336                                while (it.hasNext()) {
5337                                        final double iax = it.aDouble;
5338                                        final double ibx = it.bDouble;
5339                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
5340                                        double ox;
5341                                        double oy;
5342                                        ox = (iax - ibx);
5343                                        oy = (iay - iby);
5344                                        oc128data[it.oIndex] = ox;
5345                                        oc128data[it.oIndex + 1] = oy;
5346                                }
5347                        } else {
5348                                while (it.hasNext()) {
5349                                        final double iax = it.aDouble;
5350                                        final double ibx = it.bDouble;
5351                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
5352                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
5353                                        double ox;
5354                                        double oy;
5355                                        ox = (iax - ibx);
5356                                        oy = (iay - iby);
5357                                        oc128data[it.oIndex] = ox;
5358                                        oc128data[it.oIndex + 1] = oy;
5359                                }
5360                        }
5361                        break;
5362                default:
5363                        throw new IllegalArgumentException("subtract supports integer, compound integer, real, compound real, complex datasets only");
5364                }
5365
5366                addBinaryOperatorName(da, db, result, "-");
5367                return result;
5368        }
5369
5370        /**
5371         * multiply operator
5372         * @param a first operand
5373         * @param b second operand
5374         * @return {@code a * b}, product of a and b
5375         */
5376        public static Dataset multiply(final Object a, final Object b) {
5377                return multiply(a, b, null);
5378        }
5379
5380        /**
5381         * multiply operator
5382         * @param a first operand
5383         * @param b second operand
5384         * @param o output can be null - in which case, a new dataset is created
5385         * @return {@code a * b}, product of a and b
5386         */
5387        public static Dataset multiply(final Object a, final Object b, final Dataset o) {
5388                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
5389                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
5390                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
5391                final Dataset result = it.getOutput();
5392                if (!result.isComplex()) {
5393                        boolean change = false;
5394                        if (da.isComplex()) {
5395                                da = da.getRealView();
5396                                change = true;
5397                        }
5398                        if (db.isComplex()) {
5399                                db = db.getRealView();
5400                                change = true;
5401                        }
5402                        if (change) {
5403                                it = BroadcastIterator.createIterator(da, db, result, true);
5404                        }
5405                }
5406                final int is = result.getElementsPerItem();
5407                final int as = da.getElementsPerItem();
5408                final int bs = db.getElementsPerItem();
5409                final int dt = result.getDType();
5410
5411                switch(dt) {
5412                case Dataset.INT8:
5413                        final byte[] oi8data = ((ByteDataset) result).getData();
5414                        if (it.isOutputDouble()) {
5415                                while (it.hasNext()) {
5416                                        final double iax = it.aDouble;
5417                                        final double ibx = it.bDouble;
5418                                        byte ox;
5419                                        ox = (byte) toLong(iax * ibx);
5420                                        oi8data[it.oIndex] = ox;
5421                                }
5422                        } else {
5423                                while (it.hasNext()) {
5424                                        final long iax = it.aLong;
5425                                        final long ibx = it.bLong;
5426                                        byte ox;
5427                                        ox = (byte) (iax * ibx);
5428                                        oi8data[it.oIndex] = ox;
5429                                }
5430                        }
5431                        break;
5432                case Dataset.INT16:
5433                        final short[] oi16data = ((ShortDataset) result).getData();
5434                        if (it.isOutputDouble()) {
5435                                while (it.hasNext()) {
5436                                        final double iax = it.aDouble;
5437                                        final double ibx = it.bDouble;
5438                                        short ox;
5439                                        ox = (short) toLong(iax * ibx);
5440                                        oi16data[it.oIndex] = ox;
5441                                }
5442                        } else {
5443                                while (it.hasNext()) {
5444                                        final long iax = it.aLong;
5445                                        final long ibx = it.bLong;
5446                                        short ox;
5447                                        ox = (short) (iax * ibx);
5448                                        oi16data[it.oIndex] = ox;
5449                                }
5450                        }
5451                        break;
5452                case Dataset.INT64:
5453                        final long[] oi64data = ((LongDataset) result).getData();
5454                        if (it.isOutputDouble()) {
5455                                while (it.hasNext()) {
5456                                        final double iax = it.aDouble;
5457                                        final double ibx = it.bDouble;
5458                                        long ox;
5459                                        ox = toLong(iax * ibx);
5460                                        oi64data[it.oIndex] = ox;
5461                                }
5462                        } else {
5463                                while (it.hasNext()) {
5464                                        final long iax = it.aLong;
5465                                        final long ibx = it.bLong;
5466                                        long ox;
5467                                        ox = (iax * ibx);
5468                                        oi64data[it.oIndex] = ox;
5469                                }
5470                        }
5471                        break;
5472                case Dataset.INT32:
5473                        final int[] oi32data = ((IntegerDataset) result).getData();
5474                        if (it.isOutputDouble()) {
5475                                while (it.hasNext()) {
5476                                        final double iax = it.aDouble;
5477                                        final double ibx = it.bDouble;
5478                                        int ox;
5479                                        ox = (int) toLong(iax * ibx);
5480                                        oi32data[it.oIndex] = ox;
5481                                }
5482                        } else {
5483                                while (it.hasNext()) {
5484                                        final long iax = it.aLong;
5485                                        final long ibx = it.bLong;
5486                                        int ox;
5487                                        ox = (int) (iax * ibx);
5488                                        oi32data[it.oIndex] = ox;
5489                                }
5490                        }
5491                        break;
5492                case Dataset.ARRAYINT8:
5493                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
5494                        if (is == 1) {
5495                                if (it.isOutputDouble()) {
5496                                        while (it.hasNext()) {
5497                                                final double iax = it.aDouble;
5498                                                final double ibx = it.bDouble;
5499                                                byte ox;
5500                                                ox = (byte) toLong(iax * ibx);
5501                                                oai8data[it.oIndex] = ox;
5502                                        }
5503                                } else {
5504                                        while (it.hasNext()) {
5505                                                final long iax = it.aLong;
5506                                                final long ibx = it.bLong;
5507                                                byte ox;
5508                                                ox = (byte) (iax * ibx);
5509                                                oai8data[it.oIndex] = ox;
5510                                        }
5511                                }
5512                        } else if (as < bs) {
5513                                if (it.isOutputDouble()) {
5514                                        while (it.hasNext()) {
5515                                                final double iax = it.aDouble;
5516                                                double ibx = it.bDouble;
5517                                                byte ox;
5518                                                ox = (byte) toLong(iax * ibx);
5519                                                oai8data[it.oIndex] = ox;
5520                                                for (int j = 1; j < is; j++) {
5521                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5522                                                        ox = (byte) toLong(iax * ibx);
5523                                                        oai8data[it.oIndex + j] = ox;
5524                                                }
5525                                        }
5526                                } else {
5527                                        while (it.hasNext()) {
5528                                                final long iax = it.aLong;
5529                                                long ibx = it.bLong;
5530                                                byte ox;
5531                                                ox = (byte) (iax * ibx);
5532                                                oai8data[it.oIndex] = ox;
5533                                                for (int j = 1; j < is; j++) {
5534                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5535                                                        ox = (byte) (iax * ibx);
5536                                                        oai8data[it.oIndex + j] = ox;
5537                                                }
5538                                        }
5539                                }
5540                        } else if (as > bs) {
5541                                if (it.isOutputDouble()) {
5542                                        while (it.hasNext()) {
5543                                                double iax = it.aDouble;
5544                                                final double ibx = it.bDouble;
5545                                                byte ox;
5546                                                ox = (byte) toLong(iax * ibx);
5547                                                oai8data[it.oIndex] = ox;
5548                                                for (int j = 1; j < is; j++) {
5549                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5550                                                        ox = (byte) toLong(iax * ibx);
5551                                                        oai8data[it.oIndex + j] = ox;
5552                                                }
5553                                        }
5554                                } else {
5555                                        while (it.hasNext()) {
5556                                                long iax = it.aLong;
5557                                                final long ibx = it.bLong;
5558                                                byte ox;
5559                                                ox = (byte) (iax * ibx);
5560                                                oai8data[it.oIndex] = ox;
5561                                                for (int j = 1; j < is; j++) {
5562                                                        iax = da.getElementLongAbs(it.aIndex + j);
5563                                                        ox = (byte) (iax * ibx);
5564                                                        oai8data[it.oIndex + j] = ox;
5565                                                }
5566                                        }
5567                                }
5568                        } else if (as == 1) {
5569                                if (it.isOutputDouble()) {
5570                                        while (it.hasNext()) {
5571                                                final double iax = it.aDouble;
5572                                                final double ibx = it.bDouble;
5573                                                byte ox;
5574                                                ox = (byte) toLong(iax * ibx);
5575                                                for (int j = 0; j < is; j++) {
5576                                                        oai8data[it.oIndex + j] = ox;
5577                                                }
5578                                        }
5579                                } else {
5580                                        while (it.hasNext()) {
5581                                                final long iax = it.aLong;
5582                                                final long ibx = it.bLong;
5583                                                byte ox;
5584                                                ox = (byte) (iax * ibx);
5585                                                for (int j = 0; j < is; j++) {
5586                                                        oai8data[it.oIndex + j] = ox;
5587                                                }
5588                                        }
5589                                }
5590                        } else {
5591                                if (it.isOutputDouble()) {
5592                                        while (it.hasNext()) {
5593                                                double iax = it.aDouble;
5594                                                double ibx = it.bDouble;
5595                                                byte ox;
5596                                                ox = (byte) toLong(iax * ibx);
5597                                                oai8data[it.oIndex] = ox;
5598                                                for (int j = 1; j < is; j++) {
5599                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5600                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5601                                                        ox = (byte) toLong(iax * ibx);
5602                                                        oai8data[it.oIndex + j] = ox;
5603                                                }
5604                                        }
5605                                } else {
5606                                        while (it.hasNext()) {
5607                                                long iax = it.aLong;
5608                                                long ibx = it.bLong;
5609                                                byte ox;
5610                                                ox = (byte) (iax * ibx);
5611                                                oai8data[it.oIndex] = ox;
5612                                                for (int j = 1; j < is; j++) {
5613                                                        iax = da.getElementLongAbs(it.aIndex + j);
5614                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5615                                                        ox = (byte) (iax * ibx);
5616                                                        oai8data[it.oIndex + j] = ox;
5617                                                }
5618                                        }
5619                                }
5620                        }
5621                        break;
5622                case Dataset.ARRAYINT16:
5623                        final short[] oai16data = ((CompoundShortDataset) result).getData();
5624                        if (is == 1) {
5625                                if (it.isOutputDouble()) {
5626                                        while (it.hasNext()) {
5627                                                final double iax = it.aDouble;
5628                                                final double ibx = it.bDouble;
5629                                                short ox;
5630                                                ox = (short) toLong(iax * ibx);
5631                                                oai16data[it.oIndex] = ox;
5632                                        }
5633                                } else {
5634                                        while (it.hasNext()) {
5635                                                final long iax = it.aLong;
5636                                                final long ibx = it.bLong;
5637                                                short ox;
5638                                                ox = (short) (iax * ibx);
5639                                                oai16data[it.oIndex] = ox;
5640                                        }
5641                                }
5642                        } else if (as < bs) {
5643                                if (it.isOutputDouble()) {
5644                                        while (it.hasNext()) {
5645                                                final double iax = it.aDouble;
5646                                                double ibx = it.bDouble;
5647                                                short ox;
5648                                                ox = (short) toLong(iax * ibx);
5649                                                oai16data[it.oIndex] = ox;
5650                                                for (int j = 1; j < is; j++) {
5651                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5652                                                        ox = (short) toLong(iax * ibx);
5653                                                        oai16data[it.oIndex + j] = ox;
5654                                                }
5655                                        }
5656                                } else {
5657                                        while (it.hasNext()) {
5658                                                final long iax = it.aLong;
5659                                                long ibx = it.bLong;
5660                                                short ox;
5661                                                ox = (short) (iax * ibx);
5662                                                oai16data[it.oIndex] = ox;
5663                                                for (int j = 1; j < is; j++) {
5664                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5665                                                        ox = (short) (iax * ibx);
5666                                                        oai16data[it.oIndex + j] = ox;
5667                                                }
5668                                        }
5669                                }
5670                        } else if (as > bs) {
5671                                if (it.isOutputDouble()) {
5672                                        while (it.hasNext()) {
5673                                                double iax = it.aDouble;
5674                                                final double ibx = it.bDouble;
5675                                                short ox;
5676                                                ox = (short) toLong(iax * ibx);
5677                                                oai16data[it.oIndex] = ox;
5678                                                for (int j = 1; j < is; j++) {
5679                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5680                                                        ox = (short) toLong(iax * ibx);
5681                                                        oai16data[it.oIndex + j] = ox;
5682                                                }
5683                                        }
5684                                } else {
5685                                        while (it.hasNext()) {
5686                                                long iax = it.aLong;
5687                                                final long ibx = it.bLong;
5688                                                short ox;
5689                                                ox = (short) (iax * ibx);
5690                                                oai16data[it.oIndex] = ox;
5691                                                for (int j = 1; j < is; j++) {
5692                                                        iax = da.getElementLongAbs(it.aIndex + j);
5693                                                        ox = (short) (iax * ibx);
5694                                                        oai16data[it.oIndex + j] = ox;
5695                                                }
5696                                        }
5697                                }
5698                        } else if (as == 1) {
5699                                if (it.isOutputDouble()) {
5700                                        while (it.hasNext()) {
5701                                                final double iax = it.aDouble;
5702                                                final double ibx = it.bDouble;
5703                                                short ox;
5704                                                ox = (short) toLong(iax * ibx);
5705                                                for (int j = 0; j < is; j++) {
5706                                                        oai16data[it.oIndex + j] = ox;
5707                                                }
5708                                        }
5709                                } else {
5710                                        while (it.hasNext()) {
5711                                                final long iax = it.aLong;
5712                                                final long ibx = it.bLong;
5713                                                short ox;
5714                                                ox = (short) (iax * ibx);
5715                                                for (int j = 0; j < is; j++) {
5716                                                        oai16data[it.oIndex + j] = ox;
5717                                                }
5718                                        }
5719                                }
5720                        } else {
5721                                if (it.isOutputDouble()) {
5722                                        while (it.hasNext()) {
5723                                                double iax = it.aDouble;
5724                                                double ibx = it.bDouble;
5725                                                short ox;
5726                                                ox = (short) toLong(iax * ibx);
5727                                                oai16data[it.oIndex] = ox;
5728                                                for (int j = 1; j < is; j++) {
5729                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5730                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5731                                                        ox = (short) toLong(iax * ibx);
5732                                                        oai16data[it.oIndex + j] = ox;
5733                                                }
5734                                        }
5735                                } else {
5736                                        while (it.hasNext()) {
5737                                                long iax = it.aLong;
5738                                                long ibx = it.bLong;
5739                                                short ox;
5740                                                ox = (short) (iax * ibx);
5741                                                oai16data[it.oIndex] = ox;
5742                                                for (int j = 1; j < is; j++) {
5743                                                        iax = da.getElementLongAbs(it.aIndex + j);
5744                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5745                                                        ox = (short) (iax * ibx);
5746                                                        oai16data[it.oIndex + j] = ox;
5747                                                }
5748                                        }
5749                                }
5750                        }
5751                        break;
5752                case Dataset.ARRAYINT64:
5753                        final long[] oai64data = ((CompoundLongDataset) result).getData();
5754                        if (is == 1) {
5755                                if (it.isOutputDouble()) {
5756                                        while (it.hasNext()) {
5757                                                final double iax = it.aDouble;
5758                                                final double ibx = it.bDouble;
5759                                                long ox;
5760                                                ox = toLong(iax * ibx);
5761                                                oai64data[it.oIndex] = ox;
5762                                        }
5763                                } else {
5764                                        while (it.hasNext()) {
5765                                                final long iax = it.aLong;
5766                                                final long ibx = it.bLong;
5767                                                long ox;
5768                                                ox = (iax * ibx);
5769                                                oai64data[it.oIndex] = ox;
5770                                        }
5771                                }
5772                        } else if (as < bs) {
5773                                if (it.isOutputDouble()) {
5774                                        while (it.hasNext()) {
5775                                                final double iax = it.aDouble;
5776                                                double ibx = it.bDouble;
5777                                                long ox;
5778                                                ox = toLong(iax * ibx);
5779                                                oai64data[it.oIndex] = ox;
5780                                                for (int j = 1; j < is; j++) {
5781                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5782                                                        ox = toLong(iax * ibx);
5783                                                        oai64data[it.oIndex + j] = ox;
5784                                                }
5785                                        }
5786                                } else {
5787                                        while (it.hasNext()) {
5788                                                final long iax = it.aLong;
5789                                                long ibx = it.bLong;
5790                                                long ox;
5791                                                ox = (iax * ibx);
5792                                                oai64data[it.oIndex] = ox;
5793                                                for (int j = 1; j < is; j++) {
5794                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5795                                                        ox = (iax * ibx);
5796                                                        oai64data[it.oIndex + j] = ox;
5797                                                }
5798                                        }
5799                                }
5800                        } else if (as > bs) {
5801                                if (it.isOutputDouble()) {
5802                                        while (it.hasNext()) {
5803                                                double iax = it.aDouble;
5804                                                final double ibx = it.bDouble;
5805                                                long ox;
5806                                                ox = toLong(iax * ibx);
5807                                                oai64data[it.oIndex] = ox;
5808                                                for (int j = 1; j < is; j++) {
5809                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5810                                                        ox = toLong(iax * ibx);
5811                                                        oai64data[it.oIndex + j] = ox;
5812                                                }
5813                                        }
5814                                } else {
5815                                        while (it.hasNext()) {
5816                                                long iax = it.aLong;
5817                                                final long ibx = it.bLong;
5818                                                long ox;
5819                                                ox = (iax * ibx);
5820                                                oai64data[it.oIndex] = ox;
5821                                                for (int j = 1; j < is; j++) {
5822                                                        iax = da.getElementLongAbs(it.aIndex + j);
5823                                                        ox = (iax * ibx);
5824                                                        oai64data[it.oIndex + j] = ox;
5825                                                }
5826                                        }
5827                                }
5828                        } else if (as == 1) {
5829                                if (it.isOutputDouble()) {
5830                                        while (it.hasNext()) {
5831                                                final double iax = it.aDouble;
5832                                                final double ibx = it.bDouble;
5833                                                long ox;
5834                                                ox = toLong(iax * ibx);
5835                                                for (int j = 0; j < is; j++) {
5836                                                        oai64data[it.oIndex + j] = ox;
5837                                                }
5838                                        }
5839                                } else {
5840                                        while (it.hasNext()) {
5841                                                final long iax = it.aLong;
5842                                                final long ibx = it.bLong;
5843                                                long ox;
5844                                                ox = (iax * ibx);
5845                                                for (int j = 0; j < is; j++) {
5846                                                        oai64data[it.oIndex + j] = ox;
5847                                                }
5848                                        }
5849                                }
5850                        } else {
5851                                if (it.isOutputDouble()) {
5852                                        while (it.hasNext()) {
5853                                                double iax = it.aDouble;
5854                                                double ibx = it.bDouble;
5855                                                long ox;
5856                                                ox = toLong(iax * ibx);
5857                                                oai64data[it.oIndex] = ox;
5858                                                for (int j = 1; j < is; j++) {
5859                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5860                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5861                                                        ox = toLong(iax * ibx);
5862                                                        oai64data[it.oIndex + j] = ox;
5863                                                }
5864                                        }
5865                                } else {
5866                                        while (it.hasNext()) {
5867                                                long iax = it.aLong;
5868                                                long ibx = it.bLong;
5869                                                long ox;
5870                                                ox = (iax * ibx);
5871                                                oai64data[it.oIndex] = ox;
5872                                                for (int j = 1; j < is; j++) {
5873                                                        iax = da.getElementLongAbs(it.aIndex + j);
5874                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5875                                                        ox = (iax * ibx);
5876                                                        oai64data[it.oIndex + j] = ox;
5877                                                }
5878                                        }
5879                                }
5880                        }
5881                        break;
5882                case Dataset.ARRAYINT32:
5883                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
5884                        if (is == 1) {
5885                                if (it.isOutputDouble()) {
5886                                        while (it.hasNext()) {
5887                                                final double iax = it.aDouble;
5888                                                final double ibx = it.bDouble;
5889                                                int ox;
5890                                                ox = (int) toLong(iax * ibx);
5891                                                oai32data[it.oIndex] = ox;
5892                                        }
5893                                } else {
5894                                        while (it.hasNext()) {
5895                                                final long iax = it.aLong;
5896                                                final long ibx = it.bLong;
5897                                                int ox;
5898                                                ox = (int) (iax * ibx);
5899                                                oai32data[it.oIndex] = ox;
5900                                        }
5901                                }
5902                        } else if (as < bs) {
5903                                if (it.isOutputDouble()) {
5904                                        while (it.hasNext()) {
5905                                                final double iax = it.aDouble;
5906                                                double ibx = it.bDouble;
5907                                                int ox;
5908                                                ox = (int) toLong(iax * ibx);
5909                                                oai32data[it.oIndex] = ox;
5910                                                for (int j = 1; j < is; j++) {
5911                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5912                                                        ox = (int) toLong(iax * ibx);
5913                                                        oai32data[it.oIndex + j] = ox;
5914                                                }
5915                                        }
5916                                } else {
5917                                        while (it.hasNext()) {
5918                                                final long iax = it.aLong;
5919                                                long ibx = it.bLong;
5920                                                int ox;
5921                                                ox = (int) (iax * ibx);
5922                                                oai32data[it.oIndex] = ox;
5923                                                for (int j = 1; j < is; j++) {
5924                                                        ibx = db.getElementLongAbs(it.bIndex + j);
5925                                                        ox = (int) (iax * ibx);
5926                                                        oai32data[it.oIndex + j] = ox;
5927                                                }
5928                                        }
5929                                }
5930                        } else if (as > bs) {
5931                                if (it.isOutputDouble()) {
5932                                        while (it.hasNext()) {
5933                                                double iax = it.aDouble;
5934                                                final double ibx = it.bDouble;
5935                                                int ox;
5936                                                ox = (int) toLong(iax * ibx);
5937                                                oai32data[it.oIndex] = ox;
5938                                                for (int j = 1; j < is; j++) {
5939                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5940                                                        ox = (int) toLong(iax * ibx);
5941                                                        oai32data[it.oIndex + j] = ox;
5942                                                }
5943                                        }
5944                                } else {
5945                                        while (it.hasNext()) {
5946                                                long iax = it.aLong;
5947                                                final long ibx = it.bLong;
5948                                                int ox;
5949                                                ox = (int) (iax * ibx);
5950                                                oai32data[it.oIndex] = ox;
5951                                                for (int j = 1; j < is; j++) {
5952                                                        iax = da.getElementLongAbs(it.aIndex + j);
5953                                                        ox = (int) (iax * ibx);
5954                                                        oai32data[it.oIndex + j] = ox;
5955                                                }
5956                                        }
5957                                }
5958                        } else if (as == 1) {
5959                                if (it.isOutputDouble()) {
5960                                        while (it.hasNext()) {
5961                                                final double iax = it.aDouble;
5962                                                final double ibx = it.bDouble;
5963                                                int ox;
5964                                                ox = (int) toLong(iax * ibx);
5965                                                for (int j = 0; j < is; j++) {
5966                                                        oai32data[it.oIndex + j] = ox;
5967                                                }
5968                                        }
5969                                } else {
5970                                        while (it.hasNext()) {
5971                                                final long iax = it.aLong;
5972                                                final long ibx = it.bLong;
5973                                                int ox;
5974                                                ox = (int) (iax * ibx);
5975                                                for (int j = 0; j < is; j++) {
5976                                                        oai32data[it.oIndex + j] = ox;
5977                                                }
5978                                        }
5979                                }
5980                        } else {
5981                                if (it.isOutputDouble()) {
5982                                        while (it.hasNext()) {
5983                                                double iax = it.aDouble;
5984                                                double ibx = it.bDouble;
5985                                                int ox;
5986                                                ox = (int) toLong(iax * ibx);
5987                                                oai32data[it.oIndex] = ox;
5988                                                for (int j = 1; j < is; j++) {
5989                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
5990                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
5991                                                        ox = (int) toLong(iax * ibx);
5992                                                        oai32data[it.oIndex + j] = ox;
5993                                                }
5994                                        }
5995                                } else {
5996                                        while (it.hasNext()) {
5997                                                long iax = it.aLong;
5998                                                long ibx = it.bLong;
5999                                                int ox;
6000                                                ox = (int) (iax * ibx);
6001                                                oai32data[it.oIndex] = ox;
6002                                                for (int j = 1; j < is; j++) {
6003                                                        iax = da.getElementLongAbs(it.aIndex + j);
6004                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6005                                                        ox = (int) (iax * ibx);
6006                                                        oai32data[it.oIndex + j] = ox;
6007                                                }
6008                                        }
6009                                }
6010                        }
6011                        break;
6012                case Dataset.FLOAT32:
6013                        final float[] of32data = ((FloatDataset) result).getData();
6014                        if (it.isOutputDouble()) {
6015                                while (it.hasNext()) {
6016                                        final double iax = it.aDouble;
6017                                        final double ibx = it.bDouble;
6018                                        float ox;
6019                                        ox = (float) (iax * ibx);
6020                                        of32data[it.oIndex] = ox;
6021                                }
6022                        } else {
6023                                while (it.hasNext()) {
6024                                        final long iax = it.aLong;
6025                                        final long ibx = it.bLong;
6026                                        float ox;
6027                                        ox = (iax * ibx);
6028                                        of32data[it.oIndex] = ox;
6029                                }
6030                        }
6031                        break;
6032                case Dataset.FLOAT64:
6033                        final double[] of64data = ((DoubleDataset) result).getData();
6034                        if (it.isOutputDouble()) {
6035                                while (it.hasNext()) {
6036                                        final double iax = it.aDouble;
6037                                        final double ibx = it.bDouble;
6038                                        double ox;
6039                                        ox = (iax * ibx);
6040                                        of64data[it.oIndex] = ox;
6041                                }
6042                        } else {
6043                                while (it.hasNext()) {
6044                                        final long iax = it.aLong;
6045                                        final long ibx = it.bLong;
6046                                        double ox;
6047                                        ox = (iax * ibx);
6048                                        of64data[it.oIndex] = ox;
6049                                }
6050                        }
6051                        break;
6052                case Dataset.ARRAYFLOAT32:
6053                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
6054                        if (is == 1) {
6055                                if (it.isOutputDouble()) {
6056                                        while (it.hasNext()) {
6057                                                final double iax = it.aDouble;
6058                                                final double ibx = it.bDouble;
6059                                                float ox;
6060                                                ox = (float) (iax * ibx);
6061                                                oaf32data[it.oIndex] = ox;
6062                                        }
6063                                } else {
6064                                        while (it.hasNext()) {
6065                                                final long iax = it.aLong;
6066                                                final long ibx = it.bLong;
6067                                                float ox;
6068                                                ox = (iax * ibx);
6069                                                oaf32data[it.oIndex] = ox;
6070                                        }
6071                                }
6072                        } else if (as < bs) {
6073                                if (it.isOutputDouble()) {
6074                                        while (it.hasNext()) {
6075                                                final double iax = it.aDouble;
6076                                                double ibx = it.bDouble;
6077                                                float ox;
6078                                                ox = (float) (iax * ibx);
6079                                                oaf32data[it.oIndex] = ox;
6080                                                for (int j = 1; j < is; j++) {
6081                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6082                                                        ox = (float) (iax * ibx);
6083                                                        oaf32data[it.oIndex + j] = ox;
6084                                                }
6085                                        }
6086                                } else {
6087                                        while (it.hasNext()) {
6088                                                final long iax = it.aLong;
6089                                                long ibx = it.bLong;
6090                                                float ox;
6091                                                ox = (iax * ibx);
6092                                                oaf32data[it.oIndex] = ox;
6093                                                for (int j = 1; j < is; j++) {
6094                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6095                                                        ox = (iax * ibx);
6096                                                        oaf32data[it.oIndex + j] = ox;
6097                                                }
6098                                        }
6099                                }
6100                        } else if (as > bs) {
6101                                if (it.isOutputDouble()) {
6102                                        while (it.hasNext()) {
6103                                                double iax = it.aDouble;
6104                                                final double ibx = it.bDouble;
6105                                                float ox;
6106                                                ox = (float) (iax * ibx);
6107                                                oaf32data[it.oIndex] = ox;
6108                                                for (int j = 1; j < is; j++) {
6109                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6110                                                        ox = (float) (iax * ibx);
6111                                                        oaf32data[it.oIndex + j] = ox;
6112                                                }
6113                                        }
6114                                } else {
6115                                        while (it.hasNext()) {
6116                                                long iax = it.aLong;
6117                                                final long ibx = it.bLong;
6118                                                float ox;
6119                                                ox = (iax * ibx);
6120                                                oaf32data[it.oIndex] = ox;
6121                                                for (int j = 1; j < is; j++) {
6122                                                        iax = da.getElementLongAbs(it.aIndex + j);
6123                                                        ox = (iax * ibx);
6124                                                        oaf32data[it.oIndex + j] = ox;
6125                                                }
6126                                        }
6127                                }
6128                        } else if (as == 1) {
6129                                if (it.isOutputDouble()) {
6130                                        while (it.hasNext()) {
6131                                                final double iax = it.aDouble;
6132                                                final double ibx = it.bDouble;
6133                                                float ox;
6134                                                ox = (float) (iax * ibx);
6135                                                for (int j = 0; j < is; j++) {
6136                                                        oaf32data[it.oIndex + j] = ox;
6137                                                }
6138                                        }
6139                                } else {
6140                                        while (it.hasNext()) {
6141                                                final long iax = it.aLong;
6142                                                final long ibx = it.bLong;
6143                                                float ox;
6144                                                ox = (iax * ibx);
6145                                                for (int j = 0; j < is; j++) {
6146                                                        oaf32data[it.oIndex + j] = ox;
6147                                                }
6148                                        }
6149                                }
6150                        } else {
6151                                if (it.isOutputDouble()) {
6152                                        while (it.hasNext()) {
6153                                                double iax = it.aDouble;
6154                                                double ibx = it.bDouble;
6155                                                float ox;
6156                                                ox = (float) (iax * ibx);
6157                                                oaf32data[it.oIndex] = ox;
6158                                                for (int j = 1; j < is; j++) {
6159                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6160                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6161                                                        ox = (float) (iax * ibx);
6162                                                        oaf32data[it.oIndex + j] = ox;
6163                                                }
6164                                        }
6165                                } else {
6166                                        while (it.hasNext()) {
6167                                                long iax = it.aLong;
6168                                                long ibx = it.bLong;
6169                                                float ox;
6170                                                ox = (iax * ibx);
6171                                                oaf32data[it.oIndex] = ox;
6172                                                for (int j = 1; j < is; j++) {
6173                                                        iax = da.getElementLongAbs(it.aIndex + j);
6174                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6175                                                        ox = (iax * ibx);
6176                                                        oaf32data[it.oIndex + j] = ox;
6177                                                }
6178                                        }
6179                                }
6180                        }
6181                        break;
6182                case Dataset.ARRAYFLOAT64:
6183                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
6184                        if (is == 1) {
6185                                if (it.isOutputDouble()) {
6186                                        while (it.hasNext()) {
6187                                                final double iax = it.aDouble;
6188                                                final double ibx = it.bDouble;
6189                                                double ox;
6190                                                ox = (iax * ibx);
6191                                                oaf64data[it.oIndex] = ox;
6192                                        }
6193                                } else {
6194                                        while (it.hasNext()) {
6195                                                final long iax = it.aLong;
6196                                                final long ibx = it.bLong;
6197                                                double ox;
6198                                                ox = (iax * ibx);
6199                                                oaf64data[it.oIndex] = ox;
6200                                        }
6201                                }
6202                        } else if (as < bs) {
6203                                if (it.isOutputDouble()) {
6204                                        while (it.hasNext()) {
6205                                                final double iax = it.aDouble;
6206                                                double ibx = it.bDouble;
6207                                                double ox;
6208                                                ox = (iax * ibx);
6209                                                oaf64data[it.oIndex] = ox;
6210                                                for (int j = 1; j < is; j++) {
6211                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6212                                                        ox = (iax * ibx);
6213                                                        oaf64data[it.oIndex + j] = ox;
6214                                                }
6215                                        }
6216                                } else {
6217                                        while (it.hasNext()) {
6218                                                final long iax = it.aLong;
6219                                                long ibx = it.bLong;
6220                                                double ox;
6221                                                ox = (iax * ibx);
6222                                                oaf64data[it.oIndex] = ox;
6223                                                for (int j = 1; j < is; j++) {
6224                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6225                                                        ox = (iax * ibx);
6226                                                        oaf64data[it.oIndex + j] = ox;
6227                                                }
6228                                        }
6229                                }
6230                        } else if (as > bs) {
6231                                if (it.isOutputDouble()) {
6232                                        while (it.hasNext()) {
6233                                                double iax = it.aDouble;
6234                                                final double ibx = it.bDouble;
6235                                                double ox;
6236                                                ox = (iax * ibx);
6237                                                oaf64data[it.oIndex] = ox;
6238                                                for (int j = 1; j < is; j++) {
6239                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6240                                                        ox = (iax * ibx);
6241                                                        oaf64data[it.oIndex + j] = ox;
6242                                                }
6243                                        }
6244                                } else {
6245                                        while (it.hasNext()) {
6246                                                long iax = it.aLong;
6247                                                final long ibx = it.bLong;
6248                                                double ox;
6249                                                ox = (iax * ibx);
6250                                                oaf64data[it.oIndex] = ox;
6251                                                for (int j = 1; j < is; j++) {
6252                                                        iax = da.getElementLongAbs(it.aIndex + j);
6253                                                        ox = (iax * ibx);
6254                                                        oaf64data[it.oIndex + j] = ox;
6255                                                }
6256                                        }
6257                                }
6258                        } else if (as == 1) {
6259                                if (it.isOutputDouble()) {
6260                                        while (it.hasNext()) {
6261                                                final double iax = it.aDouble;
6262                                                final double ibx = it.bDouble;
6263                                                double ox;
6264                                                ox = (iax * ibx);
6265                                                for (int j = 0; j < is; j++) {
6266                                                        oaf64data[it.oIndex + j] = ox;
6267                                                }
6268                                        }
6269                                } else {
6270                                        while (it.hasNext()) {
6271                                                final long iax = it.aLong;
6272                                                final long ibx = it.bLong;
6273                                                double ox;
6274                                                ox = (iax * ibx);
6275                                                for (int j = 0; j < is; j++) {
6276                                                        oaf64data[it.oIndex + j] = ox;
6277                                                }
6278                                        }
6279                                }
6280                        } else {
6281                                if (it.isOutputDouble()) {
6282                                        while (it.hasNext()) {
6283                                                double iax = it.aDouble;
6284                                                double ibx = it.bDouble;
6285                                                double ox;
6286                                                ox = (iax * ibx);
6287                                                oaf64data[it.oIndex] = ox;
6288                                                for (int j = 1; j < is; j++) {
6289                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6290                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6291                                                        ox = (iax * ibx);
6292                                                        oaf64data[it.oIndex + j] = ox;
6293                                                }
6294                                        }
6295                                } else {
6296                                        while (it.hasNext()) {
6297                                                long iax = it.aLong;
6298                                                long ibx = it.bLong;
6299                                                double ox;
6300                                                ox = (iax * ibx);
6301                                                oaf64data[it.oIndex] = ox;
6302                                                for (int j = 1; j < is; j++) {
6303                                                        iax = da.getElementLongAbs(it.aIndex + j);
6304                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6305                                                        ox = (iax * ibx);
6306                                                        oaf64data[it.oIndex + j] = ox;
6307                                                }
6308                                        }
6309                                }
6310                        }
6311                        break;
6312                case Dataset.COMPLEX64:
6313                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
6314                        if (!da.isComplex()) {
6315                                if (it.isOutputDouble()) {
6316                                        final double iay = 0;
6317                                        if (db.isComplex()) {
6318                                                while (it.hasNext()) {
6319                                                        final double iax = it.aDouble;
6320                                                        final double ibx = it.bDouble;
6321                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
6322                                                        float ox;
6323                                                        float oy;
6324                                                        ox = (float) (iax * ibx - iay * iby);
6325                                                        oy = (float) (iax * iby + iay * ibx);
6326                                                        oc64data[it.oIndex] = ox;
6327                                                        oc64data[it.oIndex + 1] = oy;
6328                                                }
6329                                        } else {
6330                                                while (it.hasNext()) {
6331                                                        final double iax = it.aDouble;
6332                                                        final double ibx = it.bDouble;
6333                                                        final double iby = 0;
6334                                                        float ox;
6335                                                        float oy;
6336                                                        ox = (float) (iax * ibx - iay * iby);
6337                                                        oy = (float) (iax * iby + iay * ibx);
6338                                                        oc64data[it.oIndex] = ox;
6339                                                        oc64data[it.oIndex + 1] = oy;
6340                                                }
6341                                        }
6342                                } else {
6343                                        final long iay = 0;
6344                                        while (it.hasNext()) {
6345                                                final long iax = it.aLong;
6346                                                final long ibx = it.bLong;
6347                                                final long iby = 0;
6348                                                float ox;
6349                                                float oy;
6350                                                ox = (float) (iax * ibx - iay * iby);
6351                                                oy = (float) (iax * iby + iay * ibx);
6352                                                oc64data[it.oIndex] = ox;
6353                                                oc64data[it.oIndex + 1] = oy;
6354                                        }
6355                                }
6356                        } else if (!db.isComplex()) {
6357                                final double iby = 0;
6358                                while (it.hasNext()) {
6359                                        final double iax = it.aDouble;
6360                                        final double ibx = it.bDouble;
6361                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
6362                                        float ox;
6363                                        float oy;
6364                                        ox = (float) (iax * ibx - iay * iby);
6365                                        oy = (float) (iax * iby + iay * ibx);
6366                                        oc64data[it.oIndex] = ox;
6367                                        oc64data[it.oIndex + 1] = oy;
6368                                }
6369                        } else {
6370                                while (it.hasNext()) {
6371                                        final double iax = it.aDouble;
6372                                        final double ibx = it.bDouble;
6373                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
6374                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
6375                                        float ox;
6376                                        float oy;
6377                                        ox = (float) (iax * ibx - iay * iby);
6378                                        oy = (float) (iax * iby + iay * ibx);
6379                                        oc64data[it.oIndex] = ox;
6380                                        oc64data[it.oIndex + 1] = oy;
6381                                }
6382                        }
6383                        break;
6384                case Dataset.COMPLEX128:
6385                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
6386                        if (!da.isComplex()) {
6387                                if (it.isOutputDouble()) {
6388                                        final double iay = 0;
6389                                        if (db.isComplex()) {
6390                                                while (it.hasNext()) {
6391                                                        final double iax = it.aDouble;
6392                                                        final double ibx = it.bDouble;
6393                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
6394                                                        double ox;
6395                                                        double oy;
6396                                                        ox = (iax * ibx - iay * iby);
6397                                                        oy = (iax * iby + iay * ibx);
6398                                                        oc128data[it.oIndex] = ox;
6399                                                        oc128data[it.oIndex + 1] = oy;
6400                                                }
6401                                        } else {
6402                                                while (it.hasNext()) {
6403                                                        final double iax = it.aDouble;
6404                                                        final double ibx = it.bDouble;
6405                                                        final double iby = 0;
6406                                                        double ox;
6407                                                        double oy;
6408                                                        ox = (iax * ibx - iay * iby);
6409                                                        oy = (iax * iby + iay * ibx);
6410                                                        oc128data[it.oIndex] = ox;
6411                                                        oc128data[it.oIndex + 1] = oy;
6412                                                }
6413                                        }
6414                                } else {
6415                                        final long iay = 0;
6416                                        while (it.hasNext()) {
6417                                                final long iax = it.aLong;
6418                                                final long ibx = it.bLong;
6419                                                final long iby = 0;
6420                                                double ox;
6421                                                double oy;
6422                                                ox = (iax * ibx - iay * iby);
6423                                                oy = (iax * iby + iay * ibx);
6424                                                oc128data[it.oIndex] = ox;
6425                                                oc128data[it.oIndex + 1] = oy;
6426                                        }
6427                                }
6428                        } else if (!db.isComplex()) {
6429                                final double iby = 0;
6430                                while (it.hasNext()) {
6431                                        final double iax = it.aDouble;
6432                                        final double ibx = it.bDouble;
6433                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
6434                                        double ox;
6435                                        double oy;
6436                                        ox = (iax * ibx - iay * iby);
6437                                        oy = (iax * iby + iay * ibx);
6438                                        oc128data[it.oIndex] = ox;
6439                                        oc128data[it.oIndex + 1] = oy;
6440                                }
6441                        } else {
6442                                while (it.hasNext()) {
6443                                        final double iax = it.aDouble;
6444                                        final double ibx = it.bDouble;
6445                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
6446                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
6447                                        double ox;
6448                                        double oy;
6449                                        ox = (iax * ibx - iay * iby);
6450                                        oy = (iax * iby + iay * ibx);
6451                                        oc128data[it.oIndex] = ox;
6452                                        oc128data[it.oIndex + 1] = oy;
6453                                }
6454                        }
6455                        break;
6456                default:
6457                        throw new IllegalArgumentException("multiply supports integer, compound integer, real, compound real, complex datasets only");
6458                }
6459
6460                addBinaryOperatorName(da, db, result, "*");
6461                return result;
6462        }
6463
6464        /**
6465         * divide operator
6466         * @param a first operand
6467         * @param b second operand
6468         * @return {@code a / b}, division of a by b
6469         */
6470        public static Dataset divide(final Object a, final Object b) {
6471                return divide(a, b, null);
6472        }
6473
6474        /**
6475         * divide operator
6476         * @param a first operand
6477         * @param b second operand
6478         * @param o output can be null - in which case, a new dataset is created
6479         * @return {@code a / b}, division of a by b
6480         */
6481        public static Dataset divide(final Object a, final Object b, final Dataset o) {
6482                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
6483                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
6484                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
6485                final Dataset result = it.getOutput();
6486                if (!result.isComplex()) {
6487                        boolean change = false;
6488                        if (da.isComplex()) {
6489                                da = da.getRealView();
6490                                change = true;
6491                        }
6492                        if (db.isComplex()) {
6493                                db = db.getRealView();
6494                                change = true;
6495                        }
6496                        if (change) {
6497                                it = BroadcastIterator.createIterator(da, db, result, true);
6498                        }
6499                }
6500                final int is = result.getElementsPerItem();
6501                final int as = da.getElementsPerItem();
6502                final int bs = db.getElementsPerItem();
6503                final int dt = result.getDType();
6504
6505                switch(dt) {
6506                case Dataset.INT8:
6507                        final byte[] oi8data = ((ByteDataset) result).getData();
6508                        if (it.isOutputDouble()) {
6509                                while (it.hasNext()) {
6510                                        final double iax = it.aDouble;
6511                                        final double ibx = it.bDouble;
6512                                        byte ox;
6513                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6514                                        oi8data[it.oIndex] = ox;
6515                                }
6516                        } else {
6517                                while (it.hasNext()) {
6518                                        final long iax = it.aLong;
6519                                        final long ibx = it.bLong;
6520                                        byte ox;
6521                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6522                                        oi8data[it.oIndex] = ox;
6523                                }
6524                        }
6525                        break;
6526                case Dataset.INT16:
6527                        final short[] oi16data = ((ShortDataset) result).getData();
6528                        if (it.isOutputDouble()) {
6529                                while (it.hasNext()) {
6530                                        final double iax = it.aDouble;
6531                                        final double ibx = it.bDouble;
6532                                        short ox;
6533                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6534                                        oi16data[it.oIndex] = ox;
6535                                }
6536                        } else {
6537                                while (it.hasNext()) {
6538                                        final long iax = it.aLong;
6539                                        final long ibx = it.bLong;
6540                                        short ox;
6541                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
6542                                        oi16data[it.oIndex] = ox;
6543                                }
6544                        }
6545                        break;
6546                case Dataset.INT64:
6547                        final long[] oi64data = ((LongDataset) result).getData();
6548                        if (it.isOutputDouble()) {
6549                                while (it.hasNext()) {
6550                                        final double iax = it.aDouble;
6551                                        final double ibx = it.bDouble;
6552                                        long ox;
6553                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
6554                                        oi64data[it.oIndex] = ox;
6555                                }
6556                        } else {
6557                                while (it.hasNext()) {
6558                                        final long iax = it.aLong;
6559                                        final long ibx = it.bLong;
6560                                        long ox;
6561                                        ox = (ibx == 0 ? 0 : iax / ibx);
6562                                        oi64data[it.oIndex] = ox;
6563                                }
6564                        }
6565                        break;
6566                case Dataset.INT32:
6567                        final int[] oi32data = ((IntegerDataset) result).getData();
6568                        if (it.isOutputDouble()) {
6569                                while (it.hasNext()) {
6570                                        final double iax = it.aDouble;
6571                                        final double ibx = it.bDouble;
6572                                        int ox;
6573                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
6574                                        oi32data[it.oIndex] = ox;
6575                                }
6576                        } else {
6577                                while (it.hasNext()) {
6578                                        final long iax = it.aLong;
6579                                        final long ibx = it.bLong;
6580                                        int ox;
6581                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
6582                                        oi32data[it.oIndex] = ox;
6583                                }
6584                        }
6585                        break;
6586                case Dataset.ARRAYINT8:
6587                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
6588                        if (is == 1) {
6589                                if (it.isOutputDouble()) {
6590                                        while (it.hasNext()) {
6591                                                final double iax = it.aDouble;
6592                                                final double ibx = it.bDouble;
6593                                                byte ox;
6594                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6595                                                oai8data[it.oIndex] = ox;
6596                                        }
6597                                } else {
6598                                        while (it.hasNext()) {
6599                                                final long iax = it.aLong;
6600                                                final long ibx = it.bLong;
6601                                                byte ox;
6602                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6603                                                oai8data[it.oIndex] = ox;
6604                                        }
6605                                }
6606                        } else if (as < bs) {
6607                                if (it.isOutputDouble()) {
6608                                        while (it.hasNext()) {
6609                                                final double iax = it.aDouble;
6610                                                double ibx = it.bDouble;
6611                                                byte ox;
6612                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6613                                                oai8data[it.oIndex] = ox;
6614                                                for (int j = 1; j < is; j++) {
6615                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6616                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6617                                                        oai8data[it.oIndex + j] = ox;
6618                                                }
6619                                        }
6620                                } else {
6621                                        while (it.hasNext()) {
6622                                                final long iax = it.aLong;
6623                                                long ibx = it.bLong;
6624                                                byte ox;
6625                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6626                                                oai8data[it.oIndex] = ox;
6627                                                for (int j = 1; j < is; j++) {
6628                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6629                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6630                                                        oai8data[it.oIndex + j] = ox;
6631                                                }
6632                                        }
6633                                }
6634                        } else if (as > bs) {
6635                                if (it.isOutputDouble()) {
6636                                        while (it.hasNext()) {
6637                                                double iax = it.aDouble;
6638                                                final double ibx = it.bDouble;
6639                                                byte ox;
6640                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6641                                                oai8data[it.oIndex] = ox;
6642                                                for (int j = 1; j < is; j++) {
6643                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6644                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6645                                                        oai8data[it.oIndex + j] = ox;
6646                                                }
6647                                        }
6648                                } else {
6649                                        while (it.hasNext()) {
6650                                                long iax = it.aLong;
6651                                                final long ibx = it.bLong;
6652                                                byte ox;
6653                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6654                                                oai8data[it.oIndex] = ox;
6655                                                for (int j = 1; j < is; j++) {
6656                                                        iax = da.getElementLongAbs(it.aIndex + j);
6657                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6658                                                        oai8data[it.oIndex + j] = ox;
6659                                                }
6660                                        }
6661                                }
6662                        } else if (as == 1) {
6663                                if (it.isOutputDouble()) {
6664                                        while (it.hasNext()) {
6665                                                final double iax = it.aDouble;
6666                                                final double ibx = it.bDouble;
6667                                                byte ox;
6668                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6669                                                for (int j = 0; j < is; j++) {
6670                                                        oai8data[it.oIndex + j] = ox;
6671                                                }
6672                                        }
6673                                } else {
6674                                        while (it.hasNext()) {
6675                                                final long iax = it.aLong;
6676                                                final long ibx = it.bLong;
6677                                                byte ox;
6678                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6679                                                for (int j = 0; j < is; j++) {
6680                                                        oai8data[it.oIndex + j] = ox;
6681                                                }
6682                                        }
6683                                }
6684                        } else {
6685                                if (it.isOutputDouble()) {
6686                                        while (it.hasNext()) {
6687                                                double iax = it.aDouble;
6688                                                double ibx = it.bDouble;
6689                                                byte ox;
6690                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6691                                                oai8data[it.oIndex] = ox;
6692                                                for (int j = 1; j < is; j++) {
6693                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6694                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6695                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
6696                                                        oai8data[it.oIndex + j] = ox;
6697                                                }
6698                                        }
6699                                } else {
6700                                        while (it.hasNext()) {
6701                                                long iax = it.aLong;
6702                                                long ibx = it.bLong;
6703                                                byte ox;
6704                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6705                                                oai8data[it.oIndex] = ox;
6706                                                for (int j = 1; j < is; j++) {
6707                                                        iax = da.getElementLongAbs(it.aIndex + j);
6708                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6709                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
6710                                                        oai8data[it.oIndex + j] = ox;
6711                                                }
6712                                        }
6713                                }
6714                        }
6715                        break;
6716                case Dataset.ARRAYINT16:
6717                        final short[] oai16data = ((CompoundShortDataset) result).getData();
6718                        if (is == 1) {
6719                                if (it.isOutputDouble()) {
6720                                        while (it.hasNext()) {
6721                                                final double iax = it.aDouble;
6722                                                final double ibx = it.bDouble;
6723                                                short ox;
6724                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6725                                                oai16data[it.oIndex] = ox;
6726                                        }
6727                                } else {
6728                                        while (it.hasNext()) {
6729                                                final long iax = it.aLong;
6730                                                final long ibx = it.bLong;
6731                                                short ox;
6732                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
6733                                                oai16data[it.oIndex] = ox;
6734                                        }
6735                                }
6736                        } else if (as < bs) {
6737                                if (it.isOutputDouble()) {
6738                                        while (it.hasNext()) {
6739                                                final double iax = it.aDouble;
6740                                                double ibx = it.bDouble;
6741                                                short ox;
6742                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6743                                                oai16data[it.oIndex] = ox;
6744                                                for (int j = 1; j < is; j++) {
6745                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6746                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6747                                                        oai16data[it.oIndex + j] = ox;
6748                                                }
6749                                        }
6750                                } else {
6751                                        while (it.hasNext()) {
6752                                                final long iax = it.aLong;
6753                                                long ibx = it.bLong;
6754                                                short ox;
6755                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
6756                                                oai16data[it.oIndex] = ox;
6757                                                for (int j = 1; j < is; j++) {
6758                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6759                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
6760                                                        oai16data[it.oIndex + j] = ox;
6761                                                }
6762                                        }
6763                                }
6764                        } else if (as > bs) {
6765                                if (it.isOutputDouble()) {
6766                                        while (it.hasNext()) {
6767                                                double iax = it.aDouble;
6768                                                final double ibx = it.bDouble;
6769                                                short ox;
6770                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6771                                                oai16data[it.oIndex] = ox;
6772                                                for (int j = 1; j < is; j++) {
6773                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6774                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6775                                                        oai16data[it.oIndex + j] = ox;
6776                                                }
6777                                        }
6778                                } else {
6779                                        while (it.hasNext()) {
6780                                                long iax = it.aLong;
6781                                                final long ibx = it.bLong;
6782                                                short ox;
6783                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
6784                                                oai16data[it.oIndex] = ox;
6785                                                for (int j = 1; j < is; j++) {
6786                                                        iax = da.getElementLongAbs(it.aIndex + j);
6787                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
6788                                                        oai16data[it.oIndex + j] = ox;
6789                                                }
6790                                        }
6791                                }
6792                        } else if (as == 1) {
6793                                if (it.isOutputDouble()) {
6794                                        while (it.hasNext()) {
6795                                                final double iax = it.aDouble;
6796                                                final double ibx = it.bDouble;
6797                                                short ox;
6798                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6799                                                for (int j = 0; j < is; j++) {
6800                                                        oai16data[it.oIndex + j] = ox;
6801                                                }
6802                                        }
6803                                } else {
6804                                        while (it.hasNext()) {
6805                                                final long iax = it.aLong;
6806                                                final long ibx = it.bLong;
6807                                                short ox;
6808                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
6809                                                for (int j = 0; j < is; j++) {
6810                                                        oai16data[it.oIndex + j] = ox;
6811                                                }
6812                                        }
6813                                }
6814                        } else {
6815                                if (it.isOutputDouble()) {
6816                                        while (it.hasNext()) {
6817                                                double iax = it.aDouble;
6818                                                double ibx = it.bDouble;
6819                                                short ox;
6820                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6821                                                oai16data[it.oIndex] = ox;
6822                                                for (int j = 1; j < is; j++) {
6823                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6824                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6825                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
6826                                                        oai16data[it.oIndex + j] = ox;
6827                                                }
6828                                        }
6829                                } else {
6830                                        while (it.hasNext()) {
6831                                                long iax = it.aLong;
6832                                                long ibx = it.bLong;
6833                                                short ox;
6834                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
6835                                                oai16data[it.oIndex] = ox;
6836                                                for (int j = 1; j < is; j++) {
6837                                                        iax = da.getElementLongAbs(it.aIndex + j);
6838                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6839                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
6840                                                        oai16data[it.oIndex + j] = ox;
6841                                                }
6842                                        }
6843                                }
6844                        }
6845                        break;
6846                case Dataset.ARRAYINT64:
6847                        final long[] oai64data = ((CompoundLongDataset) result).getData();
6848                        if (is == 1) {
6849                                if (it.isOutputDouble()) {
6850                                        while (it.hasNext()) {
6851                                                final double iax = it.aDouble;
6852                                                final double ibx = it.bDouble;
6853                                                long ox;
6854                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
6855                                                oai64data[it.oIndex] = ox;
6856                                        }
6857                                } else {
6858                                        while (it.hasNext()) {
6859                                                final long iax = it.aLong;
6860                                                final long ibx = it.bLong;
6861                                                long ox;
6862                                                ox = (ibx == 0 ? 0 : iax / ibx);
6863                                                oai64data[it.oIndex] = ox;
6864                                        }
6865                                }
6866                        } else if (as < bs) {
6867                                if (it.isOutputDouble()) {
6868                                        while (it.hasNext()) {
6869                                                final double iax = it.aDouble;
6870                                                double ibx = it.bDouble;
6871                                                long ox;
6872                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
6873                                                oai64data[it.oIndex] = ox;
6874                                                for (int j = 1; j < is; j++) {
6875                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6876                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
6877                                                        oai64data[it.oIndex + j] = ox;
6878                                                }
6879                                        }
6880                                } else {
6881                                        while (it.hasNext()) {
6882                                                final long iax = it.aLong;
6883                                                long ibx = it.bLong;
6884                                                long ox;
6885                                                ox = (ibx == 0 ? 0 : iax / ibx);
6886                                                oai64data[it.oIndex] = ox;
6887                                                for (int j = 1; j < is; j++) {
6888                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6889                                                        ox = (ibx == 0 ? 0 : iax / ibx);
6890                                                        oai64data[it.oIndex + j] = ox;
6891                                                }
6892                                        }
6893                                }
6894                        } else if (as > bs) {
6895                                if (it.isOutputDouble()) {
6896                                        while (it.hasNext()) {
6897                                                double iax = it.aDouble;
6898                                                final double ibx = it.bDouble;
6899                                                long ox;
6900                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
6901                                                oai64data[it.oIndex] = ox;
6902                                                for (int j = 1; j < is; j++) {
6903                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6904                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
6905                                                        oai64data[it.oIndex + j] = ox;
6906                                                }
6907                                        }
6908                                } else {
6909                                        while (it.hasNext()) {
6910                                                long iax = it.aLong;
6911                                                final long ibx = it.bLong;
6912                                                long ox;
6913                                                ox = (ibx == 0 ? 0 : iax / ibx);
6914                                                oai64data[it.oIndex] = ox;
6915                                                for (int j = 1; j < is; j++) {
6916                                                        iax = da.getElementLongAbs(it.aIndex + j);
6917                                                        ox = (ibx == 0 ? 0 : iax / ibx);
6918                                                        oai64data[it.oIndex + j] = ox;
6919                                                }
6920                                        }
6921                                }
6922                        } else if (as == 1) {
6923                                if (it.isOutputDouble()) {
6924                                        while (it.hasNext()) {
6925                                                final double iax = it.aDouble;
6926                                                final double ibx = it.bDouble;
6927                                                long ox;
6928                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
6929                                                for (int j = 0; j < is; j++) {
6930                                                        oai64data[it.oIndex + j] = ox;
6931                                                }
6932                                        }
6933                                } else {
6934                                        while (it.hasNext()) {
6935                                                final long iax = it.aLong;
6936                                                final long ibx = it.bLong;
6937                                                long ox;
6938                                                ox = (ibx == 0 ? 0 : iax / ibx);
6939                                                for (int j = 0; j < is; j++) {
6940                                                        oai64data[it.oIndex + j] = ox;
6941                                                }
6942                                        }
6943                                }
6944                        } else {
6945                                if (it.isOutputDouble()) {
6946                                        while (it.hasNext()) {
6947                                                double iax = it.aDouble;
6948                                                double ibx = it.bDouble;
6949                                                long ox;
6950                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
6951                                                oai64data[it.oIndex] = ox;
6952                                                for (int j = 1; j < is; j++) {
6953                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
6954                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
6955                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
6956                                                        oai64data[it.oIndex + j] = ox;
6957                                                }
6958                                        }
6959                                } else {
6960                                        while (it.hasNext()) {
6961                                                long iax = it.aLong;
6962                                                long ibx = it.bLong;
6963                                                long ox;
6964                                                ox = (ibx == 0 ? 0 : iax / ibx);
6965                                                oai64data[it.oIndex] = ox;
6966                                                for (int j = 1; j < is; j++) {
6967                                                        iax = da.getElementLongAbs(it.aIndex + j);
6968                                                        ibx = db.getElementLongAbs(it.bIndex + j);
6969                                                        ox = (ibx == 0 ? 0 : iax / ibx);
6970                                                        oai64data[it.oIndex + j] = ox;
6971                                                }
6972                                        }
6973                                }
6974                        }
6975                        break;
6976                case Dataset.ARRAYINT32:
6977                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
6978                        if (is == 1) {
6979                                if (it.isOutputDouble()) {
6980                                        while (it.hasNext()) {
6981                                                final double iax = it.aDouble;
6982                                                final double ibx = it.bDouble;
6983                                                int ox;
6984                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
6985                                                oai32data[it.oIndex] = ox;
6986                                        }
6987                                } else {
6988                                        while (it.hasNext()) {
6989                                                final long iax = it.aLong;
6990                                                final long ibx = it.bLong;
6991                                                int ox;
6992                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
6993                                                oai32data[it.oIndex] = ox;
6994                                        }
6995                                }
6996                        } else if (as < bs) {
6997                                if (it.isOutputDouble()) {
6998                                        while (it.hasNext()) {
6999                                                final double iax = it.aDouble;
7000                                                double ibx = it.bDouble;
7001                                                int ox;
7002                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7003                                                oai32data[it.oIndex] = ox;
7004                                                for (int j = 1; j < is; j++) {
7005                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7006                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7007                                                        oai32data[it.oIndex + j] = ox;
7008                                                }
7009                                        }
7010                                } else {
7011                                        while (it.hasNext()) {
7012                                                final long iax = it.aLong;
7013                                                long ibx = it.bLong;
7014                                                int ox;
7015                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
7016                                                oai32data[it.oIndex] = ox;
7017                                                for (int j = 1; j < is; j++) {
7018                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7019                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
7020                                                        oai32data[it.oIndex + j] = ox;
7021                                                }
7022                                        }
7023                                }
7024                        } else if (as > bs) {
7025                                if (it.isOutputDouble()) {
7026                                        while (it.hasNext()) {
7027                                                double iax = it.aDouble;
7028                                                final double ibx = it.bDouble;
7029                                                int ox;
7030                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7031                                                oai32data[it.oIndex] = ox;
7032                                                for (int j = 1; j < is; j++) {
7033                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7034                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7035                                                        oai32data[it.oIndex + j] = ox;
7036                                                }
7037                                        }
7038                                } else {
7039                                        while (it.hasNext()) {
7040                                                long iax = it.aLong;
7041                                                final long ibx = it.bLong;
7042                                                int ox;
7043                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
7044                                                oai32data[it.oIndex] = ox;
7045                                                for (int j = 1; j < is; j++) {
7046                                                        iax = da.getElementLongAbs(it.aIndex + j);
7047                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
7048                                                        oai32data[it.oIndex + j] = ox;
7049                                                }
7050                                        }
7051                                }
7052                        } else if (as == 1) {
7053                                if (it.isOutputDouble()) {
7054                                        while (it.hasNext()) {
7055                                                final double iax = it.aDouble;
7056                                                final double ibx = it.bDouble;
7057                                                int ox;
7058                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7059                                                for (int j = 0; j < is; j++) {
7060                                                        oai32data[it.oIndex + j] = ox;
7061                                                }
7062                                        }
7063                                } else {
7064                                        while (it.hasNext()) {
7065                                                final long iax = it.aLong;
7066                                                final long ibx = it.bLong;
7067                                                int ox;
7068                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
7069                                                for (int j = 0; j < is; j++) {
7070                                                        oai32data[it.oIndex + j] = ox;
7071                                                }
7072                                        }
7073                                }
7074                        } else {
7075                                if (it.isOutputDouble()) {
7076                                        while (it.hasNext()) {
7077                                                double iax = it.aDouble;
7078                                                double ibx = it.bDouble;
7079                                                int ox;
7080                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7081                                                oai32data[it.oIndex] = ox;
7082                                                for (int j = 1; j < is; j++) {
7083                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7084                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7085                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7086                                                        oai32data[it.oIndex + j] = ox;
7087                                                }
7088                                        }
7089                                } else {
7090                                        while (it.hasNext()) {
7091                                                long iax = it.aLong;
7092                                                long ibx = it.bLong;
7093                                                int ox;
7094                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
7095                                                oai32data[it.oIndex] = ox;
7096                                                for (int j = 1; j < is; j++) {
7097                                                        iax = da.getElementLongAbs(it.aIndex + j);
7098                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7099                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
7100                                                        oai32data[it.oIndex + j] = ox;
7101                                                }
7102                                        }
7103                                }
7104                        }
7105                        break;
7106                case Dataset.FLOAT32:
7107                        final float[] of32data = ((FloatDataset) result).getData();
7108                        if (it.isOutputDouble()) {
7109                                while (it.hasNext()) {
7110                                        final double iax = it.aDouble;
7111                                        final double ibx = it.bDouble;
7112                                        float ox;
7113                                        ox = (float) (iax / ibx);
7114                                        of32data[it.oIndex] = ox;
7115                                }
7116                        } else {
7117                                while (it.hasNext()) {
7118                                        final long iax = it.aLong;
7119                                        final long ibx = it.bLong;
7120                                        float ox;
7121                                        ox = (iax / ibx);
7122                                        of32data[it.oIndex] = ox;
7123                                }
7124                        }
7125                        break;
7126                case Dataset.FLOAT64:
7127                        final double[] of64data = ((DoubleDataset) result).getData();
7128                        if (it.isOutputDouble()) {
7129                                while (it.hasNext()) {
7130                                        final double iax = it.aDouble;
7131                                        final double ibx = it.bDouble;
7132                                        double ox;
7133                                        ox = (iax / ibx);
7134                                        of64data[it.oIndex] = ox;
7135                                }
7136                        } else {
7137                                while (it.hasNext()) {
7138                                        final long iax = it.aLong;
7139                                        final long ibx = it.bLong;
7140                                        double ox;
7141                                        ox = (iax / ibx);
7142                                        of64data[it.oIndex] = ox;
7143                                }
7144                        }
7145                        break;
7146                case Dataset.ARRAYFLOAT32:
7147                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
7148                        if (is == 1) {
7149                                if (it.isOutputDouble()) {
7150                                        while (it.hasNext()) {
7151                                                final double iax = it.aDouble;
7152                                                final double ibx = it.bDouble;
7153                                                float ox;
7154                                                ox = (float) (iax / ibx);
7155                                                oaf32data[it.oIndex] = ox;
7156                                        }
7157                                } else {
7158                                        while (it.hasNext()) {
7159                                                final long iax = it.aLong;
7160                                                final long ibx = it.bLong;
7161                                                float ox;
7162                                                ox = (iax / ibx);
7163                                                oaf32data[it.oIndex] = ox;
7164                                        }
7165                                }
7166                        } else if (as < bs) {
7167                                if (it.isOutputDouble()) {
7168                                        while (it.hasNext()) {
7169                                                final double iax = it.aDouble;
7170                                                double ibx = it.bDouble;
7171                                                float ox;
7172                                                ox = (float) (iax / ibx);
7173                                                oaf32data[it.oIndex] = ox;
7174                                                for (int j = 1; j < is; j++) {
7175                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7176                                                        ox = (float) (iax / ibx);
7177                                                        oaf32data[it.oIndex + j] = ox;
7178                                                }
7179                                        }
7180                                } else {
7181                                        while (it.hasNext()) {
7182                                                final long iax = it.aLong;
7183                                                long ibx = it.bLong;
7184                                                float ox;
7185                                                ox = (iax / ibx);
7186                                                oaf32data[it.oIndex] = ox;
7187                                                for (int j = 1; j < is; j++) {
7188                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7189                                                        ox = (iax / ibx);
7190                                                        oaf32data[it.oIndex + j] = ox;
7191                                                }
7192                                        }
7193                                }
7194                        } else if (as > bs) {
7195                                if (it.isOutputDouble()) {
7196                                        while (it.hasNext()) {
7197                                                double iax = it.aDouble;
7198                                                final double ibx = it.bDouble;
7199                                                float ox;
7200                                                ox = (float) (iax / ibx);
7201                                                oaf32data[it.oIndex] = ox;
7202                                                for (int j = 1; j < is; j++) {
7203                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7204                                                        ox = (float) (iax / ibx);
7205                                                        oaf32data[it.oIndex + j] = ox;
7206                                                }
7207                                        }
7208                                } else {
7209                                        while (it.hasNext()) {
7210                                                long iax = it.aLong;
7211                                                final long ibx = it.bLong;
7212                                                float ox;
7213                                                ox = (iax / ibx);
7214                                                oaf32data[it.oIndex] = ox;
7215                                                for (int j = 1; j < is; j++) {
7216                                                        iax = da.getElementLongAbs(it.aIndex + j);
7217                                                        ox = (iax / ibx);
7218                                                        oaf32data[it.oIndex + j] = ox;
7219                                                }
7220                                        }
7221                                }
7222                        } else if (as == 1) {
7223                                if (it.isOutputDouble()) {
7224                                        while (it.hasNext()) {
7225                                                final double iax = it.aDouble;
7226                                                final double ibx = it.bDouble;
7227                                                float ox;
7228                                                ox = (float) (iax / ibx);
7229                                                for (int j = 0; j < is; j++) {
7230                                                        oaf32data[it.oIndex + j] = ox;
7231                                                }
7232                                        }
7233                                } else {
7234                                        while (it.hasNext()) {
7235                                                final long iax = it.aLong;
7236                                                final long ibx = it.bLong;
7237                                                float ox;
7238                                                ox = (iax / ibx);
7239                                                for (int j = 0; j < is; j++) {
7240                                                        oaf32data[it.oIndex + j] = ox;
7241                                                }
7242                                        }
7243                                }
7244                        } else {
7245                                if (it.isOutputDouble()) {
7246                                        while (it.hasNext()) {
7247                                                double iax = it.aDouble;
7248                                                double ibx = it.bDouble;
7249                                                float ox;
7250                                                ox = (float) (iax / ibx);
7251                                                oaf32data[it.oIndex] = ox;
7252                                                for (int j = 1; j < is; j++) {
7253                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7254                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7255                                                        ox = (float) (iax / ibx);
7256                                                        oaf32data[it.oIndex + j] = ox;
7257                                                }
7258                                        }
7259                                } else {
7260                                        while (it.hasNext()) {
7261                                                long iax = it.aLong;
7262                                                long ibx = it.bLong;
7263                                                float ox;
7264                                                ox = (iax / ibx);
7265                                                oaf32data[it.oIndex] = ox;
7266                                                for (int j = 1; j < is; j++) {
7267                                                        iax = da.getElementLongAbs(it.aIndex + j);
7268                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7269                                                        ox = (iax / ibx);
7270                                                        oaf32data[it.oIndex + j] = ox;
7271                                                }
7272                                        }
7273                                }
7274                        }
7275                        break;
7276                case Dataset.ARRAYFLOAT64:
7277                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
7278                        if (is == 1) {
7279                                if (it.isOutputDouble()) {
7280                                        while (it.hasNext()) {
7281                                                final double iax = it.aDouble;
7282                                                final double ibx = it.bDouble;
7283                                                double ox;
7284                                                ox = (iax / ibx);
7285                                                oaf64data[it.oIndex] = ox;
7286                                        }
7287                                } else {
7288                                        while (it.hasNext()) {
7289                                                final long iax = it.aLong;
7290                                                final long ibx = it.bLong;
7291                                                double ox;
7292                                                ox = (iax / ibx);
7293                                                oaf64data[it.oIndex] = ox;
7294                                        }
7295                                }
7296                        } else if (as < bs) {
7297                                if (it.isOutputDouble()) {
7298                                        while (it.hasNext()) {
7299                                                final double iax = it.aDouble;
7300                                                double ibx = it.bDouble;
7301                                                double ox;
7302                                                ox = (iax / ibx);
7303                                                oaf64data[it.oIndex] = ox;
7304                                                for (int j = 1; j < is; j++) {
7305                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7306                                                        ox = (iax / ibx);
7307                                                        oaf64data[it.oIndex + j] = ox;
7308                                                }
7309                                        }
7310                                } else {
7311                                        while (it.hasNext()) {
7312                                                final long iax = it.aLong;
7313                                                long ibx = it.bLong;
7314                                                double ox;
7315                                                ox = (iax / ibx);
7316                                                oaf64data[it.oIndex] = ox;
7317                                                for (int j = 1; j < is; j++) {
7318                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7319                                                        ox = (iax / ibx);
7320                                                        oaf64data[it.oIndex + j] = ox;
7321                                                }
7322                                        }
7323                                }
7324                        } else if (as > bs) {
7325                                if (it.isOutputDouble()) {
7326                                        while (it.hasNext()) {
7327                                                double iax = it.aDouble;
7328                                                final double ibx = it.bDouble;
7329                                                double ox;
7330                                                ox = (iax / ibx);
7331                                                oaf64data[it.oIndex] = ox;
7332                                                for (int j = 1; j < is; j++) {
7333                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7334                                                        ox = (iax / ibx);
7335                                                        oaf64data[it.oIndex + j] = ox;
7336                                                }
7337                                        }
7338                                } else {
7339                                        while (it.hasNext()) {
7340                                                long iax = it.aLong;
7341                                                final long ibx = it.bLong;
7342                                                double ox;
7343                                                ox = (iax / ibx);
7344                                                oaf64data[it.oIndex] = ox;
7345                                                for (int j = 1; j < is; j++) {
7346                                                        iax = da.getElementLongAbs(it.aIndex + j);
7347                                                        ox = (iax / ibx);
7348                                                        oaf64data[it.oIndex + j] = ox;
7349                                                }
7350                                        }
7351                                }
7352                        } else if (as == 1) {
7353                                if (it.isOutputDouble()) {
7354                                        while (it.hasNext()) {
7355                                                final double iax = it.aDouble;
7356                                                final double ibx = it.bDouble;
7357                                                double ox;
7358                                                ox = (iax / ibx);
7359                                                for (int j = 0; j < is; j++) {
7360                                                        oaf64data[it.oIndex + j] = ox;
7361                                                }
7362                                        }
7363                                } else {
7364                                        while (it.hasNext()) {
7365                                                final long iax = it.aLong;
7366                                                final long ibx = it.bLong;
7367                                                double ox;
7368                                                ox = (iax / ibx);
7369                                                for (int j = 0; j < is; j++) {
7370                                                        oaf64data[it.oIndex + j] = ox;
7371                                                }
7372                                        }
7373                                }
7374                        } else {
7375                                if (it.isOutputDouble()) {
7376                                        while (it.hasNext()) {
7377                                                double iax = it.aDouble;
7378                                                double ibx = it.bDouble;
7379                                                double ox;
7380                                                ox = (iax / ibx);
7381                                                oaf64data[it.oIndex] = ox;
7382                                                for (int j = 1; j < is; j++) {
7383                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7384                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7385                                                        ox = (iax / ibx);
7386                                                        oaf64data[it.oIndex + j] = ox;
7387                                                }
7388                                        }
7389                                } else {
7390                                        while (it.hasNext()) {
7391                                                long iax = it.aLong;
7392                                                long ibx = it.bLong;
7393                                                double ox;
7394                                                ox = (iax / ibx);
7395                                                oaf64data[it.oIndex] = ox;
7396                                                for (int j = 1; j < is; j++) {
7397                                                        iax = da.getElementLongAbs(it.aIndex + j);
7398                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7399                                                        ox = (iax / ibx);
7400                                                        oaf64data[it.oIndex + j] = ox;
7401                                                }
7402                                        }
7403                                }
7404                        }
7405                        break;
7406                case Dataset.COMPLEX64:
7407                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
7408                        if (!da.isComplex()) {
7409                                if (it.isOutputDouble()) {
7410                                        final double iay = 0;
7411                                        if (db.isComplex()) {
7412                                                while (it.hasNext()) {
7413                                                        final double iax = it.aDouble;
7414                                                        final double ibx = it.bDouble;
7415                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
7416                                                        float ox;
7417                                                        float oy;
7418                                                        float q;
7419                                                        float den;
7420                                                        if (iby == 0) {
7421                                                                ox = (float) (iax / ibx);
7422                                                                oy = (float) (iay / ibx);
7423                                                        } else if (ibx == 0) {
7424                                                                ox = (float) (iay / iby);
7425                                                                oy = (float) (-iax / iby);
7426                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
7427                                                                q = (float) (ibx / iby);
7428                                                                den = (float) (ibx * q + iby);
7429                                                                ox = (float) ((iax * q + iay) / den);
7430                                                                oy = (float) ((iay * q - iax) / den);
7431                                                        } else {
7432                                                                q = (float) (iby / ibx);
7433                                                                den = (float) (iby * q + ibx);
7434                                                                ox = (float) ((iay * q + iax) / den);
7435                                                                oy = (float) ((iay - iax * q) / den);
7436                                                        }
7437                                                        oc64data[it.oIndex] = ox;
7438                                                        oc64data[it.oIndex + 1] = oy;
7439                                                }
7440                                        } else {
7441                                                while (it.hasNext()) {
7442                                                        final double iax = it.aDouble;
7443                                                        final double ibx = it.bDouble;
7444                                                        float ox;
7445                                                        float oy;
7446                                                        ox = (float) (iax / ibx);
7447                                                        oy = (float) (iay / ibx);
7448                                                        oc64data[it.oIndex] = ox;
7449                                                        oc64data[it.oIndex + 1] = oy;
7450                                                }
7451                                        }
7452                                } else {
7453                                        final long iay = 0;
7454                                        while (it.hasNext()) {
7455                                                final long iax = it.aLong;
7456                                                final long ibx = it.bLong;
7457                                                float ox;
7458                                                float oy;
7459                                                ox = (float) (iax / ibx);
7460                                                oy = (float) (iay / ibx);
7461                                                oc64data[it.oIndex] = ox;
7462                                                oc64data[it.oIndex + 1] = oy;
7463                                        }
7464                                }
7465                        } else if (!db.isComplex()) {
7466                                while (it.hasNext()) {
7467                                        final double iax = it.aDouble;
7468                                        final double ibx = it.bDouble;
7469                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
7470                                        float ox;
7471                                        float oy;
7472                                        ox = (float) (iax / ibx);
7473                                        oy = (float) (iay / ibx);
7474                                        oc64data[it.oIndex] = ox;
7475                                        oc64data[it.oIndex + 1] = oy;
7476                                }
7477                        } else {
7478                                while (it.hasNext()) {
7479                                        final double iax = it.aDouble;
7480                                        final double ibx = it.bDouble;
7481                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
7482                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
7483                                        float ox;
7484                                        float oy;
7485                                        float q;
7486                                        float den;
7487                                        if (iby == 0) {
7488                                                ox = (float) (iax / ibx);
7489                                                oy = (float) (iay / ibx);
7490                                        } else if (ibx == 0) {
7491                                                ox = (float) (iay / iby);
7492                                                oy = (float) (-iax / iby);
7493                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
7494                                                q = (float) (ibx / iby);
7495                                                den = (float) (ibx * q + iby);
7496                                                ox = (float) ((iax * q + iay) / den);
7497                                                oy = (float) ((iay * q - iax) / den);
7498                                        } else {
7499                                                q = (float) (iby / ibx);
7500                                                den = (float) (iby * q + ibx);
7501                                                ox = (float) ((iay * q + iax) / den);
7502                                                oy = (float) ((iay - iax * q) / den);
7503                                        }
7504                                        oc64data[it.oIndex] = ox;
7505                                        oc64data[it.oIndex + 1] = oy;
7506                                }
7507                        }
7508                        break;
7509                case Dataset.COMPLEX128:
7510                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
7511                        if (!da.isComplex()) {
7512                                if (it.isOutputDouble()) {
7513                                        final double iay = 0;
7514                                        if (db.isComplex()) {
7515                                                while (it.hasNext()) {
7516                                                        final double iax = it.aDouble;
7517                                                        final double ibx = it.bDouble;
7518                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
7519                                                        double ox;
7520                                                        double oy;
7521                                                        double q;
7522                                                        double den;
7523                                                        if (iby == 0) {
7524                                                                ox = (iax / ibx);
7525                                                                oy = (iay / ibx);
7526                                                        } else if (ibx == 0) {
7527                                                                ox = (iay / iby);
7528                                                                oy = (-iax / iby);
7529                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
7530                                                                q = (ibx / iby);
7531                                                                den = (ibx * q + iby);
7532                                                                ox = ((iax * q + iay) / den);
7533                                                                oy = ((iay * q - iax) / den);
7534                                                        } else {
7535                                                                q = (iby / ibx);
7536                                                                den = (iby * q + ibx);
7537                                                                ox = ((iay * q + iax) / den);
7538                                                                oy = ((iay - iax * q) / den);
7539                                                        }
7540                                                        oc128data[it.oIndex] = ox;
7541                                                        oc128data[it.oIndex + 1] = oy;
7542                                                }
7543                                        } else {
7544                                                while (it.hasNext()) {
7545                                                        final double iax = it.aDouble;
7546                                                        final double ibx = it.bDouble;
7547                                                        double ox;
7548                                                        double oy;
7549                                                        ox = (iax / ibx);
7550                                                        oy = (iay / ibx);
7551                                                        oc128data[it.oIndex] = ox;
7552                                                        oc128data[it.oIndex + 1] = oy;
7553                                                }
7554                                        }
7555                                } else {
7556                                        final long iay = 0;
7557                                        while (it.hasNext()) {
7558                                                final long iax = it.aLong;
7559                                                final long ibx = it.bLong;
7560                                                double ox;
7561                                                double oy;
7562                                                ox = (iax / ibx);
7563                                                oy = (iay / ibx);
7564                                                oc128data[it.oIndex] = ox;
7565                                                oc128data[it.oIndex + 1] = oy;
7566                                        }
7567                                }
7568                        } else if (!db.isComplex()) {
7569                                while (it.hasNext()) {
7570                                        final double iax = it.aDouble;
7571                                        final double ibx = it.bDouble;
7572                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
7573                                        double ox;
7574                                        double oy;
7575                                        ox = (iax / ibx);
7576                                        oy = (iay / ibx);
7577                                        oc128data[it.oIndex] = ox;
7578                                        oc128data[it.oIndex + 1] = oy;
7579                                }
7580                        } else {
7581                                while (it.hasNext()) {
7582                                        final double iax = it.aDouble;
7583                                        final double ibx = it.bDouble;
7584                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
7585                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
7586                                        double ox;
7587                                        double oy;
7588                                        double q;
7589                                        double den;
7590                                        if (iby == 0) {
7591                                                ox = (iax / ibx);
7592                                                oy = (iay / ibx);
7593                                        } else if (ibx == 0) {
7594                                                ox = (iay / iby);
7595                                                oy = (-iax / iby);
7596                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
7597                                                q = (ibx / iby);
7598                                                den = (ibx * q + iby);
7599                                                ox = ((iax * q + iay) / den);
7600                                                oy = ((iay * q - iax) / den);
7601                                        } else {
7602                                                q = (iby / ibx);
7603                                                den = (iby * q + ibx);
7604                                                ox = ((iay * q + iax) / den);
7605                                                oy = ((iay - iax * q) / den);
7606                                        }
7607                                        oc128data[it.oIndex] = ox;
7608                                        oc128data[it.oIndex + 1] = oy;
7609                                }
7610                        }
7611                        break;
7612                default:
7613                        throw new IllegalArgumentException("divide supports integer, compound integer, real, compound real, complex datasets only");
7614                }
7615
7616                addBinaryOperatorName(da, db, result, "/");
7617                return result;
7618        }
7619
7620        /**
7621         * dividez operator
7622         * @param a first operand
7623         * @param b second operand
7624         * @return {@code a / b}, division of a by b
7625         */
7626        public static Dataset dividez(final Object a, final Object b) {
7627                return dividez(a, b, null);
7628        }
7629
7630        /**
7631         * dividez operator
7632         * @param a first operand
7633         * @param b second operand
7634         * @param o output can be null - in which case, a new dataset is created
7635         * @return {@code a / b}, division of a by b
7636         */
7637        public static Dataset dividez(final Object a, final Object b, final Dataset o) {
7638                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
7639                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
7640                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
7641                final Dataset result = it.getOutput();
7642                if (!result.isComplex()) {
7643                        boolean change = false;
7644                        if (da.isComplex()) {
7645                                da = da.getRealView();
7646                                change = true;
7647                        }
7648                        if (db.isComplex()) {
7649                                db = db.getRealView();
7650                                change = true;
7651                        }
7652                        if (change) {
7653                                it = BroadcastIterator.createIterator(da, db, result, true);
7654                        }
7655                }
7656                final int is = result.getElementsPerItem();
7657                final int as = da.getElementsPerItem();
7658                final int bs = db.getElementsPerItem();
7659                final int dt = result.getDType();
7660
7661                switch(dt) {
7662                case Dataset.INT8:
7663                        final byte[] oi8data = ((ByteDataset) result).getData();
7664                        if (it.isOutputDouble()) {
7665                                while (it.hasNext()) {
7666                                        final double iax = it.aDouble;
7667                                        final double ibx = it.bDouble;
7668                                        byte ox;
7669                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7670                                        oi8data[it.oIndex] = ox;
7671                                }
7672                        } else {
7673                                while (it.hasNext()) {
7674                                        final long iax = it.aLong;
7675                                        final long ibx = it.bLong;
7676                                        byte ox;
7677                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7678                                        oi8data[it.oIndex] = ox;
7679                                }
7680                        }
7681                        break;
7682                case Dataset.INT16:
7683                        final short[] oi16data = ((ShortDataset) result).getData();
7684                        if (it.isOutputDouble()) {
7685                                while (it.hasNext()) {
7686                                        final double iax = it.aDouble;
7687                                        final double ibx = it.bDouble;
7688                                        short ox;
7689                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
7690                                        oi16data[it.oIndex] = ox;
7691                                }
7692                        } else {
7693                                while (it.hasNext()) {
7694                                        final long iax = it.aLong;
7695                                        final long ibx = it.bLong;
7696                                        short ox;
7697                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
7698                                        oi16data[it.oIndex] = ox;
7699                                }
7700                        }
7701                        break;
7702                case Dataset.INT64:
7703                        final long[] oi64data = ((LongDataset) result).getData();
7704                        if (it.isOutputDouble()) {
7705                                while (it.hasNext()) {
7706                                        final double iax = it.aDouble;
7707                                        final double ibx = it.bDouble;
7708                                        long ox;
7709                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
7710                                        oi64data[it.oIndex] = ox;
7711                                }
7712                        } else {
7713                                while (it.hasNext()) {
7714                                        final long iax = it.aLong;
7715                                        final long ibx = it.bLong;
7716                                        long ox;
7717                                        ox = (ibx == 0 ? 0 : iax / ibx);
7718                                        oi64data[it.oIndex] = ox;
7719                                }
7720                        }
7721                        break;
7722                case Dataset.INT32:
7723                        final int[] oi32data = ((IntegerDataset) result).getData();
7724                        if (it.isOutputDouble()) {
7725                                while (it.hasNext()) {
7726                                        final double iax = it.aDouble;
7727                                        final double ibx = it.bDouble;
7728                                        int ox;
7729                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
7730                                        oi32data[it.oIndex] = ox;
7731                                }
7732                        } else {
7733                                while (it.hasNext()) {
7734                                        final long iax = it.aLong;
7735                                        final long ibx = it.bLong;
7736                                        int ox;
7737                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
7738                                        oi32data[it.oIndex] = ox;
7739                                }
7740                        }
7741                        break;
7742                case Dataset.ARRAYINT8:
7743                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
7744                        if (is == 1) {
7745                                if (it.isOutputDouble()) {
7746                                        while (it.hasNext()) {
7747                                                final double iax = it.aDouble;
7748                                                final double ibx = it.bDouble;
7749                                                byte ox;
7750                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7751                                                oai8data[it.oIndex] = ox;
7752                                        }
7753                                } else {
7754                                        while (it.hasNext()) {
7755                                                final long iax = it.aLong;
7756                                                final long ibx = it.bLong;
7757                                                byte ox;
7758                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7759                                                oai8data[it.oIndex] = ox;
7760                                        }
7761                                }
7762                        } else if (as < bs) {
7763                                if (it.isOutputDouble()) {
7764                                        while (it.hasNext()) {
7765                                                final double iax = it.aDouble;
7766                                                double ibx = it.bDouble;
7767                                                byte ox;
7768                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7769                                                oai8data[it.oIndex] = ox;
7770                                                for (int j = 1; j < is; j++) {
7771                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7772                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7773                                                        oai8data[it.oIndex + j] = ox;
7774                                                }
7775                                        }
7776                                } else {
7777                                        while (it.hasNext()) {
7778                                                final long iax = it.aLong;
7779                                                long ibx = it.bLong;
7780                                                byte ox;
7781                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7782                                                oai8data[it.oIndex] = ox;
7783                                                for (int j = 1; j < is; j++) {
7784                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7785                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7786                                                        oai8data[it.oIndex + j] = ox;
7787                                                }
7788                                        }
7789                                }
7790                        } else if (as > bs) {
7791                                if (it.isOutputDouble()) {
7792                                        while (it.hasNext()) {
7793                                                double iax = it.aDouble;
7794                                                final double ibx = it.bDouble;
7795                                                byte ox;
7796                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7797                                                oai8data[it.oIndex] = ox;
7798                                                for (int j = 1; j < is; j++) {
7799                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7800                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7801                                                        oai8data[it.oIndex + j] = ox;
7802                                                }
7803                                        }
7804                                } else {
7805                                        while (it.hasNext()) {
7806                                                long iax = it.aLong;
7807                                                final long ibx = it.bLong;
7808                                                byte ox;
7809                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7810                                                oai8data[it.oIndex] = ox;
7811                                                for (int j = 1; j < is; j++) {
7812                                                        iax = da.getElementLongAbs(it.aIndex + j);
7813                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7814                                                        oai8data[it.oIndex + j] = ox;
7815                                                }
7816                                        }
7817                                }
7818                        } else if (as == 1) {
7819                                if (it.isOutputDouble()) {
7820                                        while (it.hasNext()) {
7821                                                final double iax = it.aDouble;
7822                                                final double ibx = it.bDouble;
7823                                                byte ox;
7824                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7825                                                for (int j = 0; j < is; j++) {
7826                                                        oai8data[it.oIndex + j] = ox;
7827                                                }
7828                                        }
7829                                } else {
7830                                        while (it.hasNext()) {
7831                                                final long iax = it.aLong;
7832                                                final long ibx = it.bLong;
7833                                                byte ox;
7834                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7835                                                for (int j = 0; j < is; j++) {
7836                                                        oai8data[it.oIndex + j] = ox;
7837                                                }
7838                                        }
7839                                }
7840                        } else {
7841                                if (it.isOutputDouble()) {
7842                                        while (it.hasNext()) {
7843                                                double iax = it.aDouble;
7844                                                double ibx = it.bDouble;
7845                                                byte ox;
7846                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7847                                                oai8data[it.oIndex] = ox;
7848                                                for (int j = 1; j < is; j++) {
7849                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7850                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7851                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
7852                                                        oai8data[it.oIndex + j] = ox;
7853                                                }
7854                                        }
7855                                } else {
7856                                        while (it.hasNext()) {
7857                                                long iax = it.aLong;
7858                                                long ibx = it.bLong;
7859                                                byte ox;
7860                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7861                                                oai8data[it.oIndex] = ox;
7862                                                for (int j = 1; j < is; j++) {
7863                                                        iax = da.getElementLongAbs(it.aIndex + j);
7864                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7865                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
7866                                                        oai8data[it.oIndex + j] = ox;
7867                                                }
7868                                        }
7869                                }
7870                        }
7871                        break;
7872                case Dataset.ARRAYINT16:
7873                        final short[] oai16data = ((CompoundShortDataset) result).getData();
7874                        if (is == 1) {
7875                                if (it.isOutputDouble()) {
7876                                        while (it.hasNext()) {
7877                                                final double iax = it.aDouble;
7878                                                final double ibx = it.bDouble;
7879                                                short ox;
7880                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
7881                                                oai16data[it.oIndex] = ox;
7882                                        }
7883                                } else {
7884                                        while (it.hasNext()) {
7885                                                final long iax = it.aLong;
7886                                                final long ibx = it.bLong;
7887                                                short ox;
7888                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
7889                                                oai16data[it.oIndex] = ox;
7890                                        }
7891                                }
7892                        } else if (as < bs) {
7893                                if (it.isOutputDouble()) {
7894                                        while (it.hasNext()) {
7895                                                final double iax = it.aDouble;
7896                                                double ibx = it.bDouble;
7897                                                short ox;
7898                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
7899                                                oai16data[it.oIndex] = ox;
7900                                                for (int j = 1; j < is; j++) {
7901                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7902                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
7903                                                        oai16data[it.oIndex + j] = ox;
7904                                                }
7905                                        }
7906                                } else {
7907                                        while (it.hasNext()) {
7908                                                final long iax = it.aLong;
7909                                                long ibx = it.bLong;
7910                                                short ox;
7911                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
7912                                                oai16data[it.oIndex] = ox;
7913                                                for (int j = 1; j < is; j++) {
7914                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7915                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
7916                                                        oai16data[it.oIndex + j] = ox;
7917                                                }
7918                                        }
7919                                }
7920                        } else if (as > bs) {
7921                                if (it.isOutputDouble()) {
7922                                        while (it.hasNext()) {
7923                                                double iax = it.aDouble;
7924                                                final double ibx = it.bDouble;
7925                                                short ox;
7926                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
7927                                                oai16data[it.oIndex] = ox;
7928                                                for (int j = 1; j < is; j++) {
7929                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7930                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
7931                                                        oai16data[it.oIndex + j] = ox;
7932                                                }
7933                                        }
7934                                } else {
7935                                        while (it.hasNext()) {
7936                                                long iax = it.aLong;
7937                                                final long ibx = it.bLong;
7938                                                short ox;
7939                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
7940                                                oai16data[it.oIndex] = ox;
7941                                                for (int j = 1; j < is; j++) {
7942                                                        iax = da.getElementLongAbs(it.aIndex + j);
7943                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
7944                                                        oai16data[it.oIndex + j] = ox;
7945                                                }
7946                                        }
7947                                }
7948                        } else if (as == 1) {
7949                                if (it.isOutputDouble()) {
7950                                        while (it.hasNext()) {
7951                                                final double iax = it.aDouble;
7952                                                final double ibx = it.bDouble;
7953                                                short ox;
7954                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
7955                                                for (int j = 0; j < is; j++) {
7956                                                        oai16data[it.oIndex + j] = ox;
7957                                                }
7958                                        }
7959                                } else {
7960                                        while (it.hasNext()) {
7961                                                final long iax = it.aLong;
7962                                                final long ibx = it.bLong;
7963                                                short ox;
7964                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
7965                                                for (int j = 0; j < is; j++) {
7966                                                        oai16data[it.oIndex + j] = ox;
7967                                                }
7968                                        }
7969                                }
7970                        } else {
7971                                if (it.isOutputDouble()) {
7972                                        while (it.hasNext()) {
7973                                                double iax = it.aDouble;
7974                                                double ibx = it.bDouble;
7975                                                short ox;
7976                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
7977                                                oai16data[it.oIndex] = ox;
7978                                                for (int j = 1; j < is; j++) {
7979                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
7980                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
7981                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
7982                                                        oai16data[it.oIndex + j] = ox;
7983                                                }
7984                                        }
7985                                } else {
7986                                        while (it.hasNext()) {
7987                                                long iax = it.aLong;
7988                                                long ibx = it.bLong;
7989                                                short ox;
7990                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
7991                                                oai16data[it.oIndex] = ox;
7992                                                for (int j = 1; j < is; j++) {
7993                                                        iax = da.getElementLongAbs(it.aIndex + j);
7994                                                        ibx = db.getElementLongAbs(it.bIndex + j);
7995                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
7996                                                        oai16data[it.oIndex + j] = ox;
7997                                                }
7998                                        }
7999                                }
8000                        }
8001                        break;
8002                case Dataset.ARRAYINT64:
8003                        final long[] oai64data = ((CompoundLongDataset) result).getData();
8004                        if (is == 1) {
8005                                if (it.isOutputDouble()) {
8006                                        while (it.hasNext()) {
8007                                                final double iax = it.aDouble;
8008                                                final double ibx = it.bDouble;
8009                                                long ox;
8010                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
8011                                                oai64data[it.oIndex] = ox;
8012                                        }
8013                                } else {
8014                                        while (it.hasNext()) {
8015                                                final long iax = it.aLong;
8016                                                final long ibx = it.bLong;
8017                                                long ox;
8018                                                ox = (ibx == 0 ? 0 : iax / ibx);
8019                                                oai64data[it.oIndex] = ox;
8020                                        }
8021                                }
8022                        } else if (as < bs) {
8023                                if (it.isOutputDouble()) {
8024                                        while (it.hasNext()) {
8025                                                final double iax = it.aDouble;
8026                                                double ibx = it.bDouble;
8027                                                long ox;
8028                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
8029                                                oai64data[it.oIndex] = ox;
8030                                                for (int j = 1; j < is; j++) {
8031                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8032                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
8033                                                        oai64data[it.oIndex + j] = ox;
8034                                                }
8035                                        }
8036                                } else {
8037                                        while (it.hasNext()) {
8038                                                final long iax = it.aLong;
8039                                                long ibx = it.bLong;
8040                                                long ox;
8041                                                ox = (ibx == 0 ? 0 : iax / ibx);
8042                                                oai64data[it.oIndex] = ox;
8043                                                for (int j = 1; j < is; j++) {
8044                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8045                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8046                                                        oai64data[it.oIndex + j] = ox;
8047                                                }
8048                                        }
8049                                }
8050                        } else if (as > bs) {
8051                                if (it.isOutputDouble()) {
8052                                        while (it.hasNext()) {
8053                                                double iax = it.aDouble;
8054                                                final double ibx = it.bDouble;
8055                                                long ox;
8056                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
8057                                                oai64data[it.oIndex] = ox;
8058                                                for (int j = 1; j < is; j++) {
8059                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8060                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
8061                                                        oai64data[it.oIndex + j] = ox;
8062                                                }
8063                                        }
8064                                } else {
8065                                        while (it.hasNext()) {
8066                                                long iax = it.aLong;
8067                                                final long ibx = it.bLong;
8068                                                long ox;
8069                                                ox = (ibx == 0 ? 0 : iax / ibx);
8070                                                oai64data[it.oIndex] = ox;
8071                                                for (int j = 1; j < is; j++) {
8072                                                        iax = da.getElementLongAbs(it.aIndex + j);
8073                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8074                                                        oai64data[it.oIndex + j] = ox;
8075                                                }
8076                                        }
8077                                }
8078                        } else if (as == 1) {
8079                                if (it.isOutputDouble()) {
8080                                        while (it.hasNext()) {
8081                                                final double iax = it.aDouble;
8082                                                final double ibx = it.bDouble;
8083                                                long ox;
8084                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
8085                                                for (int j = 0; j < is; j++) {
8086                                                        oai64data[it.oIndex + j] = ox;
8087                                                }
8088                                        }
8089                                } else {
8090                                        while (it.hasNext()) {
8091                                                final long iax = it.aLong;
8092                                                final long ibx = it.bLong;
8093                                                long ox;
8094                                                ox = (ibx == 0 ? 0 : iax / ibx);
8095                                                for (int j = 0; j < is; j++) {
8096                                                        oai64data[it.oIndex + j] = ox;
8097                                                }
8098                                        }
8099                                }
8100                        } else {
8101                                if (it.isOutputDouble()) {
8102                                        while (it.hasNext()) {
8103                                                double iax = it.aDouble;
8104                                                double ibx = it.bDouble;
8105                                                long ox;
8106                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
8107                                                oai64data[it.oIndex] = ox;
8108                                                for (int j = 1; j < is; j++) {
8109                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8110                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8111                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
8112                                                        oai64data[it.oIndex + j] = ox;
8113                                                }
8114                                        }
8115                                } else {
8116                                        while (it.hasNext()) {
8117                                                long iax = it.aLong;
8118                                                long ibx = it.bLong;
8119                                                long ox;
8120                                                ox = (ibx == 0 ? 0 : iax / ibx);
8121                                                oai64data[it.oIndex] = ox;
8122                                                for (int j = 1; j < is; j++) {
8123                                                        iax = da.getElementLongAbs(it.aIndex + j);
8124                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8125                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8126                                                        oai64data[it.oIndex + j] = ox;
8127                                                }
8128                                        }
8129                                }
8130                        }
8131                        break;
8132                case Dataset.ARRAYINT32:
8133                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
8134                        if (is == 1) {
8135                                if (it.isOutputDouble()) {
8136                                        while (it.hasNext()) {
8137                                                final double iax = it.aDouble;
8138                                                final double ibx = it.bDouble;
8139                                                int ox;
8140                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8141                                                oai32data[it.oIndex] = ox;
8142                                        }
8143                                } else {
8144                                        while (it.hasNext()) {
8145                                                final long iax = it.aLong;
8146                                                final long ibx = it.bLong;
8147                                                int ox;
8148                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
8149                                                oai32data[it.oIndex] = ox;
8150                                        }
8151                                }
8152                        } else if (as < bs) {
8153                                if (it.isOutputDouble()) {
8154                                        while (it.hasNext()) {
8155                                                final double iax = it.aDouble;
8156                                                double ibx = it.bDouble;
8157                                                int ox;
8158                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8159                                                oai32data[it.oIndex] = ox;
8160                                                for (int j = 1; j < is; j++) {
8161                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8162                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8163                                                        oai32data[it.oIndex + j] = ox;
8164                                                }
8165                                        }
8166                                } else {
8167                                        while (it.hasNext()) {
8168                                                final long iax = it.aLong;
8169                                                long ibx = it.bLong;
8170                                                int ox;
8171                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
8172                                                oai32data[it.oIndex] = ox;
8173                                                for (int j = 1; j < is; j++) {
8174                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8175                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
8176                                                        oai32data[it.oIndex + j] = ox;
8177                                                }
8178                                        }
8179                                }
8180                        } else if (as > bs) {
8181                                if (it.isOutputDouble()) {
8182                                        while (it.hasNext()) {
8183                                                double iax = it.aDouble;
8184                                                final double ibx = it.bDouble;
8185                                                int ox;
8186                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8187                                                oai32data[it.oIndex] = ox;
8188                                                for (int j = 1; j < is; j++) {
8189                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8190                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8191                                                        oai32data[it.oIndex + j] = ox;
8192                                                }
8193                                        }
8194                                } else {
8195                                        while (it.hasNext()) {
8196                                                long iax = it.aLong;
8197                                                final long ibx = it.bLong;
8198                                                int ox;
8199                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
8200                                                oai32data[it.oIndex] = ox;
8201                                                for (int j = 1; j < is; j++) {
8202                                                        iax = da.getElementLongAbs(it.aIndex + j);
8203                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
8204                                                        oai32data[it.oIndex + j] = ox;
8205                                                }
8206                                        }
8207                                }
8208                        } else if (as == 1) {
8209                                if (it.isOutputDouble()) {
8210                                        while (it.hasNext()) {
8211                                                final double iax = it.aDouble;
8212                                                final double ibx = it.bDouble;
8213                                                int ox;
8214                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8215                                                for (int j = 0; j < is; j++) {
8216                                                        oai32data[it.oIndex + j] = ox;
8217                                                }
8218                                        }
8219                                } else {
8220                                        while (it.hasNext()) {
8221                                                final long iax = it.aLong;
8222                                                final long ibx = it.bLong;
8223                                                int ox;
8224                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
8225                                                for (int j = 0; j < is; j++) {
8226                                                        oai32data[it.oIndex + j] = ox;
8227                                                }
8228                                        }
8229                                }
8230                        } else {
8231                                if (it.isOutputDouble()) {
8232                                        while (it.hasNext()) {
8233                                                double iax = it.aDouble;
8234                                                double ibx = it.bDouble;
8235                                                int ox;
8236                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8237                                                oai32data[it.oIndex] = ox;
8238                                                for (int j = 1; j < is; j++) {
8239                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8240                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8241                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
8242                                                        oai32data[it.oIndex + j] = ox;
8243                                                }
8244                                        }
8245                                } else {
8246                                        while (it.hasNext()) {
8247                                                long iax = it.aLong;
8248                                                long ibx = it.bLong;
8249                                                int ox;
8250                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
8251                                                oai32data[it.oIndex] = ox;
8252                                                for (int j = 1; j < is; j++) {
8253                                                        iax = da.getElementLongAbs(it.aIndex + j);
8254                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8255                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
8256                                                        oai32data[it.oIndex + j] = ox;
8257                                                }
8258                                        }
8259                                }
8260                        }
8261                        break;
8262                case Dataset.FLOAT32:
8263                        final float[] of32data = ((FloatDataset) result).getData();
8264                        if (it.isOutputDouble()) {
8265                                while (it.hasNext()) {
8266                                        final double iax = it.aDouble;
8267                                        final double ibx = it.bDouble;
8268                                        float ox;
8269                                        ox = (float) (ibx == 0 ? 0 : iax / ibx);
8270                                        of32data[it.oIndex] = ox;
8271                                }
8272                        } else {
8273                                while (it.hasNext()) {
8274                                        final long iax = it.aLong;
8275                                        final long ibx = it.bLong;
8276                                        float ox;
8277                                        ox = (ibx == 0 ? 0 : iax / ibx);
8278                                        of32data[it.oIndex] = ox;
8279                                }
8280                        }
8281                        break;
8282                case Dataset.FLOAT64:
8283                        final double[] of64data = ((DoubleDataset) result).getData();
8284                        if (it.isOutputDouble()) {
8285                                while (it.hasNext()) {
8286                                        final double iax = it.aDouble;
8287                                        final double ibx = it.bDouble;
8288                                        double ox;
8289                                        ox = (ibx == 0 ? 0 : iax / ibx);
8290                                        of64data[it.oIndex] = ox;
8291                                }
8292                        } else {
8293                                while (it.hasNext()) {
8294                                        final long iax = it.aLong;
8295                                        final long ibx = it.bLong;
8296                                        double ox;
8297                                        ox = (ibx == 0 ? 0 : iax / ibx);
8298                                        of64data[it.oIndex] = ox;
8299                                }
8300                        }
8301                        break;
8302                case Dataset.ARRAYFLOAT32:
8303                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
8304                        if (is == 1) {
8305                                if (it.isOutputDouble()) {
8306                                        while (it.hasNext()) {
8307                                                final double iax = it.aDouble;
8308                                                final double ibx = it.bDouble;
8309                                                float ox;
8310                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
8311                                                oaf32data[it.oIndex] = ox;
8312                                        }
8313                                } else {
8314                                        while (it.hasNext()) {
8315                                                final long iax = it.aLong;
8316                                                final long ibx = it.bLong;
8317                                                float ox;
8318                                                ox = (ibx == 0 ? 0 : iax / ibx);
8319                                                oaf32data[it.oIndex] = ox;
8320                                        }
8321                                }
8322                        } else if (as < bs) {
8323                                if (it.isOutputDouble()) {
8324                                        while (it.hasNext()) {
8325                                                final double iax = it.aDouble;
8326                                                double ibx = it.bDouble;
8327                                                float ox;
8328                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
8329                                                oaf32data[it.oIndex] = ox;
8330                                                for (int j = 1; j < is; j++) {
8331                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8332                                                        ox = (float) (ibx == 0 ? 0 : iax / ibx);
8333                                                        oaf32data[it.oIndex + j] = ox;
8334                                                }
8335                                        }
8336                                } else {
8337                                        while (it.hasNext()) {
8338                                                final long iax = it.aLong;
8339                                                long ibx = it.bLong;
8340                                                float ox;
8341                                                ox = (ibx == 0 ? 0 : iax / ibx);
8342                                                oaf32data[it.oIndex] = ox;
8343                                                for (int j = 1; j < is; j++) {
8344                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8345                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8346                                                        oaf32data[it.oIndex + j] = ox;
8347                                                }
8348                                        }
8349                                }
8350                        } else if (as > bs) {
8351                                if (it.isOutputDouble()) {
8352                                        while (it.hasNext()) {
8353                                                double iax = it.aDouble;
8354                                                final double ibx = it.bDouble;
8355                                                float ox;
8356                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
8357                                                oaf32data[it.oIndex] = ox;
8358                                                for (int j = 1; j < is; j++) {
8359                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8360                                                        ox = (float) (ibx == 0 ? 0 : iax / ibx);
8361                                                        oaf32data[it.oIndex + j] = ox;
8362                                                }
8363                                        }
8364                                } else {
8365                                        while (it.hasNext()) {
8366                                                long iax = it.aLong;
8367                                                final long ibx = it.bLong;
8368                                                float ox;
8369                                                ox = (ibx == 0 ? 0 : iax / ibx);
8370                                                oaf32data[it.oIndex] = ox;
8371                                                for (int j = 1; j < is; j++) {
8372                                                        iax = da.getElementLongAbs(it.aIndex + j);
8373                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8374                                                        oaf32data[it.oIndex + j] = ox;
8375                                                }
8376                                        }
8377                                }
8378                        } else if (as == 1) {
8379                                if (it.isOutputDouble()) {
8380                                        while (it.hasNext()) {
8381                                                final double iax = it.aDouble;
8382                                                final double ibx = it.bDouble;
8383                                                float ox;
8384                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
8385                                                for (int j = 0; j < is; j++) {
8386                                                        oaf32data[it.oIndex + j] = ox;
8387                                                }
8388                                        }
8389                                } else {
8390                                        while (it.hasNext()) {
8391                                                final long iax = it.aLong;
8392                                                final long ibx = it.bLong;
8393                                                float ox;
8394                                                ox = (ibx == 0 ? 0 : iax / ibx);
8395                                                for (int j = 0; j < is; j++) {
8396                                                        oaf32data[it.oIndex + j] = ox;
8397                                                }
8398                                        }
8399                                }
8400                        } else {
8401                                if (it.isOutputDouble()) {
8402                                        while (it.hasNext()) {
8403                                                double iax = it.aDouble;
8404                                                double ibx = it.bDouble;
8405                                                float ox;
8406                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
8407                                                oaf32data[it.oIndex] = ox;
8408                                                for (int j = 1; j < is; j++) {
8409                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8410                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8411                                                        ox = (float) (ibx == 0 ? 0 : iax / ibx);
8412                                                        oaf32data[it.oIndex + j] = ox;
8413                                                }
8414                                        }
8415                                } else {
8416                                        while (it.hasNext()) {
8417                                                long iax = it.aLong;
8418                                                long ibx = it.bLong;
8419                                                float ox;
8420                                                ox = (ibx == 0 ? 0 : iax / ibx);
8421                                                oaf32data[it.oIndex] = ox;
8422                                                for (int j = 1; j < is; j++) {
8423                                                        iax = da.getElementLongAbs(it.aIndex + j);
8424                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8425                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8426                                                        oaf32data[it.oIndex + j] = ox;
8427                                                }
8428                                        }
8429                                }
8430                        }
8431                        break;
8432                case Dataset.ARRAYFLOAT64:
8433                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
8434                        if (is == 1) {
8435                                if (it.isOutputDouble()) {
8436                                        while (it.hasNext()) {
8437                                                final double iax = it.aDouble;
8438                                                final double ibx = it.bDouble;
8439                                                double ox;
8440                                                ox = (ibx == 0 ? 0 : iax / ibx);
8441                                                oaf64data[it.oIndex] = ox;
8442                                        }
8443                                } else {
8444                                        while (it.hasNext()) {
8445                                                final long iax = it.aLong;
8446                                                final long ibx = it.bLong;
8447                                                double ox;
8448                                                ox = (ibx == 0 ? 0 : iax / ibx);
8449                                                oaf64data[it.oIndex] = ox;
8450                                        }
8451                                }
8452                        } else if (as < bs) {
8453                                if (it.isOutputDouble()) {
8454                                        while (it.hasNext()) {
8455                                                final double iax = it.aDouble;
8456                                                double ibx = it.bDouble;
8457                                                double ox;
8458                                                ox = (ibx == 0 ? 0 : iax / ibx);
8459                                                oaf64data[it.oIndex] = ox;
8460                                                for (int j = 1; j < is; j++) {
8461                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8462                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8463                                                        oaf64data[it.oIndex + j] = ox;
8464                                                }
8465                                        }
8466                                } else {
8467                                        while (it.hasNext()) {
8468                                                final long iax = it.aLong;
8469                                                long ibx = it.bLong;
8470                                                double ox;
8471                                                ox = (ibx == 0 ? 0 : iax / ibx);
8472                                                oaf64data[it.oIndex] = ox;
8473                                                for (int j = 1; j < is; j++) {
8474                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8475                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8476                                                        oaf64data[it.oIndex + j] = ox;
8477                                                }
8478                                        }
8479                                }
8480                        } else if (as > bs) {
8481                                if (it.isOutputDouble()) {
8482                                        while (it.hasNext()) {
8483                                                double iax = it.aDouble;
8484                                                final double ibx = it.bDouble;
8485                                                double ox;
8486                                                ox = (ibx == 0 ? 0 : iax / ibx);
8487                                                oaf64data[it.oIndex] = ox;
8488                                                for (int j = 1; j < is; j++) {
8489                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8490                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8491                                                        oaf64data[it.oIndex + j] = ox;
8492                                                }
8493                                        }
8494                                } else {
8495                                        while (it.hasNext()) {
8496                                                long iax = it.aLong;
8497                                                final long ibx = it.bLong;
8498                                                double ox;
8499                                                ox = (ibx == 0 ? 0 : iax / ibx);
8500                                                oaf64data[it.oIndex] = ox;
8501                                                for (int j = 1; j < is; j++) {
8502                                                        iax = da.getElementLongAbs(it.aIndex + j);
8503                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8504                                                        oaf64data[it.oIndex + j] = ox;
8505                                                }
8506                                        }
8507                                }
8508                        } else if (as == 1) {
8509                                if (it.isOutputDouble()) {
8510                                        while (it.hasNext()) {
8511                                                final double iax = it.aDouble;
8512                                                final double ibx = it.bDouble;
8513                                                double ox;
8514                                                ox = (ibx == 0 ? 0 : iax / ibx);
8515                                                for (int j = 0; j < is; j++) {
8516                                                        oaf64data[it.oIndex + j] = ox;
8517                                                }
8518                                        }
8519                                } else {
8520                                        while (it.hasNext()) {
8521                                                final long iax = it.aLong;
8522                                                final long ibx = it.bLong;
8523                                                double ox;
8524                                                ox = (ibx == 0 ? 0 : iax / ibx);
8525                                                for (int j = 0; j < is; j++) {
8526                                                        oaf64data[it.oIndex + j] = ox;
8527                                                }
8528                                        }
8529                                }
8530                        } else {
8531                                if (it.isOutputDouble()) {
8532                                        while (it.hasNext()) {
8533                                                double iax = it.aDouble;
8534                                                double ibx = it.bDouble;
8535                                                double ox;
8536                                                ox = (ibx == 0 ? 0 : iax / ibx);
8537                                                oaf64data[it.oIndex] = ox;
8538                                                for (int j = 1; j < is; j++) {
8539                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
8540                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
8541                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8542                                                        oaf64data[it.oIndex + j] = ox;
8543                                                }
8544                                        }
8545                                } else {
8546                                        while (it.hasNext()) {
8547                                                long iax = it.aLong;
8548                                                long ibx = it.bLong;
8549                                                double ox;
8550                                                ox = (ibx == 0 ? 0 : iax / ibx);
8551                                                oaf64data[it.oIndex] = ox;
8552                                                for (int j = 1; j < is; j++) {
8553                                                        iax = da.getElementLongAbs(it.aIndex + j);
8554                                                        ibx = db.getElementLongAbs(it.bIndex + j);
8555                                                        ox = (ibx == 0 ? 0 : iax / ibx);
8556                                                        oaf64data[it.oIndex + j] = ox;
8557                                                }
8558                                        }
8559                                }
8560                        }
8561                        break;
8562                case Dataset.COMPLEX64:
8563                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
8564                        if (!da.isComplex()) {
8565                                if (it.isOutputDouble()) {
8566                                        final double iay = 0;
8567                                        if (db.isComplex()) {
8568                                                while (it.hasNext()) {
8569                                                        final double iax = it.aDouble;
8570                                                        final double ibx = it.bDouble;
8571                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
8572                                                        float ox;
8573                                                        float oy;
8574                                                        float q;
8575                                                        float den;
8576                                                        if (ibx == 0 && iby == 0) {
8577                                                                ox = 0;
8578                                                                oy = 0;
8579                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
8580                                                                q = (float) (ibx / iby);
8581                                                                den = (float) (ibx * q + iby);
8582                                                                ox = (float) ((iax * q + iay) / den);
8583                                                                oy = (float) ((iay * q - iax) / den);
8584                                                        } else {
8585                                                                q = (float) (iby / ibx);
8586                                                                den = (float) (iby * q + ibx);
8587                                                                ox = (float) ((iay * q + iax) / den);
8588                                                                oy = (float) ((iay - iax * q) / den);
8589                                                        }
8590                                                        oc64data[it.oIndex] = ox;
8591                                                        oc64data[it.oIndex + 1] = oy;
8592                                                }
8593                                        } else {
8594                                                while (it.hasNext()) {
8595                                                        final double iax = it.aDouble;
8596                                                        final double ibx = it.bDouble;
8597                                                        float ox;
8598                                                        float oy;
8599                                                        if (ibx == 0) {
8600                                                                ox = 0;
8601                                                                oy = 0;
8602                                                        } else {
8603                                                                ox = (float) (iax / ibx);
8604                                                                oy = (float) (iay / ibx);
8605                                                        }
8606                                                        oc64data[it.oIndex] = ox;
8607                                                        oc64data[it.oIndex + 1] = oy;
8608                                                }
8609                                        }
8610                                } else {
8611                                        final long iay = 0;
8612                                        while (it.hasNext()) {
8613                                                final long iax = it.aLong;
8614                                                final long ibx = it.bLong;
8615                                                float ox;
8616                                                float oy;
8617                                                if (ibx == 0) {
8618                                                        ox = 0;
8619                                                        oy = 0;
8620                                                } else {
8621                                                        ox = (float) (iax / ibx);
8622                                                        oy = (float) (iay / ibx);
8623                                                }
8624                                                oc64data[it.oIndex] = ox;
8625                                                oc64data[it.oIndex + 1] = oy;
8626                                        }
8627                                }
8628                        } else if (!db.isComplex()) {
8629                                while (it.hasNext()) {
8630                                        final double iax = it.aDouble;
8631                                        final double ibx = it.bDouble;
8632                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
8633                                        float ox;
8634                                        float oy;
8635                                        if (ibx == 0) {
8636                                                ox = 0;
8637                                                oy = 0;
8638                                        } else {
8639                                                ox = (float) (iax / ibx);
8640                                                oy = (float) (iay / ibx);
8641                                        }
8642                                        oc64data[it.oIndex] = ox;
8643                                        oc64data[it.oIndex + 1] = oy;
8644                                }
8645                        } else {
8646                                while (it.hasNext()) {
8647                                        final double iax = it.aDouble;
8648                                        final double ibx = it.bDouble;
8649                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
8650                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
8651                                        float ox;
8652                                        float oy;
8653                                        float q;
8654                                        float den;
8655                                        if (ibx == 0 && iby == 0) {
8656                                                ox = 0;
8657                                                oy = 0;
8658                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
8659                                                q = (float) (ibx / iby);
8660                                                den = (float) (ibx * q + iby);
8661                                                ox = (float) ((iax * q + iay) / den);
8662                                                oy = (float) ((iay * q - iax) / den);
8663                                        } else {
8664                                                q = (float) (iby / ibx);
8665                                                den = (float) (iby * q + ibx);
8666                                                ox = (float) ((iay * q + iax) / den);
8667                                                oy = (float) ((iay - iax * q) / den);
8668                                        }
8669                                        oc64data[it.oIndex] = ox;
8670                                        oc64data[it.oIndex + 1] = oy;
8671                                }
8672                        }
8673                        break;
8674                case Dataset.COMPLEX128:
8675                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
8676                        if (!da.isComplex()) {
8677                                if (it.isOutputDouble()) {
8678                                        final double iay = 0;
8679                                        if (db.isComplex()) {
8680                                                while (it.hasNext()) {
8681                                                        final double iax = it.aDouble;
8682                                                        final double ibx = it.bDouble;
8683                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
8684                                                        double ox;
8685                                                        double oy;
8686                                                        double q;
8687                                                        double den;
8688                                                        if (ibx == 0 && iby == 0) {
8689                                                                ox = 0;
8690                                                                oy = 0;
8691                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
8692                                                                q = (ibx / iby);
8693                                                                den = (ibx * q + iby);
8694                                                                ox = ((iax * q + iay) / den);
8695                                                                oy = ((iay * q - iax) / den);
8696                                                        } else {
8697                                                                q = (iby / ibx);
8698                                                                den = (iby * q + ibx);
8699                                                                ox = ((iay * q + iax) / den);
8700                                                                oy = ((iay - iax * q) / den);
8701                                                        }
8702                                                        oc128data[it.oIndex] = ox;
8703                                                        oc128data[it.oIndex + 1] = oy;
8704                                                }
8705                                        } else {
8706                                                while (it.hasNext()) {
8707                                                        final double iax = it.aDouble;
8708                                                        final double ibx = it.bDouble;
8709                                                        double ox;
8710                                                        double oy;
8711                                                        if (ibx == 0) {
8712                                                                ox = 0;
8713                                                                oy = 0;
8714                                                        } else {
8715                                                                ox = (iax / ibx);
8716                                                                oy = (iay / ibx);
8717                                                        }
8718                                                        oc128data[it.oIndex] = ox;
8719                                                        oc128data[it.oIndex + 1] = oy;
8720                                                }
8721                                        }
8722                                } else {
8723                                        final long iay = 0;
8724                                        while (it.hasNext()) {
8725                                                final long iax = it.aLong;
8726                                                final long ibx = it.bLong;
8727                                                double ox;
8728                                                double oy;
8729                                                if (ibx == 0) {
8730                                                        ox = 0;
8731                                                        oy = 0;
8732                                                } else {
8733                                                        ox = (iax / ibx);
8734                                                        oy = (iay / ibx);
8735                                                }
8736                                                oc128data[it.oIndex] = ox;
8737                                                oc128data[it.oIndex + 1] = oy;
8738                                        }
8739                                }
8740                        } else if (!db.isComplex()) {
8741                                while (it.hasNext()) {
8742                                        final double iax = it.aDouble;
8743                                        final double ibx = it.bDouble;
8744                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
8745                                        double ox;
8746                                        double oy;
8747                                        if (ibx == 0) {
8748                                                ox = 0;
8749                                                oy = 0;
8750                                        } else {
8751                                                ox = (iax / ibx);
8752                                                oy = (iay / ibx);
8753                                        }
8754                                        oc128data[it.oIndex] = ox;
8755                                        oc128data[it.oIndex + 1] = oy;
8756                                }
8757                        } else {
8758                                while (it.hasNext()) {
8759                                        final double iax = it.aDouble;
8760                                        final double ibx = it.bDouble;
8761                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
8762                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
8763                                        double ox;
8764                                        double oy;
8765                                        double q;
8766                                        double den;
8767                                        if (ibx == 0 && iby == 0) {
8768                                                ox = 0;
8769                                                oy = 0;
8770                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
8771                                                q = (ibx / iby);
8772                                                den = (ibx * q + iby);
8773                                                ox = ((iax * q + iay) / den);
8774                                                oy = ((iay * q - iax) / den);
8775                                        } else {
8776                                                q = (iby / ibx);
8777                                                den = (iby * q + ibx);
8778                                                ox = ((iay * q + iax) / den);
8779                                                oy = ((iay - iax * q) / den);
8780                                        }
8781                                        oc128data[it.oIndex] = ox;
8782                                        oc128data[it.oIndex + 1] = oy;
8783                                }
8784                        }
8785                        break;
8786                default:
8787                        throw new IllegalArgumentException("dividez supports integer, compound integer, real, compound real, complex datasets only");
8788                }
8789
8790                addBinaryOperatorName(da, db, result, "/");
8791                return result;
8792        }
8793
8794        /**
8795         * divideTowardsFloor operator
8796         * @param a first operand
8797         * @param b second operand
8798         * @return {@code a / b}, division of a by b but rounded towards negative infinity
8799         */
8800        public static Dataset divideTowardsFloor(final Object a, final Object b) {
8801                return divideTowardsFloor(a, b, null);
8802        }
8803
8804        /**
8805         * divideTowardsFloor operator
8806         * @param a first operand
8807         * @param b second operand
8808         * @param o output can be null - in which case, a new dataset is created
8809         * @return {@code a / b}, division of a by b but rounded towards negative infinity
8810         */
8811        public static Dataset divideTowardsFloor(final Object a, final Object b, final Dataset o) {
8812                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
8813                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
8814                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
8815                final Dataset result = it.getOutput();
8816                if (!result.isComplex()) {
8817                        boolean change = false;
8818                        if (da.isComplex()) {
8819                                da = da.getRealView();
8820                                change = true;
8821                        }
8822                        if (db.isComplex()) {
8823                                db = db.getRealView();
8824                                change = true;
8825                        }
8826                        if (change) {
8827                                it = BroadcastIterator.createIterator(da, db, result, true);
8828                        }
8829                }
8830                final int is = result.getElementsPerItem();
8831                final int as = da.getElementsPerItem();
8832                final int bs = db.getElementsPerItem();
8833                final int dt = result.getDType();
8834
8835                switch(dt) {
8836                case Dataset.INT8:
8837                        final byte[] oi8data = ((ByteDataset) result).getData();
8838                        if (it.isOutputDouble()) {
8839                                while (it.hasNext()) {
8840                                        final double iax = it.aDouble;
8841                                        final double ibx = it.bDouble;
8842                                        byte ox;
8843                                        if (ibx == 0) {
8844                                                ox = 0;
8845                                        } else {
8846                                                ox = (byte) toLong(iax / ibx);
8847                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
8848                                                        ox--;
8849                                                }
8850                                        }
8851                                        oi8data[it.oIndex] = ox;
8852                                }
8853                        } else {
8854                                while (it.hasNext()) {
8855                                        final long iax = it.aLong;
8856                                        final long ibx = it.bLong;
8857                                        byte ox;
8858                                        if (ibx == 0) {
8859                                                ox = 0;
8860                                        } else {
8861                                                ox = (byte) (iax / ibx);
8862                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
8863                                                        ox--;
8864                                                }
8865                                        }
8866                                        oi8data[it.oIndex] = ox;
8867                                }
8868                        }
8869                        break;
8870                case Dataset.INT16:
8871                        final short[] oi16data = ((ShortDataset) result).getData();
8872                        if (it.isOutputDouble()) {
8873                                while (it.hasNext()) {
8874                                        final double iax = it.aDouble;
8875                                        final double ibx = it.bDouble;
8876                                        short ox;
8877                                        if (ibx == 0) {
8878                                                ox = 0;
8879                                        } else {
8880                                                ox = (short) toLong(iax / ibx);
8881                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
8882                                                        ox--;
8883                                                }
8884                                        }
8885                                        oi16data[it.oIndex] = ox;
8886                                }
8887                        } else {
8888                                while (it.hasNext()) {
8889                                        final long iax = it.aLong;
8890                                        final long ibx = it.bLong;
8891                                        short ox;
8892                                        if (ibx == 0) {
8893                                                ox = 0;
8894                                        } else {
8895                                                ox = (short) (iax / ibx);
8896                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
8897                                                        ox--;
8898                                                }
8899                                        }
8900                                        oi16data[it.oIndex] = ox;
8901                                }
8902                        }
8903                        break;
8904                case Dataset.INT64:
8905                        final long[] oi64data = ((LongDataset) result).getData();
8906                        if (it.isOutputDouble()) {
8907                                while (it.hasNext()) {
8908                                        final double iax = it.aDouble;
8909                                        final double ibx = it.bDouble;
8910                                        long ox;
8911                                        if (ibx == 0) {
8912                                                ox = 0;
8913                                        } else {
8914                                                ox = toLong(iax / ibx);
8915                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
8916                                                        ox--;
8917                                                }
8918                                        }
8919                                        oi64data[it.oIndex] = ox;
8920                                }
8921                        } else {
8922                                while (it.hasNext()) {
8923                                        final long iax = it.aLong;
8924                                        final long ibx = it.bLong;
8925                                        long ox;
8926                                        if (ibx == 0) {
8927                                                ox = 0;
8928                                        } else {
8929                                                ox = (iax / ibx);
8930                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
8931                                                        ox--;
8932                                                }
8933                                        }
8934                                        oi64data[it.oIndex] = ox;
8935                                }
8936                        }
8937                        break;
8938                case Dataset.INT32:
8939                        final int[] oi32data = ((IntegerDataset) result).getData();
8940                        if (it.isOutputDouble()) {
8941                                while (it.hasNext()) {
8942                                        final double iax = it.aDouble;
8943                                        final double ibx = it.bDouble;
8944                                        int ox;
8945                                        if (ibx == 0) {
8946                                                ox = 0;
8947                                        } else {
8948                                                ox = (int) toLong(iax / ibx);
8949                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
8950                                                        ox--;
8951                                                }
8952                                        }
8953                                        oi32data[it.oIndex] = ox;
8954                                }
8955                        } else {
8956                                while (it.hasNext()) {
8957                                        final long iax = it.aLong;
8958                                        final long ibx = it.bLong;
8959                                        int ox;
8960                                        if (ibx == 0) {
8961                                                ox = 0;
8962                                        } else {
8963                                                ox = (int) (iax / ibx);
8964                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
8965                                                        ox--;
8966                                                }
8967                                        }
8968                                        oi32data[it.oIndex] = ox;
8969                                }
8970                        }
8971                        break;
8972                case Dataset.ARRAYINT8:
8973                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
8974                        if (is == 1) {
8975                                if (it.isOutputDouble()) {
8976                                        while (it.hasNext()) {
8977                                                final double iax = it.aDouble;
8978                                                final double ibx = it.bDouble;
8979                                                byte ox;
8980                                                if (ibx == 0) {
8981                                                        ox = 0;
8982                                                } else {
8983                                                        ox = (byte) toLong(iax / ibx);
8984                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
8985                                                                ox--;
8986                                                        }
8987                                                }
8988                                                oai8data[it.oIndex] = ox;
8989                                        }
8990                                } else {
8991                                        while (it.hasNext()) {
8992                                                final long iax = it.aLong;
8993                                                final long ibx = it.bLong;
8994                                                byte ox;
8995                                                if (ibx == 0) {
8996                                                        ox = 0;
8997                                                } else {
8998                                                        ox = (byte) (iax / ibx);
8999                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9000                                                                ox--;
9001                                                        }
9002                                                }
9003                                                oai8data[it.oIndex] = ox;
9004                                        }
9005                                }
9006                        } else if (as < bs) {
9007                                if (it.isOutputDouble()) {
9008                                        while (it.hasNext()) {
9009                                                final double iax = it.aDouble;
9010                                                double ibx = it.bDouble;
9011                                                byte ox;
9012                                                if (ibx == 0) {
9013                                                        ox = 0;
9014                                                } else {
9015                                                        ox = (byte) toLong(iax / ibx);
9016                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9017                                                                ox--;
9018                                                        }
9019                                                }
9020                                                oai8data[it.oIndex] = ox;
9021                                                for (int j = 1; j < is; j++) {
9022                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9023                                                        if (ibx == 0) {
9024                                                                ox = 0;
9025                                                        } else {
9026                                                                ox = (byte) toLong(iax / ibx);
9027                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9028                                                                        ox--;
9029                                                                }
9030                                                        }
9031                                                        oai8data[it.oIndex + j] = ox;
9032                                                }
9033                                        }
9034                                } else {
9035                                        while (it.hasNext()) {
9036                                                final long iax = it.aLong;
9037                                                long ibx = it.bLong;
9038                                                byte ox;
9039                                                if (ibx == 0) {
9040                                                        ox = 0;
9041                                                } else {
9042                                                        ox = (byte) (iax / ibx);
9043                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9044                                                                ox--;
9045                                                        }
9046                                                }
9047                                                oai8data[it.oIndex] = ox;
9048                                                for (int j = 1; j < is; j++) {
9049                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9050                                                        if (ibx == 0) {
9051                                                                ox = 0;
9052                                                        } else {
9053                                                                ox = (byte) (iax / ibx);
9054                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9055                                                                        ox--;
9056                                                                }
9057                                                        }
9058                                                        oai8data[it.oIndex + j] = ox;
9059                                                }
9060                                        }
9061                                }
9062                        } else if (as > bs) {
9063                                if (it.isOutputDouble()) {
9064                                        while (it.hasNext()) {
9065                                                double iax = it.aDouble;
9066                                                final double ibx = it.bDouble;
9067                                                byte ox;
9068                                                if (ibx == 0) {
9069                                                        ox = 0;
9070                                                } else {
9071                                                        ox = (byte) toLong(iax / ibx);
9072                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9073                                                                ox--;
9074                                                        }
9075                                                }
9076                                                oai8data[it.oIndex] = ox;
9077                                                for (int j = 1; j < is; j++) {
9078                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9079                                                        if (ibx == 0) {
9080                                                                ox = 0;
9081                                                        } else {
9082                                                                ox = (byte) toLong(iax / ibx);
9083                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9084                                                                        ox--;
9085                                                                }
9086                                                        }
9087                                                        oai8data[it.oIndex + j] = ox;
9088                                                }
9089                                        }
9090                                } else {
9091                                        while (it.hasNext()) {
9092                                                long iax = it.aLong;
9093                                                final long ibx = it.bLong;
9094                                                byte ox;
9095                                                if (ibx == 0) {
9096                                                        ox = 0;
9097                                                } else {
9098                                                        ox = (byte) (iax / ibx);
9099                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9100                                                                ox--;
9101                                                        }
9102                                                }
9103                                                oai8data[it.oIndex] = ox;
9104                                                for (int j = 1; j < is; j++) {
9105                                                        iax = da.getElementLongAbs(it.aIndex + j);
9106                                                        if (ibx == 0) {
9107                                                                ox = 0;
9108                                                        } else {
9109                                                                ox = (byte) (iax / ibx);
9110                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9111                                                                        ox--;
9112                                                                }
9113                                                        }
9114                                                        oai8data[it.oIndex + j] = ox;
9115                                                }
9116                                        }
9117                                }
9118                        } else if (as == 1) {
9119                                if (it.isOutputDouble()) {
9120                                        while (it.hasNext()) {
9121                                                final double iax = it.aDouble;
9122                                                final double ibx = it.bDouble;
9123                                                byte ox;
9124                                                if (ibx == 0) {
9125                                                        ox = 0;
9126                                                } else {
9127                                                        ox = (byte) toLong(iax / ibx);
9128                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9129                                                                ox--;
9130                                                        }
9131                                                }
9132                                                for (int j = 0; j < is; j++) {
9133                                                        oai8data[it.oIndex + j] = ox;
9134                                                }
9135                                        }
9136                                } else {
9137                                        while (it.hasNext()) {
9138                                                final long iax = it.aLong;
9139                                                final long ibx = it.bLong;
9140                                                byte ox;
9141                                                if (ibx == 0) {
9142                                                        ox = 0;
9143                                                } else {
9144                                                        ox = (byte) (iax / ibx);
9145                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9146                                                                ox--;
9147                                                        }
9148                                                }
9149                                                for (int j = 0; j < is; j++) {
9150                                                        oai8data[it.oIndex + j] = ox;
9151                                                }
9152                                        }
9153                                }
9154                        } else {
9155                                if (it.isOutputDouble()) {
9156                                        while (it.hasNext()) {
9157                                                double iax = it.aDouble;
9158                                                double ibx = it.bDouble;
9159                                                byte ox;
9160                                                if (ibx == 0) {
9161                                                        ox = 0;
9162                                                } else {
9163                                                        ox = (byte) toLong(iax / ibx);
9164                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9165                                                                ox--;
9166                                                        }
9167                                                }
9168                                                oai8data[it.oIndex] = ox;
9169                                                for (int j = 1; j < is; j++) {
9170                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9171                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9172                                                        if (ibx == 0) {
9173                                                                ox = 0;
9174                                                        } else {
9175                                                                ox = (byte) toLong(iax / ibx);
9176                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9177                                                                        ox--;
9178                                                                }
9179                                                        }
9180                                                        oai8data[it.oIndex + j] = ox;
9181                                                }
9182                                        }
9183                                } else {
9184                                        while (it.hasNext()) {
9185                                                long iax = it.aLong;
9186                                                long ibx = it.bLong;
9187                                                byte ox;
9188                                                if (ibx == 0) {
9189                                                        ox = 0;
9190                                                } else {
9191                                                        ox = (byte) (iax / ibx);
9192                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9193                                                                ox--;
9194                                                        }
9195                                                }
9196                                                oai8data[it.oIndex] = ox;
9197                                                for (int j = 1; j < is; j++) {
9198                                                        iax = da.getElementLongAbs(it.aIndex + j);
9199                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9200                                                        if (ibx == 0) {
9201                                                                ox = 0;
9202                                                        } else {
9203                                                                ox = (byte) (iax / ibx);
9204                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9205                                                                        ox--;
9206                                                                }
9207                                                        }
9208                                                        oai8data[it.oIndex + j] = ox;
9209                                                }
9210                                        }
9211                                }
9212                        }
9213                        break;
9214                case Dataset.ARRAYINT16:
9215                        final short[] oai16data = ((CompoundShortDataset) result).getData();
9216                        if (is == 1) {
9217                                if (it.isOutputDouble()) {
9218                                        while (it.hasNext()) {
9219                                                final double iax = it.aDouble;
9220                                                final double ibx = it.bDouble;
9221                                                short ox;
9222                                                if (ibx == 0) {
9223                                                        ox = 0;
9224                                                } else {
9225                                                        ox = (short) toLong(iax / ibx);
9226                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9227                                                                ox--;
9228                                                        }
9229                                                }
9230                                                oai16data[it.oIndex] = ox;
9231                                        }
9232                                } else {
9233                                        while (it.hasNext()) {
9234                                                final long iax = it.aLong;
9235                                                final long ibx = it.bLong;
9236                                                short ox;
9237                                                if (ibx == 0) {
9238                                                        ox = 0;
9239                                                } else {
9240                                                        ox = (short) (iax / ibx);
9241                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9242                                                                ox--;
9243                                                        }
9244                                                }
9245                                                oai16data[it.oIndex] = ox;
9246                                        }
9247                                }
9248                        } else if (as < bs) {
9249                                if (it.isOutputDouble()) {
9250                                        while (it.hasNext()) {
9251                                                final double iax = it.aDouble;
9252                                                double ibx = it.bDouble;
9253                                                short ox;
9254                                                if (ibx == 0) {
9255                                                        ox = 0;
9256                                                } else {
9257                                                        ox = (short) toLong(iax / ibx);
9258                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9259                                                                ox--;
9260                                                        }
9261                                                }
9262                                                oai16data[it.oIndex] = ox;
9263                                                for (int j = 1; j < is; j++) {
9264                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9265                                                        if (ibx == 0) {
9266                                                                ox = 0;
9267                                                        } else {
9268                                                                ox = (short) toLong(iax / ibx);
9269                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9270                                                                        ox--;
9271                                                                }
9272                                                        }
9273                                                        oai16data[it.oIndex + j] = ox;
9274                                                }
9275                                        }
9276                                } else {
9277                                        while (it.hasNext()) {
9278                                                final long iax = it.aLong;
9279                                                long ibx = it.bLong;
9280                                                short ox;
9281                                                if (ibx == 0) {
9282                                                        ox = 0;
9283                                                } else {
9284                                                        ox = (short) (iax / ibx);
9285                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9286                                                                ox--;
9287                                                        }
9288                                                }
9289                                                oai16data[it.oIndex] = ox;
9290                                                for (int j = 1; j < is; j++) {
9291                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9292                                                        if (ibx == 0) {
9293                                                                ox = 0;
9294                                                        } else {
9295                                                                ox = (short) (iax / ibx);
9296                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9297                                                                        ox--;
9298                                                                }
9299                                                        }
9300                                                        oai16data[it.oIndex + j] = ox;
9301                                                }
9302                                        }
9303                                }
9304                        } else if (as > bs) {
9305                                if (it.isOutputDouble()) {
9306                                        while (it.hasNext()) {
9307                                                double iax = it.aDouble;
9308                                                final double ibx = it.bDouble;
9309                                                short ox;
9310                                                if (ibx == 0) {
9311                                                        ox = 0;
9312                                                } else {
9313                                                        ox = (short) toLong(iax / ibx);
9314                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9315                                                                ox--;
9316                                                        }
9317                                                }
9318                                                oai16data[it.oIndex] = ox;
9319                                                for (int j = 1; j < is; j++) {
9320                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9321                                                        if (ibx == 0) {
9322                                                                ox = 0;
9323                                                        } else {
9324                                                                ox = (short) toLong(iax / ibx);
9325                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9326                                                                        ox--;
9327                                                                }
9328                                                        }
9329                                                        oai16data[it.oIndex + j] = ox;
9330                                                }
9331                                        }
9332                                } else {
9333                                        while (it.hasNext()) {
9334                                                long iax = it.aLong;
9335                                                final long ibx = it.bLong;
9336                                                short ox;
9337                                                if (ibx == 0) {
9338                                                        ox = 0;
9339                                                } else {
9340                                                        ox = (short) (iax / ibx);
9341                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9342                                                                ox--;
9343                                                        }
9344                                                }
9345                                                oai16data[it.oIndex] = ox;
9346                                                for (int j = 1; j < is; j++) {
9347                                                        iax = da.getElementLongAbs(it.aIndex + j);
9348                                                        if (ibx == 0) {
9349                                                                ox = 0;
9350                                                        } else {
9351                                                                ox = (short) (iax / ibx);
9352                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9353                                                                        ox--;
9354                                                                }
9355                                                        }
9356                                                        oai16data[it.oIndex + j] = ox;
9357                                                }
9358                                        }
9359                                }
9360                        } else if (as == 1) {
9361                                if (it.isOutputDouble()) {
9362                                        while (it.hasNext()) {
9363                                                final double iax = it.aDouble;
9364                                                final double ibx = it.bDouble;
9365                                                short ox;
9366                                                if (ibx == 0) {
9367                                                        ox = 0;
9368                                                } else {
9369                                                        ox = (short) toLong(iax / ibx);
9370                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9371                                                                ox--;
9372                                                        }
9373                                                }
9374                                                for (int j = 0; j < is; j++) {
9375                                                        oai16data[it.oIndex + j] = ox;
9376                                                }
9377                                        }
9378                                } else {
9379                                        while (it.hasNext()) {
9380                                                final long iax = it.aLong;
9381                                                final long ibx = it.bLong;
9382                                                short ox;
9383                                                if (ibx == 0) {
9384                                                        ox = 0;
9385                                                } else {
9386                                                        ox = (short) (iax / ibx);
9387                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9388                                                                ox--;
9389                                                        }
9390                                                }
9391                                                for (int j = 0; j < is; j++) {
9392                                                        oai16data[it.oIndex + j] = ox;
9393                                                }
9394                                        }
9395                                }
9396                        } else {
9397                                if (it.isOutputDouble()) {
9398                                        while (it.hasNext()) {
9399                                                double iax = it.aDouble;
9400                                                double ibx = it.bDouble;
9401                                                short ox;
9402                                                if (ibx == 0) {
9403                                                        ox = 0;
9404                                                } else {
9405                                                        ox = (short) toLong(iax / ibx);
9406                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9407                                                                ox--;
9408                                                        }
9409                                                }
9410                                                oai16data[it.oIndex] = ox;
9411                                                for (int j = 1; j < is; j++) {
9412                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9413                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9414                                                        if (ibx == 0) {
9415                                                                ox = 0;
9416                                                        } else {
9417                                                                ox = (short) toLong(iax / ibx);
9418                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9419                                                                        ox--;
9420                                                                }
9421                                                        }
9422                                                        oai16data[it.oIndex + j] = ox;
9423                                                }
9424                                        }
9425                                } else {
9426                                        while (it.hasNext()) {
9427                                                long iax = it.aLong;
9428                                                long ibx = it.bLong;
9429                                                short ox;
9430                                                if (ibx == 0) {
9431                                                        ox = 0;
9432                                                } else {
9433                                                        ox = (short) (iax / ibx);
9434                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9435                                                                ox--;
9436                                                        }
9437                                                }
9438                                                oai16data[it.oIndex] = ox;
9439                                                for (int j = 1; j < is; j++) {
9440                                                        iax = da.getElementLongAbs(it.aIndex + j);
9441                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9442                                                        if (ibx == 0) {
9443                                                                ox = 0;
9444                                                        } else {
9445                                                                ox = (short) (iax / ibx);
9446                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9447                                                                        ox--;
9448                                                                }
9449                                                        }
9450                                                        oai16data[it.oIndex + j] = ox;
9451                                                }
9452                                        }
9453                                }
9454                        }
9455                        break;
9456                case Dataset.ARRAYINT64:
9457                        final long[] oai64data = ((CompoundLongDataset) result).getData();
9458                        if (is == 1) {
9459                                if (it.isOutputDouble()) {
9460                                        while (it.hasNext()) {
9461                                                final double iax = it.aDouble;
9462                                                final double ibx = it.bDouble;
9463                                                long ox;
9464                                                if (ibx == 0) {
9465                                                        ox = 0;
9466                                                } else {
9467                                                        ox = toLong(iax / ibx);
9468                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9469                                                                ox--;
9470                                                        }
9471                                                }
9472                                                oai64data[it.oIndex] = ox;
9473                                        }
9474                                } else {
9475                                        while (it.hasNext()) {
9476                                                final long iax = it.aLong;
9477                                                final long ibx = it.bLong;
9478                                                long ox;
9479                                                if (ibx == 0) {
9480                                                        ox = 0;
9481                                                } else {
9482                                                        ox = (iax / ibx);
9483                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9484                                                                ox--;
9485                                                        }
9486                                                }
9487                                                oai64data[it.oIndex] = ox;
9488                                        }
9489                                }
9490                        } else if (as < bs) {
9491                                if (it.isOutputDouble()) {
9492                                        while (it.hasNext()) {
9493                                                final double iax = it.aDouble;
9494                                                double ibx = it.bDouble;
9495                                                long ox;
9496                                                if (ibx == 0) {
9497                                                        ox = 0;
9498                                                } else {
9499                                                        ox = toLong(iax / ibx);
9500                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9501                                                                ox--;
9502                                                        }
9503                                                }
9504                                                oai64data[it.oIndex] = ox;
9505                                                for (int j = 1; j < is; j++) {
9506                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9507                                                        if (ibx == 0) {
9508                                                                ox = 0;
9509                                                        } else {
9510                                                                ox = toLong(iax / ibx);
9511                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9512                                                                        ox--;
9513                                                                }
9514                                                        }
9515                                                        oai64data[it.oIndex + j] = ox;
9516                                                }
9517                                        }
9518                                } else {
9519                                        while (it.hasNext()) {
9520                                                final long iax = it.aLong;
9521                                                long ibx = it.bLong;
9522                                                long ox;
9523                                                if (ibx == 0) {
9524                                                        ox = 0;
9525                                                } else {
9526                                                        ox = (iax / ibx);
9527                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9528                                                                ox--;
9529                                                        }
9530                                                }
9531                                                oai64data[it.oIndex] = ox;
9532                                                for (int j = 1; j < is; j++) {
9533                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9534                                                        if (ibx == 0) {
9535                                                                ox = 0;
9536                                                        } else {
9537                                                                ox = (iax / ibx);
9538                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9539                                                                        ox--;
9540                                                                }
9541                                                        }
9542                                                        oai64data[it.oIndex + j] = ox;
9543                                                }
9544                                        }
9545                                }
9546                        } else if (as > bs) {
9547                                if (it.isOutputDouble()) {
9548                                        while (it.hasNext()) {
9549                                                double iax = it.aDouble;
9550                                                final double ibx = it.bDouble;
9551                                                long ox;
9552                                                if (ibx == 0) {
9553                                                        ox = 0;
9554                                                } else {
9555                                                        ox = toLong(iax / ibx);
9556                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9557                                                                ox--;
9558                                                        }
9559                                                }
9560                                                oai64data[it.oIndex] = ox;
9561                                                for (int j = 1; j < is; j++) {
9562                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9563                                                        if (ibx == 0) {
9564                                                                ox = 0;
9565                                                        } else {
9566                                                                ox = toLong(iax / ibx);
9567                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9568                                                                        ox--;
9569                                                                }
9570                                                        }
9571                                                        oai64data[it.oIndex + j] = ox;
9572                                                }
9573                                        }
9574                                } else {
9575                                        while (it.hasNext()) {
9576                                                long iax = it.aLong;
9577                                                final long ibx = it.bLong;
9578                                                long ox;
9579                                                if (ibx == 0) {
9580                                                        ox = 0;
9581                                                } else {
9582                                                        ox = (iax / ibx);
9583                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9584                                                                ox--;
9585                                                        }
9586                                                }
9587                                                oai64data[it.oIndex] = ox;
9588                                                for (int j = 1; j < is; j++) {
9589                                                        iax = da.getElementLongAbs(it.aIndex + j);
9590                                                        if (ibx == 0) {
9591                                                                ox = 0;
9592                                                        } else {
9593                                                                ox = (iax / ibx);
9594                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9595                                                                        ox--;
9596                                                                }
9597                                                        }
9598                                                        oai64data[it.oIndex + j] = ox;
9599                                                }
9600                                        }
9601                                }
9602                        } else if (as == 1) {
9603                                if (it.isOutputDouble()) {
9604                                        while (it.hasNext()) {
9605                                                final double iax = it.aDouble;
9606                                                final double ibx = it.bDouble;
9607                                                long ox;
9608                                                if (ibx == 0) {
9609                                                        ox = 0;
9610                                                } else {
9611                                                        ox = toLong(iax / ibx);
9612                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9613                                                                ox--;
9614                                                        }
9615                                                }
9616                                                for (int j = 0; j < is; j++) {
9617                                                        oai64data[it.oIndex + j] = ox;
9618                                                }
9619                                        }
9620                                } else {
9621                                        while (it.hasNext()) {
9622                                                final long iax = it.aLong;
9623                                                final long ibx = it.bLong;
9624                                                long ox;
9625                                                if (ibx == 0) {
9626                                                        ox = 0;
9627                                                } else {
9628                                                        ox = (iax / ibx);
9629                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9630                                                                ox--;
9631                                                        }
9632                                                }
9633                                                for (int j = 0; j < is; j++) {
9634                                                        oai64data[it.oIndex + j] = ox;
9635                                                }
9636                                        }
9637                                }
9638                        } else {
9639                                if (it.isOutputDouble()) {
9640                                        while (it.hasNext()) {
9641                                                double iax = it.aDouble;
9642                                                double ibx = it.bDouble;
9643                                                long ox;
9644                                                if (ibx == 0) {
9645                                                        ox = 0;
9646                                                } else {
9647                                                        ox = toLong(iax / ibx);
9648                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9649                                                                ox--;
9650                                                        }
9651                                                }
9652                                                oai64data[it.oIndex] = ox;
9653                                                for (int j = 1; j < is; j++) {
9654                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9655                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9656                                                        if (ibx == 0) {
9657                                                                ox = 0;
9658                                                        } else {
9659                                                                ox = toLong(iax / ibx);
9660                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9661                                                                        ox--;
9662                                                                }
9663                                                        }
9664                                                        oai64data[it.oIndex + j] = ox;
9665                                                }
9666                                        }
9667                                } else {
9668                                        while (it.hasNext()) {
9669                                                long iax = it.aLong;
9670                                                long ibx = it.bLong;
9671                                                long ox;
9672                                                if (ibx == 0) {
9673                                                        ox = 0;
9674                                                } else {
9675                                                        ox = (iax / ibx);
9676                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9677                                                                ox--;
9678                                                        }
9679                                                }
9680                                                oai64data[it.oIndex] = ox;
9681                                                for (int j = 1; j < is; j++) {
9682                                                        iax = da.getElementLongAbs(it.aIndex + j);
9683                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9684                                                        if (ibx == 0) {
9685                                                                ox = 0;
9686                                                        } else {
9687                                                                ox = (iax / ibx);
9688                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9689                                                                        ox--;
9690                                                                }
9691                                                        }
9692                                                        oai64data[it.oIndex + j] = ox;
9693                                                }
9694                                        }
9695                                }
9696                        }
9697                        break;
9698                case Dataset.ARRAYINT32:
9699                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
9700                        if (is == 1) {
9701                                if (it.isOutputDouble()) {
9702                                        while (it.hasNext()) {
9703                                                final double iax = it.aDouble;
9704                                                final double ibx = it.bDouble;
9705                                                int ox;
9706                                                if (ibx == 0) {
9707                                                        ox = 0;
9708                                                } else {
9709                                                        ox = (int) toLong(iax / ibx);
9710                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9711                                                                ox--;
9712                                                        }
9713                                                }
9714                                                oai32data[it.oIndex] = ox;
9715                                        }
9716                                } else {
9717                                        while (it.hasNext()) {
9718                                                final long iax = it.aLong;
9719                                                final long ibx = it.bLong;
9720                                                int ox;
9721                                                if (ibx == 0) {
9722                                                        ox = 0;
9723                                                } else {
9724                                                        ox = (int) (iax / ibx);
9725                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9726                                                                ox--;
9727                                                        }
9728                                                }
9729                                                oai32data[it.oIndex] = ox;
9730                                        }
9731                                }
9732                        } else if (as < bs) {
9733                                if (it.isOutputDouble()) {
9734                                        while (it.hasNext()) {
9735                                                final double iax = it.aDouble;
9736                                                double ibx = it.bDouble;
9737                                                int ox;
9738                                                if (ibx == 0) {
9739                                                        ox = 0;
9740                                                } else {
9741                                                        ox = (int) toLong(iax / ibx);
9742                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9743                                                                ox--;
9744                                                        }
9745                                                }
9746                                                oai32data[it.oIndex] = ox;
9747                                                for (int j = 1; j < is; j++) {
9748                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9749                                                        if (ibx == 0) {
9750                                                                ox = 0;
9751                                                        } else {
9752                                                                ox = (int) toLong(iax / ibx);
9753                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9754                                                                        ox--;
9755                                                                }
9756                                                        }
9757                                                        oai32data[it.oIndex + j] = ox;
9758                                                }
9759                                        }
9760                                } else {
9761                                        while (it.hasNext()) {
9762                                                final long iax = it.aLong;
9763                                                long ibx = it.bLong;
9764                                                int ox;
9765                                                if (ibx == 0) {
9766                                                        ox = 0;
9767                                                } else {
9768                                                        ox = (int) (iax / ibx);
9769                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9770                                                                ox--;
9771                                                        }
9772                                                }
9773                                                oai32data[it.oIndex] = ox;
9774                                                for (int j = 1; j < is; j++) {
9775                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9776                                                        if (ibx == 0) {
9777                                                                ox = 0;
9778                                                        } else {
9779                                                                ox = (int) (iax / ibx);
9780                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9781                                                                        ox--;
9782                                                                }
9783                                                        }
9784                                                        oai32data[it.oIndex + j] = ox;
9785                                                }
9786                                        }
9787                                }
9788                        } else if (as > bs) {
9789                                if (it.isOutputDouble()) {
9790                                        while (it.hasNext()) {
9791                                                double iax = it.aDouble;
9792                                                final double ibx = it.bDouble;
9793                                                int ox;
9794                                                if (ibx == 0) {
9795                                                        ox = 0;
9796                                                } else {
9797                                                        ox = (int) toLong(iax / ibx);
9798                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9799                                                                ox--;
9800                                                        }
9801                                                }
9802                                                oai32data[it.oIndex] = ox;
9803                                                for (int j = 1; j < is; j++) {
9804                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9805                                                        if (ibx == 0) {
9806                                                                ox = 0;
9807                                                        } else {
9808                                                                ox = (int) toLong(iax / ibx);
9809                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9810                                                                        ox--;
9811                                                                }
9812                                                        }
9813                                                        oai32data[it.oIndex + j] = ox;
9814                                                }
9815                                        }
9816                                } else {
9817                                        while (it.hasNext()) {
9818                                                long iax = it.aLong;
9819                                                final long ibx = it.bLong;
9820                                                int ox;
9821                                                if (ibx == 0) {
9822                                                        ox = 0;
9823                                                } else {
9824                                                        ox = (int) (iax / ibx);
9825                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9826                                                                ox--;
9827                                                        }
9828                                                }
9829                                                oai32data[it.oIndex] = ox;
9830                                                for (int j = 1; j < is; j++) {
9831                                                        iax = da.getElementLongAbs(it.aIndex + j);
9832                                                        if (ibx == 0) {
9833                                                                ox = 0;
9834                                                        } else {
9835                                                                ox = (int) (iax / ibx);
9836                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9837                                                                        ox--;
9838                                                                }
9839                                                        }
9840                                                        oai32data[it.oIndex + j] = ox;
9841                                                }
9842                                        }
9843                                }
9844                        } else if (as == 1) {
9845                                if (it.isOutputDouble()) {
9846                                        while (it.hasNext()) {
9847                                                final double iax = it.aDouble;
9848                                                final double ibx = it.bDouble;
9849                                                int ox;
9850                                                if (ibx == 0) {
9851                                                        ox = 0;
9852                                                } else {
9853                                                        ox = (int) toLong(iax / ibx);
9854                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9855                                                                ox--;
9856                                                        }
9857                                                }
9858                                                for (int j = 0; j < is; j++) {
9859                                                        oai32data[it.oIndex + j] = ox;
9860                                                }
9861                                        }
9862                                } else {
9863                                        while (it.hasNext()) {
9864                                                final long iax = it.aLong;
9865                                                final long ibx = it.bLong;
9866                                                int ox;
9867                                                if (ibx == 0) {
9868                                                        ox = 0;
9869                                                } else {
9870                                                        ox = (int) (iax / ibx);
9871                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9872                                                                ox--;
9873                                                        }
9874                                                }
9875                                                for (int j = 0; j < is; j++) {
9876                                                        oai32data[it.oIndex + j] = ox;
9877                                                }
9878                                        }
9879                                }
9880                        } else {
9881                                if (it.isOutputDouble()) {
9882                                        while (it.hasNext()) {
9883                                                double iax = it.aDouble;
9884                                                double ibx = it.bDouble;
9885                                                int ox;
9886                                                if (ibx == 0) {
9887                                                        ox = 0;
9888                                                } else {
9889                                                        ox = (int) toLong(iax / ibx);
9890                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9891                                                                ox--;
9892                                                        }
9893                                                }
9894                                                oai32data[it.oIndex] = ox;
9895                                                for (int j = 1; j < is; j++) {
9896                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
9897                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
9898                                                        if (ibx == 0) {
9899                                                                ox = 0;
9900                                                        } else {
9901                                                                ox = (int) toLong(iax / ibx);
9902                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9903                                                                        ox--;
9904                                                                }
9905                                                        }
9906                                                        oai32data[it.oIndex + j] = ox;
9907                                                }
9908                                        }
9909                                } else {
9910                                        while (it.hasNext()) {
9911                                                long iax = it.aLong;
9912                                                long ibx = it.bLong;
9913                                                int ox;
9914                                                if (ibx == 0) {
9915                                                        ox = 0;
9916                                                } else {
9917                                                        ox = (int) (iax / ibx);
9918                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9919                                                                ox--;
9920                                                        }
9921                                                }
9922                                                oai32data[it.oIndex] = ox;
9923                                                for (int j = 1; j < is; j++) {
9924                                                        iax = da.getElementLongAbs(it.aIndex + j);
9925                                                        ibx = db.getElementLongAbs(it.bIndex + j);
9926                                                        if (ibx == 0) {
9927                                                                ox = 0;
9928                                                        } else {
9929                                                                ox = (int) (iax / ibx);
9930                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
9931                                                                        ox--;
9932                                                                }
9933                                                        }
9934                                                        oai32data[it.oIndex + j] = ox;
9935                                                }
9936                                        }
9937                                }
9938                        }
9939                        break;
9940                case Dataset.FLOAT32:
9941                        final float[] of32data = ((FloatDataset) result).getData();
9942                        if (it.isOutputDouble()) {
9943                                while (it.hasNext()) {
9944                                        final double iax = it.aDouble;
9945                                        final double ibx = it.bDouble;
9946                                        float ox;
9947                                        ox = (float) (iax / ibx);
9948                                        of32data[it.oIndex] = ox;
9949                                }
9950                        } else {
9951                                while (it.hasNext()) {
9952                                        final long iax = it.aLong;
9953                                        final long ibx = it.bLong;
9954                                        float ox;
9955                                        ox = (iax / ibx);
9956                                        of32data[it.oIndex] = ox;
9957                                }
9958                        }
9959                        break;
9960                case Dataset.FLOAT64:
9961                        final double[] of64data = ((DoubleDataset) result).getData();
9962                        if (it.isOutputDouble()) {
9963                                while (it.hasNext()) {
9964                                        final double iax = it.aDouble;
9965                                        final double ibx = it.bDouble;
9966                                        double ox;
9967                                        ox = (iax / ibx);
9968                                        of64data[it.oIndex] = ox;
9969                                }
9970                        } else {
9971                                while (it.hasNext()) {
9972                                        final long iax = it.aLong;
9973                                        final long ibx = it.bLong;
9974                                        double ox;
9975                                        ox = (iax / ibx);
9976                                        of64data[it.oIndex] = ox;
9977                                }
9978                        }
9979                        break;
9980                case Dataset.ARRAYFLOAT32:
9981                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
9982                        if (is == 1) {
9983                                if (it.isOutputDouble()) {
9984                                        while (it.hasNext()) {
9985                                                final double iax = it.aDouble;
9986                                                final double ibx = it.bDouble;
9987                                                float ox;
9988                                                ox = (float) (iax / ibx);
9989                                                oaf32data[it.oIndex] = ox;
9990                                        }
9991                                } else {
9992                                        while (it.hasNext()) {
9993                                                final long iax = it.aLong;
9994                                                final long ibx = it.bLong;
9995                                                float ox;
9996                                                ox = (iax / ibx);
9997                                                oaf32data[it.oIndex] = ox;
9998                                        }
9999                                }
10000                        } else if (as < bs) {
10001                                if (it.isOutputDouble()) {
10002                                        while (it.hasNext()) {
10003                                                final double iax = it.aDouble;
10004                                                double ibx = it.bDouble;
10005                                                float ox;
10006                                                ox = (float) (iax / ibx);
10007                                                oaf32data[it.oIndex] = ox;
10008                                                for (int j = 1; j < is; j++) {
10009                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10010                                                        ox = (float) (iax / ibx);
10011                                                        oaf32data[it.oIndex + j] = ox;
10012                                                }
10013                                        }
10014                                } else {
10015                                        while (it.hasNext()) {
10016                                                final long iax = it.aLong;
10017                                                long ibx = it.bLong;
10018                                                float ox;
10019                                                ox = (iax / ibx);
10020                                                oaf32data[it.oIndex] = ox;
10021                                                for (int j = 1; j < is; j++) {
10022                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10023                                                        ox = (iax / ibx);
10024                                                        oaf32data[it.oIndex + j] = ox;
10025                                                }
10026                                        }
10027                                }
10028                        } else if (as > bs) {
10029                                if (it.isOutputDouble()) {
10030                                        while (it.hasNext()) {
10031                                                double iax = it.aDouble;
10032                                                final double ibx = it.bDouble;
10033                                                float ox;
10034                                                ox = (float) (iax / ibx);
10035                                                oaf32data[it.oIndex] = ox;
10036                                                for (int j = 1; j < is; j++) {
10037                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10038                                                        ox = (float) (iax / ibx);
10039                                                        oaf32data[it.oIndex + j] = ox;
10040                                                }
10041                                        }
10042                                } else {
10043                                        while (it.hasNext()) {
10044                                                long iax = it.aLong;
10045                                                final long ibx = it.bLong;
10046                                                float ox;
10047                                                ox = (iax / ibx);
10048                                                oaf32data[it.oIndex] = ox;
10049                                                for (int j = 1; j < is; j++) {
10050                                                        iax = da.getElementLongAbs(it.aIndex + j);
10051                                                        ox = (iax / ibx);
10052                                                        oaf32data[it.oIndex + j] = ox;
10053                                                }
10054                                        }
10055                                }
10056                        } else if (as == 1) {
10057                                if (it.isOutputDouble()) {
10058                                        while (it.hasNext()) {
10059                                                final double iax = it.aDouble;
10060                                                final double ibx = it.bDouble;
10061                                                float ox;
10062                                                ox = (float) (iax / ibx);
10063                                                for (int j = 0; j < is; j++) {
10064                                                        oaf32data[it.oIndex + j] = ox;
10065                                                }
10066                                        }
10067                                } else {
10068                                        while (it.hasNext()) {
10069                                                final long iax = it.aLong;
10070                                                final long ibx = it.bLong;
10071                                                float ox;
10072                                                ox = (iax / ibx);
10073                                                for (int j = 0; j < is; j++) {
10074                                                        oaf32data[it.oIndex + j] = ox;
10075                                                }
10076                                        }
10077                                }
10078                        } else {
10079                                if (it.isOutputDouble()) {
10080                                        while (it.hasNext()) {
10081                                                double iax = it.aDouble;
10082                                                double ibx = it.bDouble;
10083                                                float ox;
10084                                                ox = (float) (iax / ibx);
10085                                                oaf32data[it.oIndex] = ox;
10086                                                for (int j = 1; j < is; j++) {
10087                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10088                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10089                                                        ox = (float) (iax / ibx);
10090                                                        oaf32data[it.oIndex + j] = ox;
10091                                                }
10092                                        }
10093                                } else {
10094                                        while (it.hasNext()) {
10095                                                long iax = it.aLong;
10096                                                long ibx = it.bLong;
10097                                                float ox;
10098                                                ox = (iax / ibx);
10099                                                oaf32data[it.oIndex] = ox;
10100                                                for (int j = 1; j < is; j++) {
10101                                                        iax = da.getElementLongAbs(it.aIndex + j);
10102                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10103                                                        ox = (iax / ibx);
10104                                                        oaf32data[it.oIndex + j] = ox;
10105                                                }
10106                                        }
10107                                }
10108                        }
10109                        break;
10110                case Dataset.ARRAYFLOAT64:
10111                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
10112                        if (is == 1) {
10113                                if (it.isOutputDouble()) {
10114                                        while (it.hasNext()) {
10115                                                final double iax = it.aDouble;
10116                                                final double ibx = it.bDouble;
10117                                                double ox;
10118                                                ox = (iax / ibx);
10119                                                oaf64data[it.oIndex] = ox;
10120                                        }
10121                                } else {
10122                                        while (it.hasNext()) {
10123                                                final long iax = it.aLong;
10124                                                final long ibx = it.bLong;
10125                                                double ox;
10126                                                ox = (iax / ibx);
10127                                                oaf64data[it.oIndex] = ox;
10128                                        }
10129                                }
10130                        } else if (as < bs) {
10131                                if (it.isOutputDouble()) {
10132                                        while (it.hasNext()) {
10133                                                final double iax = it.aDouble;
10134                                                double ibx = it.bDouble;
10135                                                double ox;
10136                                                ox = (iax / ibx);
10137                                                oaf64data[it.oIndex] = ox;
10138                                                for (int j = 1; j < is; j++) {
10139                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10140                                                        ox = (iax / ibx);
10141                                                        oaf64data[it.oIndex + j] = ox;
10142                                                }
10143                                        }
10144                                } else {
10145                                        while (it.hasNext()) {
10146                                                final long iax = it.aLong;
10147                                                long ibx = it.bLong;
10148                                                double ox;
10149                                                ox = (iax / ibx);
10150                                                oaf64data[it.oIndex] = ox;
10151                                                for (int j = 1; j < is; j++) {
10152                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10153                                                        ox = (iax / ibx);
10154                                                        oaf64data[it.oIndex + j] = ox;
10155                                                }
10156                                        }
10157                                }
10158                        } else if (as > bs) {
10159                                if (it.isOutputDouble()) {
10160                                        while (it.hasNext()) {
10161                                                double iax = it.aDouble;
10162                                                final double ibx = it.bDouble;
10163                                                double ox;
10164                                                ox = (iax / ibx);
10165                                                oaf64data[it.oIndex] = ox;
10166                                                for (int j = 1; j < is; j++) {
10167                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10168                                                        ox = (iax / ibx);
10169                                                        oaf64data[it.oIndex + j] = ox;
10170                                                }
10171                                        }
10172                                } else {
10173                                        while (it.hasNext()) {
10174                                                long iax = it.aLong;
10175                                                final long ibx = it.bLong;
10176                                                double ox;
10177                                                ox = (iax / ibx);
10178                                                oaf64data[it.oIndex] = ox;
10179                                                for (int j = 1; j < is; j++) {
10180                                                        iax = da.getElementLongAbs(it.aIndex + j);
10181                                                        ox = (iax / ibx);
10182                                                        oaf64data[it.oIndex + j] = ox;
10183                                                }
10184                                        }
10185                                }
10186                        } else if (as == 1) {
10187                                if (it.isOutputDouble()) {
10188                                        while (it.hasNext()) {
10189                                                final double iax = it.aDouble;
10190                                                final double ibx = it.bDouble;
10191                                                double ox;
10192                                                ox = (iax / ibx);
10193                                                for (int j = 0; j < is; j++) {
10194                                                        oaf64data[it.oIndex + j] = ox;
10195                                                }
10196                                        }
10197                                } else {
10198                                        while (it.hasNext()) {
10199                                                final long iax = it.aLong;
10200                                                final long ibx = it.bLong;
10201                                                double ox;
10202                                                ox = (iax / ibx);
10203                                                for (int j = 0; j < is; j++) {
10204                                                        oaf64data[it.oIndex + j] = ox;
10205                                                }
10206                                        }
10207                                }
10208                        } else {
10209                                if (it.isOutputDouble()) {
10210                                        while (it.hasNext()) {
10211                                                double iax = it.aDouble;
10212                                                double ibx = it.bDouble;
10213                                                double ox;
10214                                                ox = (iax / ibx);
10215                                                oaf64data[it.oIndex] = ox;
10216                                                for (int j = 1; j < is; j++) {
10217                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10218                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10219                                                        ox = (iax / ibx);
10220                                                        oaf64data[it.oIndex + j] = ox;
10221                                                }
10222                                        }
10223                                } else {
10224                                        while (it.hasNext()) {
10225                                                long iax = it.aLong;
10226                                                long ibx = it.bLong;
10227                                                double ox;
10228                                                ox = (iax / ibx);
10229                                                oaf64data[it.oIndex] = ox;
10230                                                for (int j = 1; j < is; j++) {
10231                                                        iax = da.getElementLongAbs(it.aIndex + j);
10232                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10233                                                        ox = (iax / ibx);
10234                                                        oaf64data[it.oIndex + j] = ox;
10235                                                }
10236                                        }
10237                                }
10238                        }
10239                        break;
10240                case Dataset.COMPLEX64:
10241                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
10242                        if (!da.isComplex()) {
10243                                if (it.isOutputDouble()) {
10244                                        final double iay = 0;
10245                                        if (db.isComplex()) {
10246                                                while (it.hasNext()) {
10247                                                        final double iax = it.aDouble;
10248                                                        final double ibx = it.bDouble;
10249                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
10250                                                        float ox;
10251                                                        float oy;
10252                                                        float q;
10253                                                        float den;
10254                                                        if (iby == 0) {
10255                                                                ox = (float) (iax / ibx);
10256                                                                oy = (float) (iay / ibx);
10257                                                        } else if (ibx == 0) {
10258                                                                ox = (float) (iay / iby);
10259                                                                oy = (float) (-iax / iby);
10260                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
10261                                                                q = (float) (ibx / iby);
10262                                                                den = (float) (ibx * q + iby);
10263                                                                ox = (float) ((iax * q + iay) / den);
10264                                                                oy = (float) ((iay * q - iax) / den);
10265                                                        } else {
10266                                                                q = (float) (iby / ibx);
10267                                                                den = (float) (iby * q + ibx);
10268                                                                ox = (float) ((iay * q + iax) / den);
10269                                                                oy = (float) ((iay - iax * q) / den);
10270                                                        }
10271                                                        oc64data[it.oIndex] = ox;
10272                                                        oc64data[it.oIndex + 1] = oy;
10273                                                }
10274                                        } else {
10275                                                while (it.hasNext()) {
10276                                                        final double iax = it.aDouble;
10277                                                        final double ibx = it.bDouble;
10278                                                        float ox;
10279                                                        float oy;
10280                                                        ox = (float) (iax / ibx);
10281                                                        oy = (float) (iay / ibx);
10282                                                        oc64data[it.oIndex] = ox;
10283                                                        oc64data[it.oIndex + 1] = oy;
10284                                                }
10285                                        }
10286                                } else {
10287                                        final long iay = 0;
10288                                        while (it.hasNext()) {
10289                                                final long iax = it.aLong;
10290                                                final long ibx = it.bLong;
10291                                                float ox;
10292                                                float oy;
10293                                                ox = (float) (iax / ibx);
10294                                                oy = (float) (iay / ibx);
10295                                                oc64data[it.oIndex] = ox;
10296                                                oc64data[it.oIndex + 1] = oy;
10297                                        }
10298                                }
10299                        } else if (!db.isComplex()) {
10300                                while (it.hasNext()) {
10301                                        final double iax = it.aDouble;
10302                                        final double ibx = it.bDouble;
10303                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
10304                                        float ox;
10305                                        float oy;
10306                                        ox = (float) (iax / ibx);
10307                                        oy = (float) (iay / ibx);
10308                                        oc64data[it.oIndex] = ox;
10309                                        oc64data[it.oIndex + 1] = oy;
10310                                }
10311                        } else {
10312                                while (it.hasNext()) {
10313                                        final double iax = it.aDouble;
10314                                        final double ibx = it.bDouble;
10315                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
10316                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
10317                                        float ox;
10318                                        float oy;
10319                                        float q;
10320                                        float den;
10321                                        if (iby == 0) {
10322                                                ox = (float) (iax / ibx);
10323                                                oy = (float) (iay / ibx);
10324                                        } else if (ibx == 0) {
10325                                                ox = (float) (iay / iby);
10326                                                oy = (float) (-iax / iby);
10327                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
10328                                                q = (float) (ibx / iby);
10329                                                den = (float) (ibx * q + iby);
10330                                                ox = (float) ((iax * q + iay) / den);
10331                                                oy = (float) ((iay * q - iax) / den);
10332                                        } else {
10333                                                q = (float) (iby / ibx);
10334                                                den = (float) (iby * q + ibx);
10335                                                ox = (float) ((iay * q + iax) / den);
10336                                                oy = (float) ((iay - iax * q) / den);
10337                                        }
10338                                        oc64data[it.oIndex] = ox;
10339                                        oc64data[it.oIndex + 1] = oy;
10340                                }
10341                        }
10342                        break;
10343                case Dataset.COMPLEX128:
10344                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
10345                        if (!da.isComplex()) {
10346                                if (it.isOutputDouble()) {
10347                                        final double iay = 0;
10348                                        if (db.isComplex()) {
10349                                                while (it.hasNext()) {
10350                                                        final double iax = it.aDouble;
10351                                                        final double ibx = it.bDouble;
10352                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
10353                                                        double ox;
10354                                                        double oy;
10355                                                        double q;
10356                                                        double den;
10357                                                        if (iby == 0) {
10358                                                                ox = (iax / ibx);
10359                                                                oy = (iay / ibx);
10360                                                        } else if (ibx == 0) {
10361                                                                ox = (iay / iby);
10362                                                                oy = (-iax / iby);
10363                                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
10364                                                                q = (ibx / iby);
10365                                                                den = (ibx * q + iby);
10366                                                                ox = ((iax * q + iay) / den);
10367                                                                oy = ((iay * q - iax) / den);
10368                                                        } else {
10369                                                                q = (iby / ibx);
10370                                                                den = (iby * q + ibx);
10371                                                                ox = ((iay * q + iax) / den);
10372                                                                oy = ((iay - iax * q) / den);
10373                                                        }
10374                                                        oc128data[it.oIndex] = ox;
10375                                                        oc128data[it.oIndex + 1] = oy;
10376                                                }
10377                                        } else {
10378                                                while (it.hasNext()) {
10379                                                        final double iax = it.aDouble;
10380                                                        final double ibx = it.bDouble;
10381                                                        double ox;
10382                                                        double oy;
10383                                                        ox = (iax / ibx);
10384                                                        oy = (iay / ibx);
10385                                                        oc128data[it.oIndex] = ox;
10386                                                        oc128data[it.oIndex + 1] = oy;
10387                                                }
10388                                        }
10389                                } else {
10390                                        final long iay = 0;
10391                                        while (it.hasNext()) {
10392                                                final long iax = it.aLong;
10393                                                final long ibx = it.bLong;
10394                                                double ox;
10395                                                double oy;
10396                                                ox = (iax / ibx);
10397                                                oy = (iay / ibx);
10398                                                oc128data[it.oIndex] = ox;
10399                                                oc128data[it.oIndex + 1] = oy;
10400                                        }
10401                                }
10402                        } else if (!db.isComplex()) {
10403                                while (it.hasNext()) {
10404                                        final double iax = it.aDouble;
10405                                        final double ibx = it.bDouble;
10406                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
10407                                        double ox;
10408                                        double oy;
10409                                        ox = (iax / ibx);
10410                                        oy = (iay / ibx);
10411                                        oc128data[it.oIndex] = ox;
10412                                        oc128data[it.oIndex + 1] = oy;
10413                                }
10414                        } else {
10415                                while (it.hasNext()) {
10416                                        final double iax = it.aDouble;
10417                                        final double ibx = it.bDouble;
10418                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
10419                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
10420                                        double ox;
10421                                        double oy;
10422                                        double q;
10423                                        double den;
10424                                        if (iby == 0) {
10425                                                ox = (iax / ibx);
10426                                                oy = (iay / ibx);
10427                                        } else if (ibx == 0) {
10428                                                ox = (iay / iby);
10429                                                oy = (-iax / iby);
10430                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
10431                                                q = (ibx / iby);
10432                                                den = (ibx * q + iby);
10433                                                ox = ((iax * q + iay) / den);
10434                                                oy = ((iay * q - iax) / den);
10435                                        } else {
10436                                                q = (iby / ibx);
10437                                                den = (iby * q + ibx);
10438                                                ox = ((iay * q + iax) / den);
10439                                                oy = ((iay - iax * q) / den);
10440                                        }
10441                                        oc128data[it.oIndex] = ox;
10442                                        oc128data[it.oIndex + 1] = oy;
10443                                }
10444                        }
10445                        break;
10446                default:
10447                        throw new IllegalArgumentException("divideTowardsFloor supports integer, compound integer, real, compound real, complex datasets only");
10448                }
10449
10450                addBinaryOperatorName(da, db, result, "/");
10451                return result;
10452        }
10453
10454        /**
10455         * power operator
10456         * @param a first operand
10457         * @param b second operand
10458         * @return {@code a ** b}, raise a to power of b
10459         */
10460        public static Dataset power(final Object a, final Object b) {
10461                return power(a, b, null);
10462        }
10463
10464        /**
10465         * power operator
10466         * @param a first operand
10467         * @param b second operand
10468         * @param o output can be null - in which case, a new dataset is created
10469         * @return {@code a ** b}, raise a to power of b
10470         */
10471        public static Dataset power(final Object a, final Object b, final Dataset o) {
10472                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
10473                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
10474                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
10475                final Dataset result = it.getOutput();
10476                if (!result.isComplex()) {
10477                        boolean change = false;
10478                        if (da.isComplex()) {
10479                                da = da.getRealView();
10480                                change = true;
10481                        }
10482                        if (db.isComplex()) {
10483                                db = db.getRealView();
10484                                change = true;
10485                        }
10486                        if (change) {
10487                                it = BroadcastIterator.createIterator(da, db, result, true);
10488                        }
10489                }
10490                final int is = result.getElementsPerItem();
10491                final int as = da.getElementsPerItem();
10492                final int bs = db.getElementsPerItem();
10493                final int dt = result.getDType();
10494
10495                switch(dt) {
10496                case Dataset.INT8:
10497                        final byte[] oi8data = ((ByteDataset) result).getData();
10498                        if (it.isOutputDouble()) {
10499                                while (it.hasNext()) {
10500                                        final double iax = it.aDouble;
10501                                        final double ibx = it.bDouble;
10502                                        byte ox;
10503                                        ox = (byte) toLong(Math.pow(iax, ibx));
10504                                        oi8data[it.oIndex] = ox;
10505                                }
10506                        } else {
10507                                while (it.hasNext()) {
10508                                        final long iax = it.aLong;
10509                                        final long ibx = it.bLong;
10510                                        byte ox;
10511                                        ox = (byte) toLong(Math.pow(iax, ibx));
10512                                        oi8data[it.oIndex] = ox;
10513                                }
10514                        }
10515                        break;
10516                case Dataset.INT16:
10517                        final short[] oi16data = ((ShortDataset) result).getData();
10518                        if (it.isOutputDouble()) {
10519                                while (it.hasNext()) {
10520                                        final double iax = it.aDouble;
10521                                        final double ibx = it.bDouble;
10522                                        short ox;
10523                                        ox = (short) toLong(Math.pow(iax, ibx));
10524                                        oi16data[it.oIndex] = ox;
10525                                }
10526                        } else {
10527                                while (it.hasNext()) {
10528                                        final long iax = it.aLong;
10529                                        final long ibx = it.bLong;
10530                                        short ox;
10531                                        ox = (short) toLong(Math.pow(iax, ibx));
10532                                        oi16data[it.oIndex] = ox;
10533                                }
10534                        }
10535                        break;
10536                case Dataset.INT64:
10537                        final long[] oi64data = ((LongDataset) result).getData();
10538                        if (it.isOutputDouble()) {
10539                                while (it.hasNext()) {
10540                                        final double iax = it.aDouble;
10541                                        final double ibx = it.bDouble;
10542                                        long ox;
10543                                        ox = toLong(Math.pow(iax, ibx));
10544                                        oi64data[it.oIndex] = ox;
10545                                }
10546                        } else {
10547                                while (it.hasNext()) {
10548                                        final long iax = it.aLong;
10549                                        final long ibx = it.bLong;
10550                                        long ox;
10551                                        ox = toLong(Math.pow(iax, ibx));
10552                                        oi64data[it.oIndex] = ox;
10553                                }
10554                        }
10555                        break;
10556                case Dataset.INT32:
10557                        final int[] oi32data = ((IntegerDataset) result).getData();
10558                        if (it.isOutputDouble()) {
10559                                while (it.hasNext()) {
10560                                        final double iax = it.aDouble;
10561                                        final double ibx = it.bDouble;
10562                                        int ox;
10563                                        ox = (int) toLong(Math.pow(iax, ibx));
10564                                        oi32data[it.oIndex] = ox;
10565                                }
10566                        } else {
10567                                while (it.hasNext()) {
10568                                        final long iax = it.aLong;
10569                                        final long ibx = it.bLong;
10570                                        int ox;
10571                                        ox = (int) toLong(Math.pow(iax, ibx));
10572                                        oi32data[it.oIndex] = ox;
10573                                }
10574                        }
10575                        break;
10576                case Dataset.ARRAYINT8:
10577                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
10578                        if (is == 1) {
10579                                if (it.isOutputDouble()) {
10580                                        while (it.hasNext()) {
10581                                                final double iax = it.aDouble;
10582                                                final double ibx = it.bDouble;
10583                                                byte ox;
10584                                                ox = (byte) toLong(Math.pow(iax, ibx));
10585                                                oai8data[it.oIndex] = ox;
10586                                        }
10587                                } else {
10588                                        while (it.hasNext()) {
10589                                                final long iax = it.aLong;
10590                                                final long ibx = it.bLong;
10591                                                byte ox;
10592                                                ox = (byte) toLong(Math.pow(iax, ibx));
10593                                                oai8data[it.oIndex] = ox;
10594                                        }
10595                                }
10596                        } else if (as < bs) {
10597                                if (it.isOutputDouble()) {
10598                                        while (it.hasNext()) {
10599                                                final double iax = it.aDouble;
10600                                                double ibx = it.bDouble;
10601                                                byte ox;
10602                                                ox = (byte) toLong(Math.pow(iax, ibx));
10603                                                oai8data[it.oIndex] = ox;
10604                                                for (int j = 1; j < is; j++) {
10605                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10606                                                        ox = (byte) toLong(Math.pow(iax, ibx));
10607                                                        oai8data[it.oIndex + j] = ox;
10608                                                }
10609                                        }
10610                                } else {
10611                                        while (it.hasNext()) {
10612                                                final long iax = it.aLong;
10613                                                long ibx = it.bLong;
10614                                                byte ox;
10615                                                ox = (byte) toLong(Math.pow(iax, ibx));
10616                                                oai8data[it.oIndex] = ox;
10617                                                for (int j = 1; j < is; j++) {
10618                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10619                                                        ox = (byte) toLong(Math.pow(iax, ibx));
10620                                                        oai8data[it.oIndex + j] = ox;
10621                                                }
10622                                        }
10623                                }
10624                        } else if (as > bs) {
10625                                if (it.isOutputDouble()) {
10626                                        while (it.hasNext()) {
10627                                                double iax = it.aDouble;
10628                                                final double ibx = it.bDouble;
10629                                                byte ox;
10630                                                ox = (byte) toLong(Math.pow(iax, ibx));
10631                                                oai8data[it.oIndex] = ox;
10632                                                for (int j = 1; j < is; j++) {
10633                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10634                                                        ox = (byte) toLong(Math.pow(iax, ibx));
10635                                                        oai8data[it.oIndex + j] = ox;
10636                                                }
10637                                        }
10638                                } else {
10639                                        while (it.hasNext()) {
10640                                                long iax = it.aLong;
10641                                                final long ibx = it.bLong;
10642                                                byte ox;
10643                                                ox = (byte) toLong(Math.pow(iax, ibx));
10644                                                oai8data[it.oIndex] = ox;
10645                                                for (int j = 1; j < is; j++) {
10646                                                        iax = da.getElementLongAbs(it.aIndex + j);
10647                                                        ox = (byte) toLong(Math.pow(iax, ibx));
10648                                                        oai8data[it.oIndex + j] = ox;
10649                                                }
10650                                        }
10651                                }
10652                        } else if (as == 1) {
10653                                if (it.isOutputDouble()) {
10654                                        while (it.hasNext()) {
10655                                                final double iax = it.aDouble;
10656                                                final double ibx = it.bDouble;
10657                                                byte ox;
10658                                                ox = (byte) toLong(Math.pow(iax, ibx));
10659                                                for (int j = 0; j < is; j++) {
10660                                                        oai8data[it.oIndex + j] = ox;
10661                                                }
10662                                        }
10663                                } else {
10664                                        while (it.hasNext()) {
10665                                                final long iax = it.aLong;
10666                                                final long ibx = it.bLong;
10667                                                byte ox;
10668                                                ox = (byte) toLong(Math.pow(iax, ibx));
10669                                                for (int j = 0; j < is; j++) {
10670                                                        oai8data[it.oIndex + j] = ox;
10671                                                }
10672                                        }
10673                                }
10674                        } else {
10675                                if (it.isOutputDouble()) {
10676                                        while (it.hasNext()) {
10677                                                double iax = it.aDouble;
10678                                                double ibx = it.bDouble;
10679                                                byte ox;
10680                                                ox = (byte) toLong(Math.pow(iax, ibx));
10681                                                oai8data[it.oIndex] = ox;
10682                                                for (int j = 1; j < is; j++) {
10683                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10684                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10685                                                        ox = (byte) toLong(Math.pow(iax, ibx));
10686                                                        oai8data[it.oIndex + j] = ox;
10687                                                }
10688                                        }
10689                                } else {
10690                                        while (it.hasNext()) {
10691                                                long iax = it.aLong;
10692                                                long ibx = it.bLong;
10693                                                byte ox;
10694                                                ox = (byte) toLong(Math.pow(iax, ibx));
10695                                                oai8data[it.oIndex] = ox;
10696                                                for (int j = 1; j < is; j++) {
10697                                                        iax = da.getElementLongAbs(it.aIndex + j);
10698                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10699                                                        ox = (byte) toLong(Math.pow(iax, ibx));
10700                                                        oai8data[it.oIndex + j] = ox;
10701                                                }
10702                                        }
10703                                }
10704                        }
10705                        break;
10706                case Dataset.ARRAYINT16:
10707                        final short[] oai16data = ((CompoundShortDataset) result).getData();
10708                        if (is == 1) {
10709                                if (it.isOutputDouble()) {
10710                                        while (it.hasNext()) {
10711                                                final double iax = it.aDouble;
10712                                                final double ibx = it.bDouble;
10713                                                short ox;
10714                                                ox = (short) toLong(Math.pow(iax, ibx));
10715                                                oai16data[it.oIndex] = ox;
10716                                        }
10717                                } else {
10718                                        while (it.hasNext()) {
10719                                                final long iax = it.aLong;
10720                                                final long ibx = it.bLong;
10721                                                short ox;
10722                                                ox = (short) toLong(Math.pow(iax, ibx));
10723                                                oai16data[it.oIndex] = ox;
10724                                        }
10725                                }
10726                        } else if (as < bs) {
10727                                if (it.isOutputDouble()) {
10728                                        while (it.hasNext()) {
10729                                                final double iax = it.aDouble;
10730                                                double ibx = it.bDouble;
10731                                                short ox;
10732                                                ox = (short) toLong(Math.pow(iax, ibx));
10733                                                oai16data[it.oIndex] = ox;
10734                                                for (int j = 1; j < is; j++) {
10735                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10736                                                        ox = (short) toLong(Math.pow(iax, ibx));
10737                                                        oai16data[it.oIndex + j] = ox;
10738                                                }
10739                                        }
10740                                } else {
10741                                        while (it.hasNext()) {
10742                                                final long iax = it.aLong;
10743                                                long ibx = it.bLong;
10744                                                short ox;
10745                                                ox = (short) toLong(Math.pow(iax, ibx));
10746                                                oai16data[it.oIndex] = ox;
10747                                                for (int j = 1; j < is; j++) {
10748                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10749                                                        ox = (short) toLong(Math.pow(iax, ibx));
10750                                                        oai16data[it.oIndex + j] = ox;
10751                                                }
10752                                        }
10753                                }
10754                        } else if (as > bs) {
10755                                if (it.isOutputDouble()) {
10756                                        while (it.hasNext()) {
10757                                                double iax = it.aDouble;
10758                                                final double ibx = it.bDouble;
10759                                                short ox;
10760                                                ox = (short) toLong(Math.pow(iax, ibx));
10761                                                oai16data[it.oIndex] = ox;
10762                                                for (int j = 1; j < is; j++) {
10763                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10764                                                        ox = (short) toLong(Math.pow(iax, ibx));
10765                                                        oai16data[it.oIndex + j] = ox;
10766                                                }
10767                                        }
10768                                } else {
10769                                        while (it.hasNext()) {
10770                                                long iax = it.aLong;
10771                                                final long ibx = it.bLong;
10772                                                short ox;
10773                                                ox = (short) toLong(Math.pow(iax, ibx));
10774                                                oai16data[it.oIndex] = ox;
10775                                                for (int j = 1; j < is; j++) {
10776                                                        iax = da.getElementLongAbs(it.aIndex + j);
10777                                                        ox = (short) toLong(Math.pow(iax, ibx));
10778                                                        oai16data[it.oIndex + j] = ox;
10779                                                }
10780                                        }
10781                                }
10782                        } else if (as == 1) {
10783                                if (it.isOutputDouble()) {
10784                                        while (it.hasNext()) {
10785                                                final double iax = it.aDouble;
10786                                                final double ibx = it.bDouble;
10787                                                short ox;
10788                                                ox = (short) toLong(Math.pow(iax, ibx));
10789                                                for (int j = 0; j < is; j++) {
10790                                                        oai16data[it.oIndex + j] = ox;
10791                                                }
10792                                        }
10793                                } else {
10794                                        while (it.hasNext()) {
10795                                                final long iax = it.aLong;
10796                                                final long ibx = it.bLong;
10797                                                short ox;
10798                                                ox = (short) toLong(Math.pow(iax, ibx));
10799                                                for (int j = 0; j < is; j++) {
10800                                                        oai16data[it.oIndex + j] = ox;
10801                                                }
10802                                        }
10803                                }
10804                        } else {
10805                                if (it.isOutputDouble()) {
10806                                        while (it.hasNext()) {
10807                                                double iax = it.aDouble;
10808                                                double ibx = it.bDouble;
10809                                                short ox;
10810                                                ox = (short) toLong(Math.pow(iax, ibx));
10811                                                oai16data[it.oIndex] = ox;
10812                                                for (int j = 1; j < is; j++) {
10813                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10814                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10815                                                        ox = (short) toLong(Math.pow(iax, ibx));
10816                                                        oai16data[it.oIndex + j] = ox;
10817                                                }
10818                                        }
10819                                } else {
10820                                        while (it.hasNext()) {
10821                                                long iax = it.aLong;
10822                                                long ibx = it.bLong;
10823                                                short ox;
10824                                                ox = (short) toLong(Math.pow(iax, ibx));
10825                                                oai16data[it.oIndex] = ox;
10826                                                for (int j = 1; j < is; j++) {
10827                                                        iax = da.getElementLongAbs(it.aIndex + j);
10828                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10829                                                        ox = (short) toLong(Math.pow(iax, ibx));
10830                                                        oai16data[it.oIndex + j] = ox;
10831                                                }
10832                                        }
10833                                }
10834                        }
10835                        break;
10836                case Dataset.ARRAYINT64:
10837                        final long[] oai64data = ((CompoundLongDataset) result).getData();
10838                        if (is == 1) {
10839                                if (it.isOutputDouble()) {
10840                                        while (it.hasNext()) {
10841                                                final double iax = it.aDouble;
10842                                                final double ibx = it.bDouble;
10843                                                long ox;
10844                                                ox = toLong(Math.pow(iax, ibx));
10845                                                oai64data[it.oIndex] = ox;
10846                                        }
10847                                } else {
10848                                        while (it.hasNext()) {
10849                                                final long iax = it.aLong;
10850                                                final long ibx = it.bLong;
10851                                                long ox;
10852                                                ox = toLong(Math.pow(iax, ibx));
10853                                                oai64data[it.oIndex] = ox;
10854                                        }
10855                                }
10856                        } else if (as < bs) {
10857                                if (it.isOutputDouble()) {
10858                                        while (it.hasNext()) {
10859                                                final double iax = it.aDouble;
10860                                                double ibx = it.bDouble;
10861                                                long ox;
10862                                                ox = toLong(Math.pow(iax, ibx));
10863                                                oai64data[it.oIndex] = ox;
10864                                                for (int j = 1; j < is; j++) {
10865                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10866                                                        ox = toLong(Math.pow(iax, ibx));
10867                                                        oai64data[it.oIndex + j] = ox;
10868                                                }
10869                                        }
10870                                } else {
10871                                        while (it.hasNext()) {
10872                                                final long iax = it.aLong;
10873                                                long ibx = it.bLong;
10874                                                long ox;
10875                                                ox = toLong(Math.pow(iax, ibx));
10876                                                oai64data[it.oIndex] = ox;
10877                                                for (int j = 1; j < is; j++) {
10878                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10879                                                        ox = toLong(Math.pow(iax, ibx));
10880                                                        oai64data[it.oIndex + j] = ox;
10881                                                }
10882                                        }
10883                                }
10884                        } else if (as > bs) {
10885                                if (it.isOutputDouble()) {
10886                                        while (it.hasNext()) {
10887                                                double iax = it.aDouble;
10888                                                final double ibx = it.bDouble;
10889                                                long ox;
10890                                                ox = toLong(Math.pow(iax, ibx));
10891                                                oai64data[it.oIndex] = ox;
10892                                                for (int j = 1; j < is; j++) {
10893                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10894                                                        ox = toLong(Math.pow(iax, ibx));
10895                                                        oai64data[it.oIndex + j] = ox;
10896                                                }
10897                                        }
10898                                } else {
10899                                        while (it.hasNext()) {
10900                                                long iax = it.aLong;
10901                                                final long ibx = it.bLong;
10902                                                long ox;
10903                                                ox = toLong(Math.pow(iax, ibx));
10904                                                oai64data[it.oIndex] = ox;
10905                                                for (int j = 1; j < is; j++) {
10906                                                        iax = da.getElementLongAbs(it.aIndex + j);
10907                                                        ox = toLong(Math.pow(iax, ibx));
10908                                                        oai64data[it.oIndex + j] = ox;
10909                                                }
10910                                        }
10911                                }
10912                        } else if (as == 1) {
10913                                if (it.isOutputDouble()) {
10914                                        while (it.hasNext()) {
10915                                                final double iax = it.aDouble;
10916                                                final double ibx = it.bDouble;
10917                                                long ox;
10918                                                ox = toLong(Math.pow(iax, ibx));
10919                                                for (int j = 0; j < is; j++) {
10920                                                        oai64data[it.oIndex + j] = ox;
10921                                                }
10922                                        }
10923                                } else {
10924                                        while (it.hasNext()) {
10925                                                final long iax = it.aLong;
10926                                                final long ibx = it.bLong;
10927                                                long ox;
10928                                                ox = toLong(Math.pow(iax, ibx));
10929                                                for (int j = 0; j < is; j++) {
10930                                                        oai64data[it.oIndex + j] = ox;
10931                                                }
10932                                        }
10933                                }
10934                        } else {
10935                                if (it.isOutputDouble()) {
10936                                        while (it.hasNext()) {
10937                                                double iax = it.aDouble;
10938                                                double ibx = it.bDouble;
10939                                                long ox;
10940                                                ox = toLong(Math.pow(iax, ibx));
10941                                                oai64data[it.oIndex] = ox;
10942                                                for (int j = 1; j < is; j++) {
10943                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
10944                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10945                                                        ox = toLong(Math.pow(iax, ibx));
10946                                                        oai64data[it.oIndex + j] = ox;
10947                                                }
10948                                        }
10949                                } else {
10950                                        while (it.hasNext()) {
10951                                                long iax = it.aLong;
10952                                                long ibx = it.bLong;
10953                                                long ox;
10954                                                ox = toLong(Math.pow(iax, ibx));
10955                                                oai64data[it.oIndex] = ox;
10956                                                for (int j = 1; j < is; j++) {
10957                                                        iax = da.getElementLongAbs(it.aIndex + j);
10958                                                        ibx = db.getElementLongAbs(it.bIndex + j);
10959                                                        ox = toLong(Math.pow(iax, ibx));
10960                                                        oai64data[it.oIndex + j] = ox;
10961                                                }
10962                                        }
10963                                }
10964                        }
10965                        break;
10966                case Dataset.ARRAYINT32:
10967                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
10968                        if (is == 1) {
10969                                if (it.isOutputDouble()) {
10970                                        while (it.hasNext()) {
10971                                                final double iax = it.aDouble;
10972                                                final double ibx = it.bDouble;
10973                                                int ox;
10974                                                ox = (int) toLong(Math.pow(iax, ibx));
10975                                                oai32data[it.oIndex] = ox;
10976                                        }
10977                                } else {
10978                                        while (it.hasNext()) {
10979                                                final long iax = it.aLong;
10980                                                final long ibx = it.bLong;
10981                                                int ox;
10982                                                ox = (int) toLong(Math.pow(iax, ibx));
10983                                                oai32data[it.oIndex] = ox;
10984                                        }
10985                                }
10986                        } else if (as < bs) {
10987                                if (it.isOutputDouble()) {
10988                                        while (it.hasNext()) {
10989                                                final double iax = it.aDouble;
10990                                                double ibx = it.bDouble;
10991                                                int ox;
10992                                                ox = (int) toLong(Math.pow(iax, ibx));
10993                                                oai32data[it.oIndex] = ox;
10994                                                for (int j = 1; j < is; j++) {
10995                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
10996                                                        ox = (int) toLong(Math.pow(iax, ibx));
10997                                                        oai32data[it.oIndex + j] = ox;
10998                                                }
10999                                        }
11000                                } else {
11001                                        while (it.hasNext()) {
11002                                                final long iax = it.aLong;
11003                                                long ibx = it.bLong;
11004                                                int ox;
11005                                                ox = (int) toLong(Math.pow(iax, ibx));
11006                                                oai32data[it.oIndex] = ox;
11007                                                for (int j = 1; j < is; j++) {
11008                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11009                                                        ox = (int) toLong(Math.pow(iax, ibx));
11010                                                        oai32data[it.oIndex + j] = ox;
11011                                                }
11012                                        }
11013                                }
11014                        } else if (as > bs) {
11015                                if (it.isOutputDouble()) {
11016                                        while (it.hasNext()) {
11017                                                double iax = it.aDouble;
11018                                                final double ibx = it.bDouble;
11019                                                int ox;
11020                                                ox = (int) toLong(Math.pow(iax, ibx));
11021                                                oai32data[it.oIndex] = ox;
11022                                                for (int j = 1; j < is; j++) {
11023                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11024                                                        ox = (int) toLong(Math.pow(iax, ibx));
11025                                                        oai32data[it.oIndex + j] = ox;
11026                                                }
11027                                        }
11028                                } else {
11029                                        while (it.hasNext()) {
11030                                                long iax = it.aLong;
11031                                                final long ibx = it.bLong;
11032                                                int ox;
11033                                                ox = (int) toLong(Math.pow(iax, ibx));
11034                                                oai32data[it.oIndex] = ox;
11035                                                for (int j = 1; j < is; j++) {
11036                                                        iax = da.getElementLongAbs(it.aIndex + j);
11037                                                        ox = (int) toLong(Math.pow(iax, ibx));
11038                                                        oai32data[it.oIndex + j] = ox;
11039                                                }
11040                                        }
11041                                }
11042                        } else if (as == 1) {
11043                                if (it.isOutputDouble()) {
11044                                        while (it.hasNext()) {
11045                                                final double iax = it.aDouble;
11046                                                final double ibx = it.bDouble;
11047                                                int ox;
11048                                                ox = (int) toLong(Math.pow(iax, ibx));
11049                                                for (int j = 0; j < is; j++) {
11050                                                        oai32data[it.oIndex + j] = ox;
11051                                                }
11052                                        }
11053                                } else {
11054                                        while (it.hasNext()) {
11055                                                final long iax = it.aLong;
11056                                                final long ibx = it.bLong;
11057                                                int ox;
11058                                                ox = (int) toLong(Math.pow(iax, ibx));
11059                                                for (int j = 0; j < is; j++) {
11060                                                        oai32data[it.oIndex + j] = ox;
11061                                                }
11062                                        }
11063                                }
11064                        } else {
11065                                if (it.isOutputDouble()) {
11066                                        while (it.hasNext()) {
11067                                                double iax = it.aDouble;
11068                                                double ibx = it.bDouble;
11069                                                int ox;
11070                                                ox = (int) toLong(Math.pow(iax, ibx));
11071                                                oai32data[it.oIndex] = ox;
11072                                                for (int j = 1; j < is; j++) {
11073                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11074                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11075                                                        ox = (int) toLong(Math.pow(iax, ibx));
11076                                                        oai32data[it.oIndex + j] = ox;
11077                                                }
11078                                        }
11079                                } else {
11080                                        while (it.hasNext()) {
11081                                                long iax = it.aLong;
11082                                                long ibx = it.bLong;
11083                                                int ox;
11084                                                ox = (int) toLong(Math.pow(iax, ibx));
11085                                                oai32data[it.oIndex] = ox;
11086                                                for (int j = 1; j < is; j++) {
11087                                                        iax = da.getElementLongAbs(it.aIndex + j);
11088                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11089                                                        ox = (int) toLong(Math.pow(iax, ibx));
11090                                                        oai32data[it.oIndex + j] = ox;
11091                                                }
11092                                        }
11093                                }
11094                        }
11095                        break;
11096                case Dataset.FLOAT32:
11097                        final float[] of32data = ((FloatDataset) result).getData();
11098                        if (it.isOutputDouble()) {
11099                                while (it.hasNext()) {
11100                                        final double iax = it.aDouble;
11101                                        final double ibx = it.bDouble;
11102                                        float ox;
11103                                        ox = (float) (Math.pow(iax, ibx));
11104                                        of32data[it.oIndex] = ox;
11105                                }
11106                        } else {
11107                                while (it.hasNext()) {
11108                                        final long iax = it.aLong;
11109                                        final long ibx = it.bLong;
11110                                        float ox;
11111                                        ox = (float) (Math.pow(iax, ibx));
11112                                        of32data[it.oIndex] = ox;
11113                                }
11114                        }
11115                        break;
11116                case Dataset.FLOAT64:
11117                        final double[] of64data = ((DoubleDataset) result).getData();
11118                        if (it.isOutputDouble()) {
11119                                while (it.hasNext()) {
11120                                        final double iax = it.aDouble;
11121                                        final double ibx = it.bDouble;
11122                                        double ox;
11123                                        ox = (Math.pow(iax, ibx));
11124                                        of64data[it.oIndex] = ox;
11125                                }
11126                        } else {
11127                                while (it.hasNext()) {
11128                                        final long iax = it.aLong;
11129                                        final long ibx = it.bLong;
11130                                        double ox;
11131                                        ox = (Math.pow(iax, ibx));
11132                                        of64data[it.oIndex] = ox;
11133                                }
11134                        }
11135                        break;
11136                case Dataset.ARRAYFLOAT32:
11137                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
11138                        if (is == 1) {
11139                                if (it.isOutputDouble()) {
11140                                        while (it.hasNext()) {
11141                                                final double iax = it.aDouble;
11142                                                final double ibx = it.bDouble;
11143                                                float ox;
11144                                                ox = (float) (Math.pow(iax, ibx));
11145                                                oaf32data[it.oIndex] = ox;
11146                                        }
11147                                } else {
11148                                        while (it.hasNext()) {
11149                                                final long iax = it.aLong;
11150                                                final long ibx = it.bLong;
11151                                                float ox;
11152                                                ox = (float) (Math.pow(iax, ibx));
11153                                                oaf32data[it.oIndex] = ox;
11154                                        }
11155                                }
11156                        } else if (as < bs) {
11157                                if (it.isOutputDouble()) {
11158                                        while (it.hasNext()) {
11159                                                final double iax = it.aDouble;
11160                                                double ibx = it.bDouble;
11161                                                float ox;
11162                                                ox = (float) (Math.pow(iax, ibx));
11163                                                oaf32data[it.oIndex] = ox;
11164                                                for (int j = 1; j < is; j++) {
11165                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11166                                                        ox = (float) (Math.pow(iax, ibx));
11167                                                        oaf32data[it.oIndex + j] = ox;
11168                                                }
11169                                        }
11170                                } else {
11171                                        while (it.hasNext()) {
11172                                                final long iax = it.aLong;
11173                                                long ibx = it.bLong;
11174                                                float ox;
11175                                                ox = (float) (Math.pow(iax, ibx));
11176                                                oaf32data[it.oIndex] = ox;
11177                                                for (int j = 1; j < is; j++) {
11178                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11179                                                        ox = (float) (Math.pow(iax, ibx));
11180                                                        oaf32data[it.oIndex + j] = ox;
11181                                                }
11182                                        }
11183                                }
11184                        } else if (as > bs) {
11185                                if (it.isOutputDouble()) {
11186                                        while (it.hasNext()) {
11187                                                double iax = it.aDouble;
11188                                                final double ibx = it.bDouble;
11189                                                float ox;
11190                                                ox = (float) (Math.pow(iax, ibx));
11191                                                oaf32data[it.oIndex] = ox;
11192                                                for (int j = 1; j < is; j++) {
11193                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11194                                                        ox = (float) (Math.pow(iax, ibx));
11195                                                        oaf32data[it.oIndex + j] = ox;
11196                                                }
11197                                        }
11198                                } else {
11199                                        while (it.hasNext()) {
11200                                                long iax = it.aLong;
11201                                                final long ibx = it.bLong;
11202                                                float ox;
11203                                                ox = (float) (Math.pow(iax, ibx));
11204                                                oaf32data[it.oIndex] = ox;
11205                                                for (int j = 1; j < is; j++) {
11206                                                        iax = da.getElementLongAbs(it.aIndex + j);
11207                                                        ox = (float) (Math.pow(iax, ibx));
11208                                                        oaf32data[it.oIndex + j] = ox;
11209                                                }
11210                                        }
11211                                }
11212                        } else if (as == 1) {
11213                                if (it.isOutputDouble()) {
11214                                        while (it.hasNext()) {
11215                                                final double iax = it.aDouble;
11216                                                final double ibx = it.bDouble;
11217                                                float ox;
11218                                                ox = (float) (Math.pow(iax, ibx));
11219                                                for (int j = 0; j < is; j++) {
11220                                                        oaf32data[it.oIndex + j] = ox;
11221                                                }
11222                                        }
11223                                } else {
11224                                        while (it.hasNext()) {
11225                                                final long iax = it.aLong;
11226                                                final long ibx = it.bLong;
11227                                                float ox;
11228                                                ox = (float) (Math.pow(iax, ibx));
11229                                                for (int j = 0; j < is; j++) {
11230                                                        oaf32data[it.oIndex + j] = ox;
11231                                                }
11232                                        }
11233                                }
11234                        } else {
11235                                if (it.isOutputDouble()) {
11236                                        while (it.hasNext()) {
11237                                                double iax = it.aDouble;
11238                                                double ibx = it.bDouble;
11239                                                float ox;
11240                                                ox = (float) (Math.pow(iax, ibx));
11241                                                oaf32data[it.oIndex] = ox;
11242                                                for (int j = 1; j < is; j++) {
11243                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11244                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11245                                                        ox = (float) (Math.pow(iax, ibx));
11246                                                        oaf32data[it.oIndex + j] = ox;
11247                                                }
11248                                        }
11249                                } else {
11250                                        while (it.hasNext()) {
11251                                                long iax = it.aLong;
11252                                                long ibx = it.bLong;
11253                                                float ox;
11254                                                ox = (float) (Math.pow(iax, ibx));
11255                                                oaf32data[it.oIndex] = ox;
11256                                                for (int j = 1; j < is; j++) {
11257                                                        iax = da.getElementLongAbs(it.aIndex + j);
11258                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11259                                                        ox = (float) (Math.pow(iax, ibx));
11260                                                        oaf32data[it.oIndex + j] = ox;
11261                                                }
11262                                        }
11263                                }
11264                        }
11265                        break;
11266                case Dataset.ARRAYFLOAT64:
11267                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
11268                        if (is == 1) {
11269                                if (it.isOutputDouble()) {
11270                                        while (it.hasNext()) {
11271                                                final double iax = it.aDouble;
11272                                                final double ibx = it.bDouble;
11273                                                double ox;
11274                                                ox = (Math.pow(iax, ibx));
11275                                                oaf64data[it.oIndex] = ox;
11276                                        }
11277                                } else {
11278                                        while (it.hasNext()) {
11279                                                final long iax = it.aLong;
11280                                                final long ibx = it.bLong;
11281                                                double ox;
11282                                                ox = (Math.pow(iax, ibx));
11283                                                oaf64data[it.oIndex] = ox;
11284                                        }
11285                                }
11286                        } else if (as < bs) {
11287                                if (it.isOutputDouble()) {
11288                                        while (it.hasNext()) {
11289                                                final double iax = it.aDouble;
11290                                                double ibx = it.bDouble;
11291                                                double ox;
11292                                                ox = (Math.pow(iax, ibx));
11293                                                oaf64data[it.oIndex] = ox;
11294                                                for (int j = 1; j < is; j++) {
11295                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11296                                                        ox = (Math.pow(iax, ibx));
11297                                                        oaf64data[it.oIndex + j] = ox;
11298                                                }
11299                                        }
11300                                } else {
11301                                        while (it.hasNext()) {
11302                                                final long iax = it.aLong;
11303                                                long ibx = it.bLong;
11304                                                double ox;
11305                                                ox = (Math.pow(iax, ibx));
11306                                                oaf64data[it.oIndex] = ox;
11307                                                for (int j = 1; j < is; j++) {
11308                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11309                                                        ox = (Math.pow(iax, ibx));
11310                                                        oaf64data[it.oIndex + j] = ox;
11311                                                }
11312                                        }
11313                                }
11314                        } else if (as > bs) {
11315                                if (it.isOutputDouble()) {
11316                                        while (it.hasNext()) {
11317                                                double iax = it.aDouble;
11318                                                final double ibx = it.bDouble;
11319                                                double ox;
11320                                                ox = (Math.pow(iax, ibx));
11321                                                oaf64data[it.oIndex] = ox;
11322                                                for (int j = 1; j < is; j++) {
11323                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11324                                                        ox = (Math.pow(iax, ibx));
11325                                                        oaf64data[it.oIndex + j] = ox;
11326                                                }
11327                                        }
11328                                } else {
11329                                        while (it.hasNext()) {
11330                                                long iax = it.aLong;
11331                                                final long ibx = it.bLong;
11332                                                double ox;
11333                                                ox = (Math.pow(iax, ibx));
11334                                                oaf64data[it.oIndex] = ox;
11335                                                for (int j = 1; j < is; j++) {
11336                                                        iax = da.getElementLongAbs(it.aIndex + j);
11337                                                        ox = (Math.pow(iax, ibx));
11338                                                        oaf64data[it.oIndex + j] = ox;
11339                                                }
11340                                        }
11341                                }
11342                        } else if (as == 1) {
11343                                if (it.isOutputDouble()) {
11344                                        while (it.hasNext()) {
11345                                                final double iax = it.aDouble;
11346                                                final double ibx = it.bDouble;
11347                                                double ox;
11348                                                ox = (Math.pow(iax, ibx));
11349                                                for (int j = 0; j < is; j++) {
11350                                                        oaf64data[it.oIndex + j] = ox;
11351                                                }
11352                                        }
11353                                } else {
11354                                        while (it.hasNext()) {
11355                                                final long iax = it.aLong;
11356                                                final long ibx = it.bLong;
11357                                                double ox;
11358                                                ox = (Math.pow(iax, ibx));
11359                                                for (int j = 0; j < is; j++) {
11360                                                        oaf64data[it.oIndex + j] = ox;
11361                                                }
11362                                        }
11363                                }
11364                        } else {
11365                                if (it.isOutputDouble()) {
11366                                        while (it.hasNext()) {
11367                                                double iax = it.aDouble;
11368                                                double ibx = it.bDouble;
11369                                                double ox;
11370                                                ox = (Math.pow(iax, ibx));
11371                                                oaf64data[it.oIndex] = ox;
11372                                                for (int j = 1; j < is; j++) {
11373                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11374                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11375                                                        ox = (Math.pow(iax, ibx));
11376                                                        oaf64data[it.oIndex + j] = ox;
11377                                                }
11378                                        }
11379                                } else {
11380                                        while (it.hasNext()) {
11381                                                long iax = it.aLong;
11382                                                long ibx = it.bLong;
11383                                                double ox;
11384                                                ox = (Math.pow(iax, ibx));
11385                                                oaf64data[it.oIndex] = ox;
11386                                                for (int j = 1; j < is; j++) {
11387                                                        iax = da.getElementLongAbs(it.aIndex + j);
11388                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11389                                                        ox = (Math.pow(iax, ibx));
11390                                                        oaf64data[it.oIndex + j] = ox;
11391                                                }
11392                                        }
11393                                }
11394                        }
11395                        break;
11396                case Dataset.COMPLEX64:
11397                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
11398                        if (!da.isComplex()) {
11399                                if (it.isOutputDouble()) {
11400                                        final double iay = 0;
11401                                        if (db.isComplex()) {
11402                                                while (it.hasNext()) {
11403                                                        final double iax = it.aDouble;
11404                                                        final double ibx = it.bDouble;
11405                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
11406                                                        Complex tz;
11407                                                        float ox;
11408                                                        float oy;
11409                                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11410                                                        ox = (float) (tz.getReal());
11411                                                        oy = (float) (tz.getImaginary());
11412                                                        oc64data[it.oIndex] = ox;
11413                                                        oc64data[it.oIndex + 1] = oy;
11414                                                }
11415                                        } else {
11416                                                while (it.hasNext()) {
11417                                                        final double iax = it.aDouble;
11418                                                        final double ibx = it.bDouble;
11419                                                        final double iby = 0;
11420                                                        Complex tz;
11421                                                        float ox;
11422                                                        float oy;
11423                                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11424                                                        ox = (float) (tz.getReal());
11425                                                        oy = (float) (tz.getImaginary());
11426                                                        oc64data[it.oIndex] = ox;
11427                                                        oc64data[it.oIndex + 1] = oy;
11428                                                }
11429                                        }
11430                                } else {
11431                                        final long iay = 0;
11432                                        while (it.hasNext()) {
11433                                                final long iax = it.aLong;
11434                                                final long ibx = it.bLong;
11435                                                final long iby = 0;
11436                                                Complex tz;
11437                                                float ox;
11438                                                float oy;
11439                                                tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11440                                                ox = (float) (tz.getReal());
11441                                                oy = (float) (tz.getImaginary());
11442                                                oc64data[it.oIndex] = ox;
11443                                                oc64data[it.oIndex + 1] = oy;
11444                                        }
11445                                }
11446                        } else if (!db.isComplex()) {
11447                                final double iby = 0;
11448                                while (it.hasNext()) {
11449                                        final double iax = it.aDouble;
11450                                        final double ibx = it.bDouble;
11451                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
11452                                        Complex tz;
11453                                        float ox;
11454                                        float oy;
11455                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11456                                        ox = (float) (tz.getReal());
11457                                        oy = (float) (tz.getImaginary());
11458                                        oc64data[it.oIndex] = ox;
11459                                        oc64data[it.oIndex + 1] = oy;
11460                                }
11461                        } else {
11462                                while (it.hasNext()) {
11463                                        final double iax = it.aDouble;
11464                                        final double ibx = it.bDouble;
11465                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
11466                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
11467                                        Complex tz;
11468                                        float ox;
11469                                        float oy;
11470                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11471                                        ox = (float) (tz.getReal());
11472                                        oy = (float) (tz.getImaginary());
11473                                        oc64data[it.oIndex] = ox;
11474                                        oc64data[it.oIndex + 1] = oy;
11475                                }
11476                        }
11477                        break;
11478                case Dataset.COMPLEX128:
11479                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
11480                        if (!da.isComplex()) {
11481                                if (it.isOutputDouble()) {
11482                                        final double iay = 0;
11483                                        if (db.isComplex()) {
11484                                                while (it.hasNext()) {
11485                                                        final double iax = it.aDouble;
11486                                                        final double ibx = it.bDouble;
11487                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
11488                                                        Complex tz;
11489                                                        double ox;
11490                                                        double oy;
11491                                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11492                                                        ox = (tz.getReal());
11493                                                        oy = (tz.getImaginary());
11494                                                        oc128data[it.oIndex] = ox;
11495                                                        oc128data[it.oIndex + 1] = oy;
11496                                                }
11497                                        } else {
11498                                                while (it.hasNext()) {
11499                                                        final double iax = it.aDouble;
11500                                                        final double ibx = it.bDouble;
11501                                                        final double iby = 0;
11502                                                        Complex tz;
11503                                                        double ox;
11504                                                        double oy;
11505                                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11506                                                        ox = (tz.getReal());
11507                                                        oy = (tz.getImaginary());
11508                                                        oc128data[it.oIndex] = ox;
11509                                                        oc128data[it.oIndex + 1] = oy;
11510                                                }
11511                                        }
11512                                } else {
11513                                        final long iay = 0;
11514                                        while (it.hasNext()) {
11515                                                final long iax = it.aLong;
11516                                                final long ibx = it.bLong;
11517                                                final long iby = 0;
11518                                                Complex tz;
11519                                                double ox;
11520                                                double oy;
11521                                                tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11522                                                ox = (tz.getReal());
11523                                                oy = (tz.getImaginary());
11524                                                oc128data[it.oIndex] = ox;
11525                                                oc128data[it.oIndex + 1] = oy;
11526                                        }
11527                                }
11528                        } else if (!db.isComplex()) {
11529                                final double iby = 0;
11530                                while (it.hasNext()) {
11531                                        final double iax = it.aDouble;
11532                                        final double ibx = it.bDouble;
11533                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
11534                                        Complex tz;
11535                                        double ox;
11536                                        double oy;
11537                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11538                                        ox = (tz.getReal());
11539                                        oy = (tz.getImaginary());
11540                                        oc128data[it.oIndex] = ox;
11541                                        oc128data[it.oIndex + 1] = oy;
11542                                }
11543                        } else {
11544                                while (it.hasNext()) {
11545                                        final double iax = it.aDouble;
11546                                        final double ibx = it.bDouble;
11547                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
11548                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
11549                                        Complex tz;
11550                                        double ox;
11551                                        double oy;
11552                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
11553                                        ox = (tz.getReal());
11554                                        oy = (tz.getImaginary());
11555                                        oc128data[it.oIndex] = ox;
11556                                        oc128data[it.oIndex + 1] = oy;
11557                                }
11558                        }
11559                        break;
11560                default:
11561                        throw new IllegalArgumentException("power supports integer, compound integer, real, compound real, complex datasets only");
11562                }
11563
11564                addBinaryOperatorName(da, db, result, "**");
11565                return result;
11566        }
11567
11568        /**
11569         * remainder operator
11570         * @param a first operand
11571         * @param b second operand
11572         * @return {@code a % b}, remainder of division of a by b
11573         */
11574        public static Dataset remainder(final Object a, final Object b) {
11575                return remainder(a, b, null);
11576        }
11577
11578        /**
11579         * remainder operator
11580         * @param a first operand
11581         * @param b second operand
11582         * @param o output can be null - in which case, a new dataset is created
11583         * @return {@code a % b}, remainder of division of a by b
11584         */
11585        public static Dataset remainder(final Object a, final Object b, final Dataset o) {
11586                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
11587                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
11588                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
11589                final Dataset result = it.getOutput();
11590                if (!result.isComplex()) {
11591                        boolean change = false;
11592                        if (da.isComplex()) {
11593                                da = da.getRealView();
11594                                change = true;
11595                        }
11596                        if (db.isComplex()) {
11597                                db = db.getRealView();
11598                                change = true;
11599                        }
11600                        if (change) {
11601                                it = BroadcastIterator.createIterator(da, db, result, true);
11602                        }
11603                }
11604                final int is = result.getElementsPerItem();
11605                final int as = da.getElementsPerItem();
11606                final int bs = db.getElementsPerItem();
11607                final int dt = result.getDType();
11608
11609                switch(dt) {
11610                case Dataset.INT8:
11611                        final byte[] oi8data = ((ByteDataset) result).getData();
11612                        if (it.isOutputDouble()) {
11613                                while (it.hasNext()) {
11614                                        final double iax = it.aDouble;
11615                                        final double ibx = it.bDouble;
11616                                        byte ox;
11617                                        ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
11618                                        oi8data[it.oIndex] = ox;
11619                                }
11620                        } else {
11621                                while (it.hasNext()) {
11622                                        final long iax = it.aLong;
11623                                        final long ibx = it.bLong;
11624                                        byte ox;
11625                                        ox = (byte) (ibx == 0 ? 0 : iax % ibx);
11626                                        oi8data[it.oIndex] = ox;
11627                                }
11628                        }
11629                        break;
11630                case Dataset.INT16:
11631                        final short[] oi16data = ((ShortDataset) result).getData();
11632                        if (it.isOutputDouble()) {
11633                                while (it.hasNext()) {
11634                                        final double iax = it.aDouble;
11635                                        final double ibx = it.bDouble;
11636                                        short ox;
11637                                        ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
11638                                        oi16data[it.oIndex] = ox;
11639                                }
11640                        } else {
11641                                while (it.hasNext()) {
11642                                        final long iax = it.aLong;
11643                                        final long ibx = it.bLong;
11644                                        short ox;
11645                                        ox = (short) (ibx == 0 ? 0 : iax % ibx);
11646                                        oi16data[it.oIndex] = ox;
11647                                }
11648                        }
11649                        break;
11650                case Dataset.INT64:
11651                        final long[] oi64data = ((LongDataset) result).getData();
11652                        if (it.isOutputDouble()) {
11653                                while (it.hasNext()) {
11654                                        final double iax = it.aDouble;
11655                                        final double ibx = it.bDouble;
11656                                        long ox;
11657                                        ox = toLong(ibx == 0 ? 0 : iax % ibx);
11658                                        oi64data[it.oIndex] = ox;
11659                                }
11660                        } else {
11661                                while (it.hasNext()) {
11662                                        final long iax = it.aLong;
11663                                        final long ibx = it.bLong;
11664                                        long ox;
11665                                        ox = (ibx == 0 ? 0 : iax % ibx);
11666                                        oi64data[it.oIndex] = ox;
11667                                }
11668                        }
11669                        break;
11670                case Dataset.INT32:
11671                        final int[] oi32data = ((IntegerDataset) result).getData();
11672                        if (it.isOutputDouble()) {
11673                                while (it.hasNext()) {
11674                                        final double iax = it.aDouble;
11675                                        final double ibx = it.bDouble;
11676                                        int ox;
11677                                        ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
11678                                        oi32data[it.oIndex] = ox;
11679                                }
11680                        } else {
11681                                while (it.hasNext()) {
11682                                        final long iax = it.aLong;
11683                                        final long ibx = it.bLong;
11684                                        int ox;
11685                                        ox = (int) (ibx == 0 ? 0 : iax % ibx);
11686                                        oi32data[it.oIndex] = ox;
11687                                }
11688                        }
11689                        break;
11690                case Dataset.ARRAYINT8:
11691                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
11692                        if (is == 1) {
11693                                if (it.isOutputDouble()) {
11694                                        while (it.hasNext()) {
11695                                                final double iax = it.aDouble;
11696                                                final double ibx = it.bDouble;
11697                                                byte ox;
11698                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
11699                                                oai8data[it.oIndex] = ox;
11700                                        }
11701                                } else {
11702                                        while (it.hasNext()) {
11703                                                final long iax = it.aLong;
11704                                                final long ibx = it.bLong;
11705                                                byte ox;
11706                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
11707                                                oai8data[it.oIndex] = ox;
11708                                        }
11709                                }
11710                        } else if (as < bs) {
11711                                if (it.isOutputDouble()) {
11712                                        while (it.hasNext()) {
11713                                                final double iax = it.aDouble;
11714                                                double ibx = it.bDouble;
11715                                                byte ox;
11716                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
11717                                                oai8data[it.oIndex] = ox;
11718                                                for (int j = 1; j < is; j++) {
11719                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11720                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
11721                                                        oai8data[it.oIndex + j] = ox;
11722                                                }
11723                                        }
11724                                } else {
11725                                        while (it.hasNext()) {
11726                                                final long iax = it.aLong;
11727                                                long ibx = it.bLong;
11728                                                byte ox;
11729                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
11730                                                oai8data[it.oIndex] = ox;
11731                                                for (int j = 1; j < is; j++) {
11732                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11733                                                        ox = (byte) (ibx == 0 ? 0 : iax % ibx);
11734                                                        oai8data[it.oIndex + j] = ox;
11735                                                }
11736                                        }
11737                                }
11738                        } else if (as > bs) {
11739                                if (it.isOutputDouble()) {
11740                                        while (it.hasNext()) {
11741                                                double iax = it.aDouble;
11742                                                final double ibx = it.bDouble;
11743                                                byte ox;
11744                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
11745                                                oai8data[it.oIndex] = ox;
11746                                                for (int j = 1; j < is; j++) {
11747                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11748                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
11749                                                        oai8data[it.oIndex + j] = ox;
11750                                                }
11751                                        }
11752                                } else {
11753                                        while (it.hasNext()) {
11754                                                long iax = it.aLong;
11755                                                final long ibx = it.bLong;
11756                                                byte ox;
11757                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
11758                                                oai8data[it.oIndex] = ox;
11759                                                for (int j = 1; j < is; j++) {
11760                                                        iax = da.getElementLongAbs(it.aIndex + j);
11761                                                        ox = (byte) (ibx == 0 ? 0 : iax % ibx);
11762                                                        oai8data[it.oIndex + j] = ox;
11763                                                }
11764                                        }
11765                                }
11766                        } else if (as == 1) {
11767                                if (it.isOutputDouble()) {
11768                                        while (it.hasNext()) {
11769                                                final double iax = it.aDouble;
11770                                                final double ibx = it.bDouble;
11771                                                byte ox;
11772                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
11773                                                for (int j = 0; j < is; j++) {
11774                                                        oai8data[it.oIndex + j] = ox;
11775                                                }
11776                                        }
11777                                } else {
11778                                        while (it.hasNext()) {
11779                                                final long iax = it.aLong;
11780                                                final long ibx = it.bLong;
11781                                                byte ox;
11782                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
11783                                                for (int j = 0; j < is; j++) {
11784                                                        oai8data[it.oIndex + j] = ox;
11785                                                }
11786                                        }
11787                                }
11788                        } else {
11789                                if (it.isOutputDouble()) {
11790                                        while (it.hasNext()) {
11791                                                double iax = it.aDouble;
11792                                                double ibx = it.bDouble;
11793                                                byte ox;
11794                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
11795                                                oai8data[it.oIndex] = ox;
11796                                                for (int j = 1; j < is; j++) {
11797                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11798                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11799                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
11800                                                        oai8data[it.oIndex + j] = ox;
11801                                                }
11802                                        }
11803                                } else {
11804                                        while (it.hasNext()) {
11805                                                long iax = it.aLong;
11806                                                long ibx = it.bLong;
11807                                                byte ox;
11808                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
11809                                                oai8data[it.oIndex] = ox;
11810                                                for (int j = 1; j < is; j++) {
11811                                                        iax = da.getElementLongAbs(it.aIndex + j);
11812                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11813                                                        ox = (byte) (ibx == 0 ? 0 : iax % ibx);
11814                                                        oai8data[it.oIndex + j] = ox;
11815                                                }
11816                                        }
11817                                }
11818                        }
11819                        break;
11820                case Dataset.ARRAYINT16:
11821                        final short[] oai16data = ((CompoundShortDataset) result).getData();
11822                        if (is == 1) {
11823                                if (it.isOutputDouble()) {
11824                                        while (it.hasNext()) {
11825                                                final double iax = it.aDouble;
11826                                                final double ibx = it.bDouble;
11827                                                short ox;
11828                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
11829                                                oai16data[it.oIndex] = ox;
11830                                        }
11831                                } else {
11832                                        while (it.hasNext()) {
11833                                                final long iax = it.aLong;
11834                                                final long ibx = it.bLong;
11835                                                short ox;
11836                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
11837                                                oai16data[it.oIndex] = ox;
11838                                        }
11839                                }
11840                        } else if (as < bs) {
11841                                if (it.isOutputDouble()) {
11842                                        while (it.hasNext()) {
11843                                                final double iax = it.aDouble;
11844                                                double ibx = it.bDouble;
11845                                                short ox;
11846                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
11847                                                oai16data[it.oIndex] = ox;
11848                                                for (int j = 1; j < is; j++) {
11849                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11850                                                        ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
11851                                                        oai16data[it.oIndex + j] = ox;
11852                                                }
11853                                        }
11854                                } else {
11855                                        while (it.hasNext()) {
11856                                                final long iax = it.aLong;
11857                                                long ibx = it.bLong;
11858                                                short ox;
11859                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
11860                                                oai16data[it.oIndex] = ox;
11861                                                for (int j = 1; j < is; j++) {
11862                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11863                                                        ox = (short) (ibx == 0 ? 0 : iax % ibx);
11864                                                        oai16data[it.oIndex + j] = ox;
11865                                                }
11866                                        }
11867                                }
11868                        } else if (as > bs) {
11869                                if (it.isOutputDouble()) {
11870                                        while (it.hasNext()) {
11871                                                double iax = it.aDouble;
11872                                                final double ibx = it.bDouble;
11873                                                short ox;
11874                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
11875                                                oai16data[it.oIndex] = ox;
11876                                                for (int j = 1; j < is; j++) {
11877                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11878                                                        ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
11879                                                        oai16data[it.oIndex + j] = ox;
11880                                                }
11881                                        }
11882                                } else {
11883                                        while (it.hasNext()) {
11884                                                long iax = it.aLong;
11885                                                final long ibx = it.bLong;
11886                                                short ox;
11887                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
11888                                                oai16data[it.oIndex] = ox;
11889                                                for (int j = 1; j < is; j++) {
11890                                                        iax = da.getElementLongAbs(it.aIndex + j);
11891                                                        ox = (short) (ibx == 0 ? 0 : iax % ibx);
11892                                                        oai16data[it.oIndex + j] = ox;
11893                                                }
11894                                        }
11895                                }
11896                        } else if (as == 1) {
11897                                if (it.isOutputDouble()) {
11898                                        while (it.hasNext()) {
11899                                                final double iax = it.aDouble;
11900                                                final double ibx = it.bDouble;
11901                                                short ox;
11902                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
11903                                                for (int j = 0; j < is; j++) {
11904                                                        oai16data[it.oIndex + j] = ox;
11905                                                }
11906                                        }
11907                                } else {
11908                                        while (it.hasNext()) {
11909                                                final long iax = it.aLong;
11910                                                final long ibx = it.bLong;
11911                                                short ox;
11912                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
11913                                                for (int j = 0; j < is; j++) {
11914                                                        oai16data[it.oIndex + j] = ox;
11915                                                }
11916                                        }
11917                                }
11918                        } else {
11919                                if (it.isOutputDouble()) {
11920                                        while (it.hasNext()) {
11921                                                double iax = it.aDouble;
11922                                                double ibx = it.bDouble;
11923                                                short ox;
11924                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
11925                                                oai16data[it.oIndex] = ox;
11926                                                for (int j = 1; j < is; j++) {
11927                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
11928                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11929                                                        ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
11930                                                        oai16data[it.oIndex + j] = ox;
11931                                                }
11932                                        }
11933                                } else {
11934                                        while (it.hasNext()) {
11935                                                long iax = it.aLong;
11936                                                long ibx = it.bLong;
11937                                                short ox;
11938                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
11939                                                oai16data[it.oIndex] = ox;
11940                                                for (int j = 1; j < is; j++) {
11941                                                        iax = da.getElementLongAbs(it.aIndex + j);
11942                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11943                                                        ox = (short) (ibx == 0 ? 0 : iax % ibx);
11944                                                        oai16data[it.oIndex + j] = ox;
11945                                                }
11946                                        }
11947                                }
11948                        }
11949                        break;
11950                case Dataset.ARRAYINT64:
11951                        final long[] oai64data = ((CompoundLongDataset) result).getData();
11952                        if (is == 1) {
11953                                if (it.isOutputDouble()) {
11954                                        while (it.hasNext()) {
11955                                                final double iax = it.aDouble;
11956                                                final double ibx = it.bDouble;
11957                                                long ox;
11958                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
11959                                                oai64data[it.oIndex] = ox;
11960                                        }
11961                                } else {
11962                                        while (it.hasNext()) {
11963                                                final long iax = it.aLong;
11964                                                final long ibx = it.bLong;
11965                                                long ox;
11966                                                ox = (ibx == 0 ? 0 : iax % ibx);
11967                                                oai64data[it.oIndex] = ox;
11968                                        }
11969                                }
11970                        } else if (as < bs) {
11971                                if (it.isOutputDouble()) {
11972                                        while (it.hasNext()) {
11973                                                final double iax = it.aDouble;
11974                                                double ibx = it.bDouble;
11975                                                long ox;
11976                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
11977                                                oai64data[it.oIndex] = ox;
11978                                                for (int j = 1; j < is; j++) {
11979                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
11980                                                        ox = toLong(ibx == 0 ? 0 : iax % ibx);
11981                                                        oai64data[it.oIndex + j] = ox;
11982                                                }
11983                                        }
11984                                } else {
11985                                        while (it.hasNext()) {
11986                                                final long iax = it.aLong;
11987                                                long ibx = it.bLong;
11988                                                long ox;
11989                                                ox = (ibx == 0 ? 0 : iax % ibx);
11990                                                oai64data[it.oIndex] = ox;
11991                                                for (int j = 1; j < is; j++) {
11992                                                        ibx = db.getElementLongAbs(it.bIndex + j);
11993                                                        ox = (ibx == 0 ? 0 : iax % ibx);
11994                                                        oai64data[it.oIndex + j] = ox;
11995                                                }
11996                                        }
11997                                }
11998                        } else if (as > bs) {
11999                                if (it.isOutputDouble()) {
12000                                        while (it.hasNext()) {
12001                                                double iax = it.aDouble;
12002                                                final double ibx = it.bDouble;
12003                                                long ox;
12004                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
12005                                                oai64data[it.oIndex] = ox;
12006                                                for (int j = 1; j < is; j++) {
12007                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12008                                                        ox = toLong(ibx == 0 ? 0 : iax % ibx);
12009                                                        oai64data[it.oIndex + j] = ox;
12010                                                }
12011                                        }
12012                                } else {
12013                                        while (it.hasNext()) {
12014                                                long iax = it.aLong;
12015                                                final long ibx = it.bLong;
12016                                                long ox;
12017                                                ox = (ibx == 0 ? 0 : iax % ibx);
12018                                                oai64data[it.oIndex] = ox;
12019                                                for (int j = 1; j < is; j++) {
12020                                                        iax = da.getElementLongAbs(it.aIndex + j);
12021                                                        ox = (ibx == 0 ? 0 : iax % ibx);
12022                                                        oai64data[it.oIndex + j] = ox;
12023                                                }
12024                                        }
12025                                }
12026                        } else if (as == 1) {
12027                                if (it.isOutputDouble()) {
12028                                        while (it.hasNext()) {
12029                                                final double iax = it.aDouble;
12030                                                final double ibx = it.bDouble;
12031                                                long ox;
12032                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
12033                                                for (int j = 0; j < is; j++) {
12034                                                        oai64data[it.oIndex + j] = ox;
12035                                                }
12036                                        }
12037                                } else {
12038                                        while (it.hasNext()) {
12039                                                final long iax = it.aLong;
12040                                                final long ibx = it.bLong;
12041                                                long ox;
12042                                                ox = (ibx == 0 ? 0 : iax % ibx);
12043                                                for (int j = 0; j < is; j++) {
12044                                                        oai64data[it.oIndex + j] = ox;
12045                                                }
12046                                        }
12047                                }
12048                        } else {
12049                                if (it.isOutputDouble()) {
12050                                        while (it.hasNext()) {
12051                                                double iax = it.aDouble;
12052                                                double ibx = it.bDouble;
12053                                                long ox;
12054                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
12055                                                oai64data[it.oIndex] = ox;
12056                                                for (int j = 1; j < is; j++) {
12057                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12058                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12059                                                        ox = toLong(ibx == 0 ? 0 : iax % ibx);
12060                                                        oai64data[it.oIndex + j] = ox;
12061                                                }
12062                                        }
12063                                } else {
12064                                        while (it.hasNext()) {
12065                                                long iax = it.aLong;
12066                                                long ibx = it.bLong;
12067                                                long ox;
12068                                                ox = (ibx == 0 ? 0 : iax % ibx);
12069                                                oai64data[it.oIndex] = ox;
12070                                                for (int j = 1; j < is; j++) {
12071                                                        iax = da.getElementLongAbs(it.aIndex + j);
12072                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12073                                                        ox = (ibx == 0 ? 0 : iax % ibx);
12074                                                        oai64data[it.oIndex + j] = ox;
12075                                                }
12076                                        }
12077                                }
12078                        }
12079                        break;
12080                case Dataset.ARRAYINT32:
12081                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
12082                        if (is == 1) {
12083                                if (it.isOutputDouble()) {
12084                                        while (it.hasNext()) {
12085                                                final double iax = it.aDouble;
12086                                                final double ibx = it.bDouble;
12087                                                int ox;
12088                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12089                                                oai32data[it.oIndex] = ox;
12090                                        }
12091                                } else {
12092                                        while (it.hasNext()) {
12093                                                final long iax = it.aLong;
12094                                                final long ibx = it.bLong;
12095                                                int ox;
12096                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
12097                                                oai32data[it.oIndex] = ox;
12098                                        }
12099                                }
12100                        } else if (as < bs) {
12101                                if (it.isOutputDouble()) {
12102                                        while (it.hasNext()) {
12103                                                final double iax = it.aDouble;
12104                                                double ibx = it.bDouble;
12105                                                int ox;
12106                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12107                                                oai32data[it.oIndex] = ox;
12108                                                for (int j = 1; j < is; j++) {
12109                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12110                                                        ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12111                                                        oai32data[it.oIndex + j] = ox;
12112                                                }
12113                                        }
12114                                } else {
12115                                        while (it.hasNext()) {
12116                                                final long iax = it.aLong;
12117                                                long ibx = it.bLong;
12118                                                int ox;
12119                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
12120                                                oai32data[it.oIndex] = ox;
12121                                                for (int j = 1; j < is; j++) {
12122                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12123                                                        ox = (int) (ibx == 0 ? 0 : iax % ibx);
12124                                                        oai32data[it.oIndex + j] = ox;
12125                                                }
12126                                        }
12127                                }
12128                        } else if (as > bs) {
12129                                if (it.isOutputDouble()) {
12130                                        while (it.hasNext()) {
12131                                                double iax = it.aDouble;
12132                                                final double ibx = it.bDouble;
12133                                                int ox;
12134                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12135                                                oai32data[it.oIndex] = ox;
12136                                                for (int j = 1; j < is; j++) {
12137                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12138                                                        ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12139                                                        oai32data[it.oIndex + j] = ox;
12140                                                }
12141                                        }
12142                                } else {
12143                                        while (it.hasNext()) {
12144                                                long iax = it.aLong;
12145                                                final long ibx = it.bLong;
12146                                                int ox;
12147                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
12148                                                oai32data[it.oIndex] = ox;
12149                                                for (int j = 1; j < is; j++) {
12150                                                        iax = da.getElementLongAbs(it.aIndex + j);
12151                                                        ox = (int) (ibx == 0 ? 0 : iax % ibx);
12152                                                        oai32data[it.oIndex + j] = ox;
12153                                                }
12154                                        }
12155                                }
12156                        } else if (as == 1) {
12157                                if (it.isOutputDouble()) {
12158                                        while (it.hasNext()) {
12159                                                final double iax = it.aDouble;
12160                                                final double ibx = it.bDouble;
12161                                                int ox;
12162                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12163                                                for (int j = 0; j < is; j++) {
12164                                                        oai32data[it.oIndex + j] = ox;
12165                                                }
12166                                        }
12167                                } else {
12168                                        while (it.hasNext()) {
12169                                                final long iax = it.aLong;
12170                                                final long ibx = it.bLong;
12171                                                int ox;
12172                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
12173                                                for (int j = 0; j < is; j++) {
12174                                                        oai32data[it.oIndex + j] = ox;
12175                                                }
12176                                        }
12177                                }
12178                        } else {
12179                                if (it.isOutputDouble()) {
12180                                        while (it.hasNext()) {
12181                                                double iax = it.aDouble;
12182                                                double ibx = it.bDouble;
12183                                                int ox;
12184                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12185                                                oai32data[it.oIndex] = ox;
12186                                                for (int j = 1; j < is; j++) {
12187                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12188                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12189                                                        ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
12190                                                        oai32data[it.oIndex + j] = ox;
12191                                                }
12192                                        }
12193                                } else {
12194                                        while (it.hasNext()) {
12195                                                long iax = it.aLong;
12196                                                long ibx = it.bLong;
12197                                                int ox;
12198                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
12199                                                oai32data[it.oIndex] = ox;
12200                                                for (int j = 1; j < is; j++) {
12201                                                        iax = da.getElementLongAbs(it.aIndex + j);
12202                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12203                                                        ox = (int) (ibx == 0 ? 0 : iax % ibx);
12204                                                        oai32data[it.oIndex + j] = ox;
12205                                                }
12206                                        }
12207                                }
12208                        }
12209                        break;
12210                case Dataset.FLOAT32:
12211                        final float[] of32data = ((FloatDataset) result).getData();
12212                        if (it.isOutputDouble()) {
12213                                while (it.hasNext()) {
12214                                        final double iax = it.aDouble;
12215                                        final double ibx = it.bDouble;
12216                                        float ox;
12217                                        ox = (float) (iax % ibx);
12218                                        of32data[it.oIndex] = ox;
12219                                }
12220                        } else {
12221                                while (it.hasNext()) {
12222                                        final long iax = it.aLong;
12223                                        final long ibx = it.bLong;
12224                                        float ox;
12225                                        ox = (iax % ibx);
12226                                        of32data[it.oIndex] = ox;
12227                                }
12228                        }
12229                        break;
12230                case Dataset.FLOAT64:
12231                        final double[] of64data = ((DoubleDataset) result).getData();
12232                        if (it.isOutputDouble()) {
12233                                while (it.hasNext()) {
12234                                        final double iax = it.aDouble;
12235                                        final double ibx = it.bDouble;
12236                                        double ox;
12237                                        ox = (iax % ibx);
12238                                        of64data[it.oIndex] = ox;
12239                                }
12240                        } else {
12241                                while (it.hasNext()) {
12242                                        final long iax = it.aLong;
12243                                        final long ibx = it.bLong;
12244                                        double ox;
12245                                        ox = (iax % ibx);
12246                                        of64data[it.oIndex] = ox;
12247                                }
12248                        }
12249                        break;
12250                case Dataset.ARRAYFLOAT32:
12251                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
12252                        if (is == 1) {
12253                                if (it.isOutputDouble()) {
12254                                        while (it.hasNext()) {
12255                                                final double iax = it.aDouble;
12256                                                final double ibx = it.bDouble;
12257                                                float ox;
12258                                                ox = (float) (iax % ibx);
12259                                                oaf32data[it.oIndex] = ox;
12260                                        }
12261                                } else {
12262                                        while (it.hasNext()) {
12263                                                final long iax = it.aLong;
12264                                                final long ibx = it.bLong;
12265                                                float ox;
12266                                                ox = (iax % ibx);
12267                                                oaf32data[it.oIndex] = ox;
12268                                        }
12269                                }
12270                        } else if (as < bs) {
12271                                if (it.isOutputDouble()) {
12272                                        while (it.hasNext()) {
12273                                                final double iax = it.aDouble;
12274                                                double ibx = it.bDouble;
12275                                                float ox;
12276                                                ox = (float) (iax % ibx);
12277                                                oaf32data[it.oIndex] = ox;
12278                                                for (int j = 1; j < is; j++) {
12279                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12280                                                        ox = (float) (iax % ibx);
12281                                                        oaf32data[it.oIndex + j] = ox;
12282                                                }
12283                                        }
12284                                } else {
12285                                        while (it.hasNext()) {
12286                                                final long iax = it.aLong;
12287                                                long ibx = it.bLong;
12288                                                float ox;
12289                                                ox = (iax % ibx);
12290                                                oaf32data[it.oIndex] = ox;
12291                                                for (int j = 1; j < is; j++) {
12292                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12293                                                        ox = (iax % ibx);
12294                                                        oaf32data[it.oIndex + j] = ox;
12295                                                }
12296                                        }
12297                                }
12298                        } else if (as > bs) {
12299                                if (it.isOutputDouble()) {
12300                                        while (it.hasNext()) {
12301                                                double iax = it.aDouble;
12302                                                final double ibx = it.bDouble;
12303                                                float ox;
12304                                                ox = (float) (iax % ibx);
12305                                                oaf32data[it.oIndex] = ox;
12306                                                for (int j = 1; j < is; j++) {
12307                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12308                                                        ox = (float) (iax % ibx);
12309                                                        oaf32data[it.oIndex + j] = ox;
12310                                                }
12311                                        }
12312                                } else {
12313                                        while (it.hasNext()) {
12314                                                long iax = it.aLong;
12315                                                final long ibx = it.bLong;
12316                                                float ox;
12317                                                ox = (iax % ibx);
12318                                                oaf32data[it.oIndex] = ox;
12319                                                for (int j = 1; j < is; j++) {
12320                                                        iax = da.getElementLongAbs(it.aIndex + j);
12321                                                        ox = (iax % ibx);
12322                                                        oaf32data[it.oIndex + j] = ox;
12323                                                }
12324                                        }
12325                                }
12326                        } else if (as == 1) {
12327                                if (it.isOutputDouble()) {
12328                                        while (it.hasNext()) {
12329                                                final double iax = it.aDouble;
12330                                                final double ibx = it.bDouble;
12331                                                float ox;
12332                                                ox = (float) (iax % ibx);
12333                                                for (int j = 0; j < is; j++) {
12334                                                        oaf32data[it.oIndex + j] = ox;
12335                                                }
12336                                        }
12337                                } else {
12338                                        while (it.hasNext()) {
12339                                                final long iax = it.aLong;
12340                                                final long ibx = it.bLong;
12341                                                float ox;
12342                                                ox = (iax % ibx);
12343                                                for (int j = 0; j < is; j++) {
12344                                                        oaf32data[it.oIndex + j] = ox;
12345                                                }
12346                                        }
12347                                }
12348                        } else {
12349                                if (it.isOutputDouble()) {
12350                                        while (it.hasNext()) {
12351                                                double iax = it.aDouble;
12352                                                double ibx = it.bDouble;
12353                                                float ox;
12354                                                ox = (float) (iax % ibx);
12355                                                oaf32data[it.oIndex] = ox;
12356                                                for (int j = 1; j < is; j++) {
12357                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12358                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12359                                                        ox = (float) (iax % ibx);
12360                                                        oaf32data[it.oIndex + j] = ox;
12361                                                }
12362                                        }
12363                                } else {
12364                                        while (it.hasNext()) {
12365                                                long iax = it.aLong;
12366                                                long ibx = it.bLong;
12367                                                float ox;
12368                                                ox = (iax % ibx);
12369                                                oaf32data[it.oIndex] = ox;
12370                                                for (int j = 1; j < is; j++) {
12371                                                        iax = da.getElementLongAbs(it.aIndex + j);
12372                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12373                                                        ox = (iax % ibx);
12374                                                        oaf32data[it.oIndex + j] = ox;
12375                                                }
12376                                        }
12377                                }
12378                        }
12379                        break;
12380                case Dataset.ARRAYFLOAT64:
12381                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
12382                        if (is == 1) {
12383                                if (it.isOutputDouble()) {
12384                                        while (it.hasNext()) {
12385                                                final double iax = it.aDouble;
12386                                                final double ibx = it.bDouble;
12387                                                double ox;
12388                                                ox = (iax % ibx);
12389                                                oaf64data[it.oIndex] = ox;
12390                                        }
12391                                } else {
12392                                        while (it.hasNext()) {
12393                                                final long iax = it.aLong;
12394                                                final long ibx = it.bLong;
12395                                                double ox;
12396                                                ox = (iax % ibx);
12397                                                oaf64data[it.oIndex] = ox;
12398                                        }
12399                                }
12400                        } else if (as < bs) {
12401                                if (it.isOutputDouble()) {
12402                                        while (it.hasNext()) {
12403                                                final double iax = it.aDouble;
12404                                                double ibx = it.bDouble;
12405                                                double ox;
12406                                                ox = (iax % ibx);
12407                                                oaf64data[it.oIndex] = ox;
12408                                                for (int j = 1; j < is; j++) {
12409                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12410                                                        ox = (iax % ibx);
12411                                                        oaf64data[it.oIndex + j] = ox;
12412                                                }
12413                                        }
12414                                } else {
12415                                        while (it.hasNext()) {
12416                                                final long iax = it.aLong;
12417                                                long ibx = it.bLong;
12418                                                double ox;
12419                                                ox = (iax % ibx);
12420                                                oaf64data[it.oIndex] = ox;
12421                                                for (int j = 1; j < is; j++) {
12422                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12423                                                        ox = (iax % ibx);
12424                                                        oaf64data[it.oIndex + j] = ox;
12425                                                }
12426                                        }
12427                                }
12428                        } else if (as > bs) {
12429                                if (it.isOutputDouble()) {
12430                                        while (it.hasNext()) {
12431                                                double iax = it.aDouble;
12432                                                final double ibx = it.bDouble;
12433                                                double ox;
12434                                                ox = (iax % ibx);
12435                                                oaf64data[it.oIndex] = ox;
12436                                                for (int j = 1; j < is; j++) {
12437                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12438                                                        ox = (iax % ibx);
12439                                                        oaf64data[it.oIndex + j] = ox;
12440                                                }
12441                                        }
12442                                } else {
12443                                        while (it.hasNext()) {
12444                                                long iax = it.aLong;
12445                                                final long ibx = it.bLong;
12446                                                double ox;
12447                                                ox = (iax % ibx);
12448                                                oaf64data[it.oIndex] = ox;
12449                                                for (int j = 1; j < is; j++) {
12450                                                        iax = da.getElementLongAbs(it.aIndex + j);
12451                                                        ox = (iax % ibx);
12452                                                        oaf64data[it.oIndex + j] = ox;
12453                                                }
12454                                        }
12455                                }
12456                        } else if (as == 1) {
12457                                if (it.isOutputDouble()) {
12458                                        while (it.hasNext()) {
12459                                                final double iax = it.aDouble;
12460                                                final double ibx = it.bDouble;
12461                                                double ox;
12462                                                ox = (iax % ibx);
12463                                                for (int j = 0; j < is; j++) {
12464                                                        oaf64data[it.oIndex + j] = ox;
12465                                                }
12466                                        }
12467                                } else {
12468                                        while (it.hasNext()) {
12469                                                final long iax = it.aLong;
12470                                                final long ibx = it.bLong;
12471                                                double ox;
12472                                                ox = (iax % ibx);
12473                                                for (int j = 0; j < is; j++) {
12474                                                        oaf64data[it.oIndex + j] = ox;
12475                                                }
12476                                        }
12477                                }
12478                        } else {
12479                                if (it.isOutputDouble()) {
12480                                        while (it.hasNext()) {
12481                                                double iax = it.aDouble;
12482                                                double ibx = it.bDouble;
12483                                                double ox;
12484                                                ox = (iax % ibx);
12485                                                oaf64data[it.oIndex] = ox;
12486                                                for (int j = 1; j < is; j++) {
12487                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12488                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12489                                                        ox = (iax % ibx);
12490                                                        oaf64data[it.oIndex + j] = ox;
12491                                                }
12492                                        }
12493                                } else {
12494                                        while (it.hasNext()) {
12495                                                long iax = it.aLong;
12496                                                long ibx = it.bLong;
12497                                                double ox;
12498                                                ox = (iax % ibx);
12499                                                oaf64data[it.oIndex] = ox;
12500                                                for (int j = 1; j < is; j++) {
12501                                                        iax = da.getElementLongAbs(it.aIndex + j);
12502                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12503                                                        ox = (iax % ibx);
12504                                                        oaf64data[it.oIndex + j] = ox;
12505                                                }
12506                                        }
12507                                }
12508                        }
12509                        break;
12510                default:
12511                        throw new IllegalArgumentException("remainder supports integer, compound integer, real, compound real datasets only");
12512                }
12513
12514                addBinaryOperatorName(da, db, result, "%");
12515                return result;
12516        }
12517
12518        /**
12519         * maximum operator
12520         * @param a first operand
12521         * @param b second operand
12522         * @return return maximum of a and b
12523         */
12524        public static Dataset maximum(final Object a, final Object b) {
12525                return maximum(a, b, null);
12526        }
12527
12528        /**
12529         * maximum operator
12530         * @param a first operand
12531         * @param b second operand
12532         * @param o output can be null - in which case, a new dataset is created
12533         * @return return maximum of a and b
12534         */
12535        public static Dataset maximum(final Object a, final Object b, final Dataset o) {
12536                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
12537                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
12538                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
12539                final Dataset result = it.getOutput();
12540                if (!result.isComplex()) {
12541                        boolean change = false;
12542                        if (da.isComplex()) {
12543                                da = da.getRealView();
12544                                change = true;
12545                        }
12546                        if (db.isComplex()) {
12547                                db = db.getRealView();
12548                                change = true;
12549                        }
12550                        if (change) {
12551                                it = BroadcastIterator.createIterator(da, db, result, true);
12552                        }
12553                }
12554                final int is = result.getElementsPerItem();
12555                final int as = da.getElementsPerItem();
12556                final int bs = db.getElementsPerItem();
12557                final int dt = result.getDType();
12558
12559                switch(dt) {
12560                case Dataset.INT8:
12561                        final byte[] oi8data = ((ByteDataset) result).getData();
12562                        if (it.isOutputDouble()) {
12563                                while (it.hasNext()) {
12564                                        final double iax = it.aDouble;
12565                                        final double ibx = it.bDouble;
12566                                        byte ox;
12567                                        ox = (byte) toLong(Math.max(iax, ibx));
12568                                        oi8data[it.oIndex] = ox;
12569                                }
12570                        } else {
12571                                while (it.hasNext()) {
12572                                        final long iax = it.aLong;
12573                                        final long ibx = it.bLong;
12574                                        byte ox;
12575                                        ox = (byte) toLong(Math.max(iax, ibx));
12576                                        oi8data[it.oIndex] = ox;
12577                                }
12578                        }
12579                        break;
12580                case Dataset.INT16:
12581                        final short[] oi16data = ((ShortDataset) result).getData();
12582                        if (it.isOutputDouble()) {
12583                                while (it.hasNext()) {
12584                                        final double iax = it.aDouble;
12585                                        final double ibx = it.bDouble;
12586                                        short ox;
12587                                        ox = (short) toLong(Math.max(iax, ibx));
12588                                        oi16data[it.oIndex] = ox;
12589                                }
12590                        } else {
12591                                while (it.hasNext()) {
12592                                        final long iax = it.aLong;
12593                                        final long ibx = it.bLong;
12594                                        short ox;
12595                                        ox = (short) toLong(Math.max(iax, ibx));
12596                                        oi16data[it.oIndex] = ox;
12597                                }
12598                        }
12599                        break;
12600                case Dataset.INT64:
12601                        final long[] oi64data = ((LongDataset) result).getData();
12602                        if (it.isOutputDouble()) {
12603                                while (it.hasNext()) {
12604                                        final double iax = it.aDouble;
12605                                        final double ibx = it.bDouble;
12606                                        long ox;
12607                                        ox = toLong(Math.max(iax, ibx));
12608                                        oi64data[it.oIndex] = ox;
12609                                }
12610                        } else {
12611                                while (it.hasNext()) {
12612                                        final long iax = it.aLong;
12613                                        final long ibx = it.bLong;
12614                                        long ox;
12615                                        ox = toLong(Math.max(iax, ibx));
12616                                        oi64data[it.oIndex] = ox;
12617                                }
12618                        }
12619                        break;
12620                case Dataset.INT32:
12621                        final int[] oi32data = ((IntegerDataset) result).getData();
12622                        if (it.isOutputDouble()) {
12623                                while (it.hasNext()) {
12624                                        final double iax = it.aDouble;
12625                                        final double ibx = it.bDouble;
12626                                        int ox;
12627                                        ox = (int) toLong(Math.max(iax, ibx));
12628                                        oi32data[it.oIndex] = ox;
12629                                }
12630                        } else {
12631                                while (it.hasNext()) {
12632                                        final long iax = it.aLong;
12633                                        final long ibx = it.bLong;
12634                                        int ox;
12635                                        ox = (int) toLong(Math.max(iax, ibx));
12636                                        oi32data[it.oIndex] = ox;
12637                                }
12638                        }
12639                        break;
12640                case Dataset.ARRAYINT8:
12641                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
12642                        if (is == 1) {
12643                                if (it.isOutputDouble()) {
12644                                        while (it.hasNext()) {
12645                                                final double iax = it.aDouble;
12646                                                final double ibx = it.bDouble;
12647                                                byte ox;
12648                                                ox = (byte) toLong(Math.max(iax, ibx));
12649                                                oai8data[it.oIndex] = ox;
12650                                        }
12651                                } else {
12652                                        while (it.hasNext()) {
12653                                                final long iax = it.aLong;
12654                                                final long ibx = it.bLong;
12655                                                byte ox;
12656                                                ox = (byte) toLong(Math.max(iax, ibx));
12657                                                oai8data[it.oIndex] = ox;
12658                                        }
12659                                }
12660                        } else if (as < bs) {
12661                                if (it.isOutputDouble()) {
12662                                        while (it.hasNext()) {
12663                                                final double iax = it.aDouble;
12664                                                double ibx = it.bDouble;
12665                                                byte ox;
12666                                                ox = (byte) toLong(Math.max(iax, ibx));
12667                                                oai8data[it.oIndex] = ox;
12668                                                for (int j = 1; j < is; j++) {
12669                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12670                                                        ox = (byte) toLong(Math.max(iax, ibx));
12671                                                        oai8data[it.oIndex + j] = ox;
12672                                                }
12673                                        }
12674                                } else {
12675                                        while (it.hasNext()) {
12676                                                final long iax = it.aLong;
12677                                                long ibx = it.bLong;
12678                                                byte ox;
12679                                                ox = (byte) toLong(Math.max(iax, ibx));
12680                                                oai8data[it.oIndex] = ox;
12681                                                for (int j = 1; j < is; j++) {
12682                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12683                                                        ox = (byte) toLong(Math.max(iax, ibx));
12684                                                        oai8data[it.oIndex + j] = ox;
12685                                                }
12686                                        }
12687                                }
12688                        } else if (as > bs) {
12689                                if (it.isOutputDouble()) {
12690                                        while (it.hasNext()) {
12691                                                double iax = it.aDouble;
12692                                                final double ibx = it.bDouble;
12693                                                byte ox;
12694                                                ox = (byte) toLong(Math.max(iax, ibx));
12695                                                oai8data[it.oIndex] = ox;
12696                                                for (int j = 1; j < is; j++) {
12697                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12698                                                        ox = (byte) toLong(Math.max(iax, ibx));
12699                                                        oai8data[it.oIndex + j] = ox;
12700                                                }
12701                                        }
12702                                } else {
12703                                        while (it.hasNext()) {
12704                                                long iax = it.aLong;
12705                                                final long ibx = it.bLong;
12706                                                byte ox;
12707                                                ox = (byte) toLong(Math.max(iax, ibx));
12708                                                oai8data[it.oIndex] = ox;
12709                                                for (int j = 1; j < is; j++) {
12710                                                        iax = da.getElementLongAbs(it.aIndex + j);
12711                                                        ox = (byte) toLong(Math.max(iax, ibx));
12712                                                        oai8data[it.oIndex + j] = ox;
12713                                                }
12714                                        }
12715                                }
12716                        } else if (as == 1) {
12717                                if (it.isOutputDouble()) {
12718                                        while (it.hasNext()) {
12719                                                final double iax = it.aDouble;
12720                                                final double ibx = it.bDouble;
12721                                                byte ox;
12722                                                ox = (byte) toLong(Math.max(iax, ibx));
12723                                                for (int j = 0; j < is; j++) {
12724                                                        oai8data[it.oIndex + j] = ox;
12725                                                }
12726                                        }
12727                                } else {
12728                                        while (it.hasNext()) {
12729                                                final long iax = it.aLong;
12730                                                final long ibx = it.bLong;
12731                                                byte ox;
12732                                                ox = (byte) toLong(Math.max(iax, ibx));
12733                                                for (int j = 0; j < is; j++) {
12734                                                        oai8data[it.oIndex + j] = ox;
12735                                                }
12736                                        }
12737                                }
12738                        } else {
12739                                if (it.isOutputDouble()) {
12740                                        while (it.hasNext()) {
12741                                                double iax = it.aDouble;
12742                                                double ibx = it.bDouble;
12743                                                byte ox;
12744                                                ox = (byte) toLong(Math.max(iax, ibx));
12745                                                oai8data[it.oIndex] = ox;
12746                                                for (int j = 1; j < is; j++) {
12747                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12748                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12749                                                        ox = (byte) toLong(Math.max(iax, ibx));
12750                                                        oai8data[it.oIndex + j] = ox;
12751                                                }
12752                                        }
12753                                } else {
12754                                        while (it.hasNext()) {
12755                                                long iax = it.aLong;
12756                                                long ibx = it.bLong;
12757                                                byte ox;
12758                                                ox = (byte) toLong(Math.max(iax, ibx));
12759                                                oai8data[it.oIndex] = ox;
12760                                                for (int j = 1; j < is; j++) {
12761                                                        iax = da.getElementLongAbs(it.aIndex + j);
12762                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12763                                                        ox = (byte) toLong(Math.max(iax, ibx));
12764                                                        oai8data[it.oIndex + j] = ox;
12765                                                }
12766                                        }
12767                                }
12768                        }
12769                        break;
12770                case Dataset.ARRAYINT16:
12771                        final short[] oai16data = ((CompoundShortDataset) result).getData();
12772                        if (is == 1) {
12773                                if (it.isOutputDouble()) {
12774                                        while (it.hasNext()) {
12775                                                final double iax = it.aDouble;
12776                                                final double ibx = it.bDouble;
12777                                                short ox;
12778                                                ox = (short) toLong(Math.max(iax, ibx));
12779                                                oai16data[it.oIndex] = ox;
12780                                        }
12781                                } else {
12782                                        while (it.hasNext()) {
12783                                                final long iax = it.aLong;
12784                                                final long ibx = it.bLong;
12785                                                short ox;
12786                                                ox = (short) toLong(Math.max(iax, ibx));
12787                                                oai16data[it.oIndex] = ox;
12788                                        }
12789                                }
12790                        } else if (as < bs) {
12791                                if (it.isOutputDouble()) {
12792                                        while (it.hasNext()) {
12793                                                final double iax = it.aDouble;
12794                                                double ibx = it.bDouble;
12795                                                short ox;
12796                                                ox = (short) toLong(Math.max(iax, ibx));
12797                                                oai16data[it.oIndex] = ox;
12798                                                for (int j = 1; j < is; j++) {
12799                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12800                                                        ox = (short) toLong(Math.max(iax, ibx));
12801                                                        oai16data[it.oIndex + j] = ox;
12802                                                }
12803                                        }
12804                                } else {
12805                                        while (it.hasNext()) {
12806                                                final long iax = it.aLong;
12807                                                long ibx = it.bLong;
12808                                                short ox;
12809                                                ox = (short) toLong(Math.max(iax, ibx));
12810                                                oai16data[it.oIndex] = ox;
12811                                                for (int j = 1; j < is; j++) {
12812                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12813                                                        ox = (short) toLong(Math.max(iax, ibx));
12814                                                        oai16data[it.oIndex + j] = ox;
12815                                                }
12816                                        }
12817                                }
12818                        } else if (as > bs) {
12819                                if (it.isOutputDouble()) {
12820                                        while (it.hasNext()) {
12821                                                double iax = it.aDouble;
12822                                                final double ibx = it.bDouble;
12823                                                short ox;
12824                                                ox = (short) toLong(Math.max(iax, ibx));
12825                                                oai16data[it.oIndex] = ox;
12826                                                for (int j = 1; j < is; j++) {
12827                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12828                                                        ox = (short) toLong(Math.max(iax, ibx));
12829                                                        oai16data[it.oIndex + j] = ox;
12830                                                }
12831                                        }
12832                                } else {
12833                                        while (it.hasNext()) {
12834                                                long iax = it.aLong;
12835                                                final long ibx = it.bLong;
12836                                                short ox;
12837                                                ox = (short) toLong(Math.max(iax, ibx));
12838                                                oai16data[it.oIndex] = ox;
12839                                                for (int j = 1; j < is; j++) {
12840                                                        iax = da.getElementLongAbs(it.aIndex + j);
12841                                                        ox = (short) toLong(Math.max(iax, ibx));
12842                                                        oai16data[it.oIndex + j] = ox;
12843                                                }
12844                                        }
12845                                }
12846                        } else if (as == 1) {
12847                                if (it.isOutputDouble()) {
12848                                        while (it.hasNext()) {
12849                                                final double iax = it.aDouble;
12850                                                final double ibx = it.bDouble;
12851                                                short ox;
12852                                                ox = (short) toLong(Math.max(iax, ibx));
12853                                                for (int j = 0; j < is; j++) {
12854                                                        oai16data[it.oIndex + j] = ox;
12855                                                }
12856                                        }
12857                                } else {
12858                                        while (it.hasNext()) {
12859                                                final long iax = it.aLong;
12860                                                final long ibx = it.bLong;
12861                                                short ox;
12862                                                ox = (short) toLong(Math.max(iax, ibx));
12863                                                for (int j = 0; j < is; j++) {
12864                                                        oai16data[it.oIndex + j] = ox;
12865                                                }
12866                                        }
12867                                }
12868                        } else {
12869                                if (it.isOutputDouble()) {
12870                                        while (it.hasNext()) {
12871                                                double iax = it.aDouble;
12872                                                double ibx = it.bDouble;
12873                                                short ox;
12874                                                ox = (short) toLong(Math.max(iax, ibx));
12875                                                oai16data[it.oIndex] = ox;
12876                                                for (int j = 1; j < is; j++) {
12877                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12878                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12879                                                        ox = (short) toLong(Math.max(iax, ibx));
12880                                                        oai16data[it.oIndex + j] = ox;
12881                                                }
12882                                        }
12883                                } else {
12884                                        while (it.hasNext()) {
12885                                                long iax = it.aLong;
12886                                                long ibx = it.bLong;
12887                                                short ox;
12888                                                ox = (short) toLong(Math.max(iax, ibx));
12889                                                oai16data[it.oIndex] = ox;
12890                                                for (int j = 1; j < is; j++) {
12891                                                        iax = da.getElementLongAbs(it.aIndex + j);
12892                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12893                                                        ox = (short) toLong(Math.max(iax, ibx));
12894                                                        oai16data[it.oIndex + j] = ox;
12895                                                }
12896                                        }
12897                                }
12898                        }
12899                        break;
12900                case Dataset.ARRAYINT64:
12901                        final long[] oai64data = ((CompoundLongDataset) result).getData();
12902                        if (is == 1) {
12903                                if (it.isOutputDouble()) {
12904                                        while (it.hasNext()) {
12905                                                final double iax = it.aDouble;
12906                                                final double ibx = it.bDouble;
12907                                                long ox;
12908                                                ox = toLong(Math.max(iax, ibx));
12909                                                oai64data[it.oIndex] = ox;
12910                                        }
12911                                } else {
12912                                        while (it.hasNext()) {
12913                                                final long iax = it.aLong;
12914                                                final long ibx = it.bLong;
12915                                                long ox;
12916                                                ox = toLong(Math.max(iax, ibx));
12917                                                oai64data[it.oIndex] = ox;
12918                                        }
12919                                }
12920                        } else if (as < bs) {
12921                                if (it.isOutputDouble()) {
12922                                        while (it.hasNext()) {
12923                                                final double iax = it.aDouble;
12924                                                double ibx = it.bDouble;
12925                                                long ox;
12926                                                ox = toLong(Math.max(iax, ibx));
12927                                                oai64data[it.oIndex] = ox;
12928                                                for (int j = 1; j < is; j++) {
12929                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
12930                                                        ox = toLong(Math.max(iax, ibx));
12931                                                        oai64data[it.oIndex + j] = ox;
12932                                                }
12933                                        }
12934                                } else {
12935                                        while (it.hasNext()) {
12936                                                final long iax = it.aLong;
12937                                                long ibx = it.bLong;
12938                                                long ox;
12939                                                ox = toLong(Math.max(iax, ibx));
12940                                                oai64data[it.oIndex] = ox;
12941                                                for (int j = 1; j < is; j++) {
12942                                                        ibx = db.getElementLongAbs(it.bIndex + j);
12943                                                        ox = toLong(Math.max(iax, ibx));
12944                                                        oai64data[it.oIndex + j] = ox;
12945                                                }
12946                                        }
12947                                }
12948                        } else if (as > bs) {
12949                                if (it.isOutputDouble()) {
12950                                        while (it.hasNext()) {
12951                                                double iax = it.aDouble;
12952                                                final double ibx = it.bDouble;
12953                                                long ox;
12954                                                ox = toLong(Math.max(iax, ibx));
12955                                                oai64data[it.oIndex] = ox;
12956                                                for (int j = 1; j < is; j++) {
12957                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
12958                                                        ox = toLong(Math.max(iax, ibx));
12959                                                        oai64data[it.oIndex + j] = ox;
12960                                                }
12961                                        }
12962                                } else {
12963                                        while (it.hasNext()) {
12964                                                long iax = it.aLong;
12965                                                final long ibx = it.bLong;
12966                                                long ox;
12967                                                ox = toLong(Math.max(iax, ibx));
12968                                                oai64data[it.oIndex] = ox;
12969                                                for (int j = 1; j < is; j++) {
12970                                                        iax = da.getElementLongAbs(it.aIndex + j);
12971                                                        ox = toLong(Math.max(iax, ibx));
12972                                                        oai64data[it.oIndex + j] = ox;
12973                                                }
12974                                        }
12975                                }
12976                        } else if (as == 1) {
12977                                if (it.isOutputDouble()) {
12978                                        while (it.hasNext()) {
12979                                                final double iax = it.aDouble;
12980                                                final double ibx = it.bDouble;
12981                                                long ox;
12982                                                ox = toLong(Math.max(iax, ibx));
12983                                                for (int j = 0; j < is; j++) {
12984                                                        oai64data[it.oIndex + j] = ox;
12985                                                }
12986                                        }
12987                                } else {
12988                                        while (it.hasNext()) {
12989                                                final long iax = it.aLong;
12990                                                final long ibx = it.bLong;
12991                                                long ox;
12992                                                ox = toLong(Math.max(iax, ibx));
12993                                                for (int j = 0; j < is; j++) {
12994                                                        oai64data[it.oIndex + j] = ox;
12995                                                }
12996                                        }
12997                                }
12998                        } else {
12999                                if (it.isOutputDouble()) {
13000                                        while (it.hasNext()) {
13001                                                double iax = it.aDouble;
13002                                                double ibx = it.bDouble;
13003                                                long ox;
13004                                                ox = toLong(Math.max(iax, ibx));
13005                                                oai64data[it.oIndex] = ox;
13006                                                for (int j = 1; j < is; j++) {
13007                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13008                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13009                                                        ox = toLong(Math.max(iax, ibx));
13010                                                        oai64data[it.oIndex + j] = ox;
13011                                                }
13012                                        }
13013                                } else {
13014                                        while (it.hasNext()) {
13015                                                long iax = it.aLong;
13016                                                long ibx = it.bLong;
13017                                                long ox;
13018                                                ox = toLong(Math.max(iax, ibx));
13019                                                oai64data[it.oIndex] = ox;
13020                                                for (int j = 1; j < is; j++) {
13021                                                        iax = da.getElementLongAbs(it.aIndex + j);
13022                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13023                                                        ox = toLong(Math.max(iax, ibx));
13024                                                        oai64data[it.oIndex + j] = ox;
13025                                                }
13026                                        }
13027                                }
13028                        }
13029                        break;
13030                case Dataset.ARRAYINT32:
13031                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
13032                        if (is == 1) {
13033                                if (it.isOutputDouble()) {
13034                                        while (it.hasNext()) {
13035                                                final double iax = it.aDouble;
13036                                                final double ibx = it.bDouble;
13037                                                int ox;
13038                                                ox = (int) toLong(Math.max(iax, ibx));
13039                                                oai32data[it.oIndex] = ox;
13040                                        }
13041                                } else {
13042                                        while (it.hasNext()) {
13043                                                final long iax = it.aLong;
13044                                                final long ibx = it.bLong;
13045                                                int ox;
13046                                                ox = (int) toLong(Math.max(iax, ibx));
13047                                                oai32data[it.oIndex] = ox;
13048                                        }
13049                                }
13050                        } else if (as < bs) {
13051                                if (it.isOutputDouble()) {
13052                                        while (it.hasNext()) {
13053                                                final double iax = it.aDouble;
13054                                                double ibx = it.bDouble;
13055                                                int ox;
13056                                                ox = (int) toLong(Math.max(iax, ibx));
13057                                                oai32data[it.oIndex] = ox;
13058                                                for (int j = 1; j < is; j++) {
13059                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13060                                                        ox = (int) toLong(Math.max(iax, ibx));
13061                                                        oai32data[it.oIndex + j] = ox;
13062                                                }
13063                                        }
13064                                } else {
13065                                        while (it.hasNext()) {
13066                                                final long iax = it.aLong;
13067                                                long ibx = it.bLong;
13068                                                int ox;
13069                                                ox = (int) toLong(Math.max(iax, ibx));
13070                                                oai32data[it.oIndex] = ox;
13071                                                for (int j = 1; j < is; j++) {
13072                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13073                                                        ox = (int) toLong(Math.max(iax, ibx));
13074                                                        oai32data[it.oIndex + j] = ox;
13075                                                }
13076                                        }
13077                                }
13078                        } else if (as > bs) {
13079                                if (it.isOutputDouble()) {
13080                                        while (it.hasNext()) {
13081                                                double iax = it.aDouble;
13082                                                final double ibx = it.bDouble;
13083                                                int ox;
13084                                                ox = (int) toLong(Math.max(iax, ibx));
13085                                                oai32data[it.oIndex] = ox;
13086                                                for (int j = 1; j < is; j++) {
13087                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13088                                                        ox = (int) toLong(Math.max(iax, ibx));
13089                                                        oai32data[it.oIndex + j] = ox;
13090                                                }
13091                                        }
13092                                } else {
13093                                        while (it.hasNext()) {
13094                                                long iax = it.aLong;
13095                                                final long ibx = it.bLong;
13096                                                int ox;
13097                                                ox = (int) toLong(Math.max(iax, ibx));
13098                                                oai32data[it.oIndex] = ox;
13099                                                for (int j = 1; j < is; j++) {
13100                                                        iax = da.getElementLongAbs(it.aIndex + j);
13101                                                        ox = (int) toLong(Math.max(iax, ibx));
13102                                                        oai32data[it.oIndex + j] = ox;
13103                                                }
13104                                        }
13105                                }
13106                        } else if (as == 1) {
13107                                if (it.isOutputDouble()) {
13108                                        while (it.hasNext()) {
13109                                                final double iax = it.aDouble;
13110                                                final double ibx = it.bDouble;
13111                                                int ox;
13112                                                ox = (int) toLong(Math.max(iax, ibx));
13113                                                for (int j = 0; j < is; j++) {
13114                                                        oai32data[it.oIndex + j] = ox;
13115                                                }
13116                                        }
13117                                } else {
13118                                        while (it.hasNext()) {
13119                                                final long iax = it.aLong;
13120                                                final long ibx = it.bLong;
13121                                                int ox;
13122                                                ox = (int) toLong(Math.max(iax, ibx));
13123                                                for (int j = 0; j < is; j++) {
13124                                                        oai32data[it.oIndex + j] = ox;
13125                                                }
13126                                        }
13127                                }
13128                        } else {
13129                                if (it.isOutputDouble()) {
13130                                        while (it.hasNext()) {
13131                                                double iax = it.aDouble;
13132                                                double ibx = it.bDouble;
13133                                                int ox;
13134                                                ox = (int) toLong(Math.max(iax, ibx));
13135                                                oai32data[it.oIndex] = ox;
13136                                                for (int j = 1; j < is; j++) {
13137                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13138                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13139                                                        ox = (int) toLong(Math.max(iax, ibx));
13140                                                        oai32data[it.oIndex + j] = ox;
13141                                                }
13142                                        }
13143                                } else {
13144                                        while (it.hasNext()) {
13145                                                long iax = it.aLong;
13146                                                long ibx = it.bLong;
13147                                                int ox;
13148                                                ox = (int) toLong(Math.max(iax, ibx));
13149                                                oai32data[it.oIndex] = ox;
13150                                                for (int j = 1; j < is; j++) {
13151                                                        iax = da.getElementLongAbs(it.aIndex + j);
13152                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13153                                                        ox = (int) toLong(Math.max(iax, ibx));
13154                                                        oai32data[it.oIndex + j] = ox;
13155                                                }
13156                                        }
13157                                }
13158                        }
13159                        break;
13160                case Dataset.FLOAT32:
13161                        final float[] of32data = ((FloatDataset) result).getData();
13162                        if (it.isOutputDouble()) {
13163                                while (it.hasNext()) {
13164                                        final double iax = it.aDouble;
13165                                        final double ibx = it.bDouble;
13166                                        float ox;
13167                                        ox = (float) (Math.max(iax, ibx));
13168                                        of32data[it.oIndex] = ox;
13169                                }
13170                        } else {
13171                                while (it.hasNext()) {
13172                                        final long iax = it.aLong;
13173                                        final long ibx = it.bLong;
13174                                        float ox;
13175                                        ox = (float) (Math.max(iax, ibx));
13176                                        of32data[it.oIndex] = ox;
13177                                }
13178                        }
13179                        break;
13180                case Dataset.FLOAT64:
13181                        final double[] of64data = ((DoubleDataset) result).getData();
13182                        if (it.isOutputDouble()) {
13183                                while (it.hasNext()) {
13184                                        final double iax = it.aDouble;
13185                                        final double ibx = it.bDouble;
13186                                        double ox;
13187                                        ox = (Math.max(iax, ibx));
13188                                        of64data[it.oIndex] = ox;
13189                                }
13190                        } else {
13191                                while (it.hasNext()) {
13192                                        final long iax = it.aLong;
13193                                        final long ibx = it.bLong;
13194                                        double ox;
13195                                        ox = (Math.max(iax, ibx));
13196                                        of64data[it.oIndex] = ox;
13197                                }
13198                        }
13199                        break;
13200                case Dataset.ARRAYFLOAT32:
13201                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
13202                        if (is == 1) {
13203                                if (it.isOutputDouble()) {
13204                                        while (it.hasNext()) {
13205                                                final double iax = it.aDouble;
13206                                                final double ibx = it.bDouble;
13207                                                float ox;
13208                                                ox = (float) (Math.max(iax, ibx));
13209                                                oaf32data[it.oIndex] = ox;
13210                                        }
13211                                } else {
13212                                        while (it.hasNext()) {
13213                                                final long iax = it.aLong;
13214                                                final long ibx = it.bLong;
13215                                                float ox;
13216                                                ox = (float) (Math.max(iax, ibx));
13217                                                oaf32data[it.oIndex] = ox;
13218                                        }
13219                                }
13220                        } else if (as < bs) {
13221                                if (it.isOutputDouble()) {
13222                                        while (it.hasNext()) {
13223                                                final double iax = it.aDouble;
13224                                                double ibx = it.bDouble;
13225                                                float ox;
13226                                                ox = (float) (Math.max(iax, ibx));
13227                                                oaf32data[it.oIndex] = ox;
13228                                                for (int j = 1; j < is; j++) {
13229                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13230                                                        ox = (float) (Math.max(iax, ibx));
13231                                                        oaf32data[it.oIndex + j] = ox;
13232                                                }
13233                                        }
13234                                } else {
13235                                        while (it.hasNext()) {
13236                                                final long iax = it.aLong;
13237                                                long ibx = it.bLong;
13238                                                float ox;
13239                                                ox = (float) (Math.max(iax, ibx));
13240                                                oaf32data[it.oIndex] = ox;
13241                                                for (int j = 1; j < is; j++) {
13242                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13243                                                        ox = (float) (Math.max(iax, ibx));
13244                                                        oaf32data[it.oIndex + j] = ox;
13245                                                }
13246                                        }
13247                                }
13248                        } else if (as > bs) {
13249                                if (it.isOutputDouble()) {
13250                                        while (it.hasNext()) {
13251                                                double iax = it.aDouble;
13252                                                final double ibx = it.bDouble;
13253                                                float ox;
13254                                                ox = (float) (Math.max(iax, ibx));
13255                                                oaf32data[it.oIndex] = ox;
13256                                                for (int j = 1; j < is; j++) {
13257                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13258                                                        ox = (float) (Math.max(iax, ibx));
13259                                                        oaf32data[it.oIndex + j] = ox;
13260                                                }
13261                                        }
13262                                } else {
13263                                        while (it.hasNext()) {
13264                                                long iax = it.aLong;
13265                                                final long ibx = it.bLong;
13266                                                float ox;
13267                                                ox = (float) (Math.max(iax, ibx));
13268                                                oaf32data[it.oIndex] = ox;
13269                                                for (int j = 1; j < is; j++) {
13270                                                        iax = da.getElementLongAbs(it.aIndex + j);
13271                                                        ox = (float) (Math.max(iax, ibx));
13272                                                        oaf32data[it.oIndex + j] = ox;
13273                                                }
13274                                        }
13275                                }
13276                        } else if (as == 1) {
13277                                if (it.isOutputDouble()) {
13278                                        while (it.hasNext()) {
13279                                                final double iax = it.aDouble;
13280                                                final double ibx = it.bDouble;
13281                                                float ox;
13282                                                ox = (float) (Math.max(iax, ibx));
13283                                                for (int j = 0; j < is; j++) {
13284                                                        oaf32data[it.oIndex + j] = ox;
13285                                                }
13286                                        }
13287                                } else {
13288                                        while (it.hasNext()) {
13289                                                final long iax = it.aLong;
13290                                                final long ibx = it.bLong;
13291                                                float ox;
13292                                                ox = (float) (Math.max(iax, ibx));
13293                                                for (int j = 0; j < is; j++) {
13294                                                        oaf32data[it.oIndex + j] = ox;
13295                                                }
13296                                        }
13297                                }
13298                        } else {
13299                                if (it.isOutputDouble()) {
13300                                        while (it.hasNext()) {
13301                                                double iax = it.aDouble;
13302                                                double ibx = it.bDouble;
13303                                                float ox;
13304                                                ox = (float) (Math.max(iax, ibx));
13305                                                oaf32data[it.oIndex] = ox;
13306                                                for (int j = 1; j < is; j++) {
13307                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13308                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13309                                                        ox = (float) (Math.max(iax, ibx));
13310                                                        oaf32data[it.oIndex + j] = ox;
13311                                                }
13312                                        }
13313                                } else {
13314                                        while (it.hasNext()) {
13315                                                long iax = it.aLong;
13316                                                long ibx = it.bLong;
13317                                                float ox;
13318                                                ox = (float) (Math.max(iax, ibx));
13319                                                oaf32data[it.oIndex] = ox;
13320                                                for (int j = 1; j < is; j++) {
13321                                                        iax = da.getElementLongAbs(it.aIndex + j);
13322                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13323                                                        ox = (float) (Math.max(iax, ibx));
13324                                                        oaf32data[it.oIndex + j] = ox;
13325                                                }
13326                                        }
13327                                }
13328                        }
13329                        break;
13330                case Dataset.ARRAYFLOAT64:
13331                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
13332                        if (is == 1) {
13333                                if (it.isOutputDouble()) {
13334                                        while (it.hasNext()) {
13335                                                final double iax = it.aDouble;
13336                                                final double ibx = it.bDouble;
13337                                                double ox;
13338                                                ox = (Math.max(iax, ibx));
13339                                                oaf64data[it.oIndex] = ox;
13340                                        }
13341                                } else {
13342                                        while (it.hasNext()) {
13343                                                final long iax = it.aLong;
13344                                                final long ibx = it.bLong;
13345                                                double ox;
13346                                                ox = (Math.max(iax, ibx));
13347                                                oaf64data[it.oIndex] = ox;
13348                                        }
13349                                }
13350                        } else if (as < bs) {
13351                                if (it.isOutputDouble()) {
13352                                        while (it.hasNext()) {
13353                                                final double iax = it.aDouble;
13354                                                double ibx = it.bDouble;
13355                                                double ox;
13356                                                ox = (Math.max(iax, ibx));
13357                                                oaf64data[it.oIndex] = ox;
13358                                                for (int j = 1; j < is; j++) {
13359                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13360                                                        ox = (Math.max(iax, ibx));
13361                                                        oaf64data[it.oIndex + j] = ox;
13362                                                }
13363                                        }
13364                                } else {
13365                                        while (it.hasNext()) {
13366                                                final long iax = it.aLong;
13367                                                long ibx = it.bLong;
13368                                                double ox;
13369                                                ox = (Math.max(iax, ibx));
13370                                                oaf64data[it.oIndex] = ox;
13371                                                for (int j = 1; j < is; j++) {
13372                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13373                                                        ox = (Math.max(iax, ibx));
13374                                                        oaf64data[it.oIndex + j] = ox;
13375                                                }
13376                                        }
13377                                }
13378                        } else if (as > bs) {
13379                                if (it.isOutputDouble()) {
13380                                        while (it.hasNext()) {
13381                                                double iax = it.aDouble;
13382                                                final double ibx = it.bDouble;
13383                                                double ox;
13384                                                ox = (Math.max(iax, ibx));
13385                                                oaf64data[it.oIndex] = ox;
13386                                                for (int j = 1; j < is; j++) {
13387                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13388                                                        ox = (Math.max(iax, ibx));
13389                                                        oaf64data[it.oIndex + j] = ox;
13390                                                }
13391                                        }
13392                                } else {
13393                                        while (it.hasNext()) {
13394                                                long iax = it.aLong;
13395                                                final long ibx = it.bLong;
13396                                                double ox;
13397                                                ox = (Math.max(iax, ibx));
13398                                                oaf64data[it.oIndex] = ox;
13399                                                for (int j = 1; j < is; j++) {
13400                                                        iax = da.getElementLongAbs(it.aIndex + j);
13401                                                        ox = (Math.max(iax, ibx));
13402                                                        oaf64data[it.oIndex + j] = ox;
13403                                                }
13404                                        }
13405                                }
13406                        } else if (as == 1) {
13407                                if (it.isOutputDouble()) {
13408                                        while (it.hasNext()) {
13409                                                final double iax = it.aDouble;
13410                                                final double ibx = it.bDouble;
13411                                                double ox;
13412                                                ox = (Math.max(iax, ibx));
13413                                                for (int j = 0; j < is; j++) {
13414                                                        oaf64data[it.oIndex + j] = ox;
13415                                                }
13416                                        }
13417                                } else {
13418                                        while (it.hasNext()) {
13419                                                final long iax = it.aLong;
13420                                                final long ibx = it.bLong;
13421                                                double ox;
13422                                                ox = (Math.max(iax, ibx));
13423                                                for (int j = 0; j < is; j++) {
13424                                                        oaf64data[it.oIndex + j] = ox;
13425                                                }
13426                                        }
13427                                }
13428                        } else {
13429                                if (it.isOutputDouble()) {
13430                                        while (it.hasNext()) {
13431                                                double iax = it.aDouble;
13432                                                double ibx = it.bDouble;
13433                                                double ox;
13434                                                ox = (Math.max(iax, ibx));
13435                                                oaf64data[it.oIndex] = ox;
13436                                                for (int j = 1; j < is; j++) {
13437                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13438                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13439                                                        ox = (Math.max(iax, ibx));
13440                                                        oaf64data[it.oIndex + j] = ox;
13441                                                }
13442                                        }
13443                                } else {
13444                                        while (it.hasNext()) {
13445                                                long iax = it.aLong;
13446                                                long ibx = it.bLong;
13447                                                double ox;
13448                                                ox = (Math.max(iax, ibx));
13449                                                oaf64data[it.oIndex] = ox;
13450                                                for (int j = 1; j < is; j++) {
13451                                                        iax = da.getElementLongAbs(it.aIndex + j);
13452                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13453                                                        ox = (Math.max(iax, ibx));
13454                                                        oaf64data[it.oIndex + j] = ox;
13455                                                }
13456                                        }
13457                                }
13458                        }
13459                        break;
13460                case Dataset.COMPLEX64:
13461                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
13462                        if (!da.isComplex()) {
13463                                if (it.isOutputDouble()) {
13464                                        final double iay = 0;
13465                                        if (db.isComplex()) {
13466                                                while (it.hasNext()) {
13467                                                        final double iax = it.aDouble;
13468                                                        final double ibx = it.bDouble;
13469                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
13470                                                        float ox;
13471                                                        float oy;
13472                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13473                                                                ox = (float) (iax);
13474                                                                oy = (float) (iay);
13475                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13476                                                                ox = (float) (ibx);
13477                                                                oy = (float) (iby);
13478                                                        } else {
13479                                                                ox = (float) (Math.max(iax, ibx));
13480                                                                oy = (float) (Math.max(iay, iby));
13481                                                        }
13482                                                        oc64data[it.oIndex] = ox;
13483                                                        oc64data[it.oIndex + 1] = oy;
13484                                                }
13485                                        } else {
13486                                                while (it.hasNext()) {
13487                                                        final double iax = it.aDouble;
13488                                                        final double ibx = it.bDouble;
13489                                                        final double iby = 0;
13490                                                        float ox;
13491                                                        float oy;
13492                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13493                                                                ox = (float) (iax);
13494                                                                oy = (float) (iay);
13495                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13496                                                                ox = (float) (ibx);
13497                                                                oy = (float) (iby);
13498                                                        } else {
13499                                                                ox = (float) (Math.max(iax, ibx));
13500                                                                oy = (float) (Math.max(iay, iby));
13501                                                        }
13502                                                        oc64data[it.oIndex] = ox;
13503                                                        oc64data[it.oIndex + 1] = oy;
13504                                                }
13505                                        }
13506                                } else {
13507                                        final long iay = 0;
13508                                        while (it.hasNext()) {
13509                                                final long iax = it.aLong;
13510                                                final long ibx = it.bLong;
13511                                                final long iby = 0;
13512                                                float ox;
13513                                                float oy;
13514                                                if (Double.isNaN(iax) || Double.isNaN(iay)) {
13515                                                        ox = (float) (iax);
13516                                                        oy = (float) (iay);
13517                                                } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13518                                                        ox = (float) (ibx);
13519                                                        oy = (float) (iby);
13520                                                } else {
13521                                                        ox = (float) (Math.max(iax, ibx));
13522                                                        oy = (float) (Math.max(iay, iby));
13523                                                }
13524                                                oc64data[it.oIndex] = ox;
13525                                                oc64data[it.oIndex + 1] = oy;
13526                                        }
13527                                }
13528                        } else if (!db.isComplex()) {
13529                                final double iby = 0;
13530                                while (it.hasNext()) {
13531                                        final double iax = it.aDouble;
13532                                        final double ibx = it.bDouble;
13533                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
13534                                        float ox;
13535                                        float oy;
13536                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13537                                                ox = (float) (iax);
13538                                                oy = (float) (iay);
13539                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13540                                                ox = (float) (ibx);
13541                                                oy = (float) (iby);
13542                                        } else {
13543                                                ox = (float) (Math.max(iax, ibx));
13544                                                oy = (float) (Math.max(iay, iby));
13545                                        }
13546                                        oc64data[it.oIndex] = ox;
13547                                        oc64data[it.oIndex + 1] = oy;
13548                                }
13549                        } else {
13550                                while (it.hasNext()) {
13551                                        final double iax = it.aDouble;
13552                                        final double ibx = it.bDouble;
13553                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
13554                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
13555                                        float ox;
13556                                        float oy;
13557                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13558                                                ox = (float) (iax);
13559                                                oy = (float) (iay);
13560                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13561                                                ox = (float) (ibx);
13562                                                oy = (float) (iby);
13563                                        } else {
13564                                                ox = (float) (Math.max(iax, ibx));
13565                                                oy = (float) (Math.max(iay, iby));
13566                                        }
13567                                        oc64data[it.oIndex] = ox;
13568                                        oc64data[it.oIndex + 1] = oy;
13569                                }
13570                        }
13571                        break;
13572                case Dataset.COMPLEX128:
13573                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
13574                        if (!da.isComplex()) {
13575                                if (it.isOutputDouble()) {
13576                                        final double iay = 0;
13577                                        if (db.isComplex()) {
13578                                                while (it.hasNext()) {
13579                                                        final double iax = it.aDouble;
13580                                                        final double ibx = it.bDouble;
13581                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
13582                                                        double ox;
13583                                                        double oy;
13584                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13585                                                                ox = (iax);
13586                                                                oy = (iay);
13587                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13588                                                                ox = (ibx);
13589                                                                oy = (iby);
13590                                                        } else {
13591                                                                ox = (Math.max(iax, ibx));
13592                                                                oy = (Math.max(iay, iby));
13593                                                        }
13594                                                        oc128data[it.oIndex] = ox;
13595                                                        oc128data[it.oIndex + 1] = oy;
13596                                                }
13597                                        } else {
13598                                                while (it.hasNext()) {
13599                                                        final double iax = it.aDouble;
13600                                                        final double ibx = it.bDouble;
13601                                                        final double iby = 0;
13602                                                        double ox;
13603                                                        double oy;
13604                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13605                                                                ox = (iax);
13606                                                                oy = (iay);
13607                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13608                                                                ox = (ibx);
13609                                                                oy = (iby);
13610                                                        } else {
13611                                                                ox = (Math.max(iax, ibx));
13612                                                                oy = (Math.max(iay, iby));
13613                                                        }
13614                                                        oc128data[it.oIndex] = ox;
13615                                                        oc128data[it.oIndex + 1] = oy;
13616                                                }
13617                                        }
13618                                } else {
13619                                        final long iay = 0;
13620                                        while (it.hasNext()) {
13621                                                final long iax = it.aLong;
13622                                                final long ibx = it.bLong;
13623                                                final long iby = 0;
13624                                                double ox;
13625                                                double oy;
13626                                                if (Double.isNaN(iax) || Double.isNaN(iay)) {
13627                                                        ox = (iax);
13628                                                        oy = (iay);
13629                                                } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13630                                                        ox = (ibx);
13631                                                        oy = (iby);
13632                                                } else {
13633                                                        ox = (double) (Math.max(iax, ibx));
13634                                                        oy = (double) (Math.max(iay, iby));
13635                                                }
13636                                                oc128data[it.oIndex] = ox;
13637                                                oc128data[it.oIndex + 1] = oy;
13638                                        }
13639                                }
13640                        } else if (!db.isComplex()) {
13641                                final double iby = 0;
13642                                while (it.hasNext()) {
13643                                        final double iax = it.aDouble;
13644                                        final double ibx = it.bDouble;
13645                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
13646                                        double ox;
13647                                        double oy;
13648                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13649                                                ox = (iax);
13650                                                oy = (iay);
13651                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13652                                                ox = (ibx);
13653                                                oy = (iby);
13654                                        } else {
13655                                                ox = (Math.max(iax, ibx));
13656                                                oy = (Math.max(iay, iby));
13657                                        }
13658                                        oc128data[it.oIndex] = ox;
13659                                        oc128data[it.oIndex + 1] = oy;
13660                                }
13661                        } else {
13662                                while (it.hasNext()) {
13663                                        final double iax = it.aDouble;
13664                                        final double ibx = it.bDouble;
13665                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
13666                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
13667                                        double ox;
13668                                        double oy;
13669                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
13670                                                ox = (iax);
13671                                                oy = (iay);
13672                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
13673                                                ox = (ibx);
13674                                                oy = (iby);
13675                                        } else {
13676                                                ox = (Math.max(iax, ibx));
13677                                                oy = (Math.max(iay, iby));
13678                                        }
13679                                        oc128data[it.oIndex] = ox;
13680                                        oc128data[it.oIndex + 1] = oy;
13681                                }
13682                        }
13683                        break;
13684                default:
13685                        throw new IllegalArgumentException("maximum supports integer, compound integer, real, compound real, complex datasets only");
13686                }
13687
13688                addBinaryOperatorName(da, db, result, "maximum");
13689                return result;
13690        }
13691
13692        /**
13693         * minimum operator
13694         * @param a first operand
13695         * @param b second operand
13696         * @return return minimum of a and b
13697         */
13698        public static Dataset minimum(final Object a, final Object b) {
13699                return minimum(a, b, null);
13700        }
13701
13702        /**
13703         * minimum operator
13704         * @param a first operand
13705         * @param b second operand
13706         * @param o output can be null - in which case, a new dataset is created
13707         * @return return minimum of a and b
13708         */
13709        public static Dataset minimum(final Object a, final Object b, final Dataset o) {
13710                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
13711                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
13712                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
13713                final Dataset result = it.getOutput();
13714                if (!result.isComplex()) {
13715                        boolean change = false;
13716                        if (da.isComplex()) {
13717                                da = da.getRealView();
13718                                change = true;
13719                        }
13720                        if (db.isComplex()) {
13721                                db = db.getRealView();
13722                                change = true;
13723                        }
13724                        if (change) {
13725                                it = BroadcastIterator.createIterator(da, db, result, true);
13726                        }
13727                }
13728                final int is = result.getElementsPerItem();
13729                final int as = da.getElementsPerItem();
13730                final int bs = db.getElementsPerItem();
13731                final int dt = result.getDType();
13732
13733                switch(dt) {
13734                case Dataset.INT8:
13735                        final byte[] oi8data = ((ByteDataset) result).getData();
13736                        if (it.isOutputDouble()) {
13737                                while (it.hasNext()) {
13738                                        final double iax = it.aDouble;
13739                                        final double ibx = it.bDouble;
13740                                        byte ox;
13741                                        ox = (byte) toLong(Math.min(iax, ibx));
13742                                        oi8data[it.oIndex] = ox;
13743                                }
13744                        } else {
13745                                while (it.hasNext()) {
13746                                        final long iax = it.aLong;
13747                                        final long ibx = it.bLong;
13748                                        byte ox;
13749                                        ox = (byte) toLong(Math.min(iax, ibx));
13750                                        oi8data[it.oIndex] = ox;
13751                                }
13752                        }
13753                        break;
13754                case Dataset.INT16:
13755                        final short[] oi16data = ((ShortDataset) result).getData();
13756                        if (it.isOutputDouble()) {
13757                                while (it.hasNext()) {
13758                                        final double iax = it.aDouble;
13759                                        final double ibx = it.bDouble;
13760                                        short ox;
13761                                        ox = (short) toLong(Math.min(iax, ibx));
13762                                        oi16data[it.oIndex] = ox;
13763                                }
13764                        } else {
13765                                while (it.hasNext()) {
13766                                        final long iax = it.aLong;
13767                                        final long ibx = it.bLong;
13768                                        short ox;
13769                                        ox = (short) toLong(Math.min(iax, ibx));
13770                                        oi16data[it.oIndex] = ox;
13771                                }
13772                        }
13773                        break;
13774                case Dataset.INT64:
13775                        final long[] oi64data = ((LongDataset) result).getData();
13776                        if (it.isOutputDouble()) {
13777                                while (it.hasNext()) {
13778                                        final double iax = it.aDouble;
13779                                        final double ibx = it.bDouble;
13780                                        long ox;
13781                                        ox = toLong(Math.min(iax, ibx));
13782                                        oi64data[it.oIndex] = ox;
13783                                }
13784                        } else {
13785                                while (it.hasNext()) {
13786                                        final long iax = it.aLong;
13787                                        final long ibx = it.bLong;
13788                                        long ox;
13789                                        ox = toLong(Math.min(iax, ibx));
13790                                        oi64data[it.oIndex] = ox;
13791                                }
13792                        }
13793                        break;
13794                case Dataset.INT32:
13795                        final int[] oi32data = ((IntegerDataset) result).getData();
13796                        if (it.isOutputDouble()) {
13797                                while (it.hasNext()) {
13798                                        final double iax = it.aDouble;
13799                                        final double ibx = it.bDouble;
13800                                        int ox;
13801                                        ox = (int) toLong(Math.min(iax, ibx));
13802                                        oi32data[it.oIndex] = ox;
13803                                }
13804                        } else {
13805                                while (it.hasNext()) {
13806                                        final long iax = it.aLong;
13807                                        final long ibx = it.bLong;
13808                                        int ox;
13809                                        ox = (int) toLong(Math.min(iax, ibx));
13810                                        oi32data[it.oIndex] = ox;
13811                                }
13812                        }
13813                        break;
13814                case Dataset.ARRAYINT8:
13815                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
13816                        if (is == 1) {
13817                                if (it.isOutputDouble()) {
13818                                        while (it.hasNext()) {
13819                                                final double iax = it.aDouble;
13820                                                final double ibx = it.bDouble;
13821                                                byte ox;
13822                                                ox = (byte) toLong(Math.min(iax, ibx));
13823                                                oai8data[it.oIndex] = ox;
13824                                        }
13825                                } else {
13826                                        while (it.hasNext()) {
13827                                                final long iax = it.aLong;
13828                                                final long ibx = it.bLong;
13829                                                byte ox;
13830                                                ox = (byte) toLong(Math.min(iax, ibx));
13831                                                oai8data[it.oIndex] = ox;
13832                                        }
13833                                }
13834                        } else if (as < bs) {
13835                                if (it.isOutputDouble()) {
13836                                        while (it.hasNext()) {
13837                                                final double iax = it.aDouble;
13838                                                double ibx = it.bDouble;
13839                                                byte ox;
13840                                                ox = (byte) toLong(Math.min(iax, ibx));
13841                                                oai8data[it.oIndex] = ox;
13842                                                for (int j = 1; j < is; j++) {
13843                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13844                                                        ox = (byte) toLong(Math.min(iax, ibx));
13845                                                        oai8data[it.oIndex + j] = ox;
13846                                                }
13847                                        }
13848                                } else {
13849                                        while (it.hasNext()) {
13850                                                final long iax = it.aLong;
13851                                                long ibx = it.bLong;
13852                                                byte ox;
13853                                                ox = (byte) toLong(Math.min(iax, ibx));
13854                                                oai8data[it.oIndex] = ox;
13855                                                for (int j = 1; j < is; j++) {
13856                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13857                                                        ox = (byte) toLong(Math.min(iax, ibx));
13858                                                        oai8data[it.oIndex + j] = ox;
13859                                                }
13860                                        }
13861                                }
13862                        } else if (as > bs) {
13863                                if (it.isOutputDouble()) {
13864                                        while (it.hasNext()) {
13865                                                double iax = it.aDouble;
13866                                                final double ibx = it.bDouble;
13867                                                byte ox;
13868                                                ox = (byte) toLong(Math.min(iax, ibx));
13869                                                oai8data[it.oIndex] = ox;
13870                                                for (int j = 1; j < is; j++) {
13871                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13872                                                        ox = (byte) toLong(Math.min(iax, ibx));
13873                                                        oai8data[it.oIndex + j] = ox;
13874                                                }
13875                                        }
13876                                } else {
13877                                        while (it.hasNext()) {
13878                                                long iax = it.aLong;
13879                                                final long ibx = it.bLong;
13880                                                byte ox;
13881                                                ox = (byte) toLong(Math.min(iax, ibx));
13882                                                oai8data[it.oIndex] = ox;
13883                                                for (int j = 1; j < is; j++) {
13884                                                        iax = da.getElementLongAbs(it.aIndex + j);
13885                                                        ox = (byte) toLong(Math.min(iax, ibx));
13886                                                        oai8data[it.oIndex + j] = ox;
13887                                                }
13888                                        }
13889                                }
13890                        } else if (as == 1) {
13891                                if (it.isOutputDouble()) {
13892                                        while (it.hasNext()) {
13893                                                final double iax = it.aDouble;
13894                                                final double ibx = it.bDouble;
13895                                                byte ox;
13896                                                ox = (byte) toLong(Math.min(iax, ibx));
13897                                                for (int j = 0; j < is; j++) {
13898                                                        oai8data[it.oIndex + j] = ox;
13899                                                }
13900                                        }
13901                                } else {
13902                                        while (it.hasNext()) {
13903                                                final long iax = it.aLong;
13904                                                final long ibx = it.bLong;
13905                                                byte ox;
13906                                                ox = (byte) toLong(Math.min(iax, ibx));
13907                                                for (int j = 0; j < is; j++) {
13908                                                        oai8data[it.oIndex + j] = ox;
13909                                                }
13910                                        }
13911                                }
13912                        } else {
13913                                if (it.isOutputDouble()) {
13914                                        while (it.hasNext()) {
13915                                                double iax = it.aDouble;
13916                                                double ibx = it.bDouble;
13917                                                byte ox;
13918                                                ox = (byte) toLong(Math.min(iax, ibx));
13919                                                oai8data[it.oIndex] = ox;
13920                                                for (int j = 1; j < is; j++) {
13921                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
13922                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13923                                                        ox = (byte) toLong(Math.min(iax, ibx));
13924                                                        oai8data[it.oIndex + j] = ox;
13925                                                }
13926                                        }
13927                                } else {
13928                                        while (it.hasNext()) {
13929                                                long iax = it.aLong;
13930                                                long ibx = it.bLong;
13931                                                byte ox;
13932                                                ox = (byte) toLong(Math.min(iax, ibx));
13933                                                oai8data[it.oIndex] = ox;
13934                                                for (int j = 1; j < is; j++) {
13935                                                        iax = da.getElementLongAbs(it.aIndex + j);
13936                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13937                                                        ox = (byte) toLong(Math.min(iax, ibx));
13938                                                        oai8data[it.oIndex + j] = ox;
13939                                                }
13940                                        }
13941                                }
13942                        }
13943                        break;
13944                case Dataset.ARRAYINT16:
13945                        final short[] oai16data = ((CompoundShortDataset) result).getData();
13946                        if (is == 1) {
13947                                if (it.isOutputDouble()) {
13948                                        while (it.hasNext()) {
13949                                                final double iax = it.aDouble;
13950                                                final double ibx = it.bDouble;
13951                                                short ox;
13952                                                ox = (short) toLong(Math.min(iax, ibx));
13953                                                oai16data[it.oIndex] = ox;
13954                                        }
13955                                } else {
13956                                        while (it.hasNext()) {
13957                                                final long iax = it.aLong;
13958                                                final long ibx = it.bLong;
13959                                                short ox;
13960                                                ox = (short) toLong(Math.min(iax, ibx));
13961                                                oai16data[it.oIndex] = ox;
13962                                        }
13963                                }
13964                        } else if (as < bs) {
13965                                if (it.isOutputDouble()) {
13966                                        while (it.hasNext()) {
13967                                                final double iax = it.aDouble;
13968                                                double ibx = it.bDouble;
13969                                                short ox;
13970                                                ox = (short) toLong(Math.min(iax, ibx));
13971                                                oai16data[it.oIndex] = ox;
13972                                                for (int j = 1; j < is; j++) {
13973                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
13974                                                        ox = (short) toLong(Math.min(iax, ibx));
13975                                                        oai16data[it.oIndex + j] = ox;
13976                                                }
13977                                        }
13978                                } else {
13979                                        while (it.hasNext()) {
13980                                                final long iax = it.aLong;
13981                                                long ibx = it.bLong;
13982                                                short ox;
13983                                                ox = (short) toLong(Math.min(iax, ibx));
13984                                                oai16data[it.oIndex] = ox;
13985                                                for (int j = 1; j < is; j++) {
13986                                                        ibx = db.getElementLongAbs(it.bIndex + j);
13987                                                        ox = (short) toLong(Math.min(iax, ibx));
13988                                                        oai16data[it.oIndex + j] = ox;
13989                                                }
13990                                        }
13991                                }
13992                        } else if (as > bs) {
13993                                if (it.isOutputDouble()) {
13994                                        while (it.hasNext()) {
13995                                                double iax = it.aDouble;
13996                                                final double ibx = it.bDouble;
13997                                                short ox;
13998                                                ox = (short) toLong(Math.min(iax, ibx));
13999                                                oai16data[it.oIndex] = ox;
14000                                                for (int j = 1; j < is; j++) {
14001                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14002                                                        ox = (short) toLong(Math.min(iax, ibx));
14003                                                        oai16data[it.oIndex + j] = ox;
14004                                                }
14005                                        }
14006                                } else {
14007                                        while (it.hasNext()) {
14008                                                long iax = it.aLong;
14009                                                final long ibx = it.bLong;
14010                                                short ox;
14011                                                ox = (short) toLong(Math.min(iax, ibx));
14012                                                oai16data[it.oIndex] = ox;
14013                                                for (int j = 1; j < is; j++) {
14014                                                        iax = da.getElementLongAbs(it.aIndex + j);
14015                                                        ox = (short) toLong(Math.min(iax, ibx));
14016                                                        oai16data[it.oIndex + j] = ox;
14017                                                }
14018                                        }
14019                                }
14020                        } else if (as == 1) {
14021                                if (it.isOutputDouble()) {
14022                                        while (it.hasNext()) {
14023                                                final double iax = it.aDouble;
14024                                                final double ibx = it.bDouble;
14025                                                short ox;
14026                                                ox = (short) toLong(Math.min(iax, ibx));
14027                                                for (int j = 0; j < is; j++) {
14028                                                        oai16data[it.oIndex + j] = ox;
14029                                                }
14030                                        }
14031                                } else {
14032                                        while (it.hasNext()) {
14033                                                final long iax = it.aLong;
14034                                                final long ibx = it.bLong;
14035                                                short ox;
14036                                                ox = (short) toLong(Math.min(iax, ibx));
14037                                                for (int j = 0; j < is; j++) {
14038                                                        oai16data[it.oIndex + j] = ox;
14039                                                }
14040                                        }
14041                                }
14042                        } else {
14043                                if (it.isOutputDouble()) {
14044                                        while (it.hasNext()) {
14045                                                double iax = it.aDouble;
14046                                                double ibx = it.bDouble;
14047                                                short ox;
14048                                                ox = (short) toLong(Math.min(iax, ibx));
14049                                                oai16data[it.oIndex] = ox;
14050                                                for (int j = 1; j < is; j++) {
14051                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14052                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14053                                                        ox = (short) toLong(Math.min(iax, ibx));
14054                                                        oai16data[it.oIndex + j] = ox;
14055                                                }
14056                                        }
14057                                } else {
14058                                        while (it.hasNext()) {
14059                                                long iax = it.aLong;
14060                                                long ibx = it.bLong;
14061                                                short ox;
14062                                                ox = (short) toLong(Math.min(iax, ibx));
14063                                                oai16data[it.oIndex] = ox;
14064                                                for (int j = 1; j < is; j++) {
14065                                                        iax = da.getElementLongAbs(it.aIndex + j);
14066                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14067                                                        ox = (short) toLong(Math.min(iax, ibx));
14068                                                        oai16data[it.oIndex + j] = ox;
14069                                                }
14070                                        }
14071                                }
14072                        }
14073                        break;
14074                case Dataset.ARRAYINT64:
14075                        final long[] oai64data = ((CompoundLongDataset) result).getData();
14076                        if (is == 1) {
14077                                if (it.isOutputDouble()) {
14078                                        while (it.hasNext()) {
14079                                                final double iax = it.aDouble;
14080                                                final double ibx = it.bDouble;
14081                                                long ox;
14082                                                ox = toLong(Math.min(iax, ibx));
14083                                                oai64data[it.oIndex] = ox;
14084                                        }
14085                                } else {
14086                                        while (it.hasNext()) {
14087                                                final long iax = it.aLong;
14088                                                final long ibx = it.bLong;
14089                                                long ox;
14090                                                ox = toLong(Math.min(iax, ibx));
14091                                                oai64data[it.oIndex] = ox;
14092                                        }
14093                                }
14094                        } else if (as < bs) {
14095                                if (it.isOutputDouble()) {
14096                                        while (it.hasNext()) {
14097                                                final double iax = it.aDouble;
14098                                                double ibx = it.bDouble;
14099                                                long ox;
14100                                                ox = toLong(Math.min(iax, ibx));
14101                                                oai64data[it.oIndex] = ox;
14102                                                for (int j = 1; j < is; j++) {
14103                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14104                                                        ox = toLong(Math.min(iax, ibx));
14105                                                        oai64data[it.oIndex + j] = ox;
14106                                                }
14107                                        }
14108                                } else {
14109                                        while (it.hasNext()) {
14110                                                final long iax = it.aLong;
14111                                                long ibx = it.bLong;
14112                                                long ox;
14113                                                ox = toLong(Math.min(iax, ibx));
14114                                                oai64data[it.oIndex] = ox;
14115                                                for (int j = 1; j < is; j++) {
14116                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14117                                                        ox = toLong(Math.min(iax, ibx));
14118                                                        oai64data[it.oIndex + j] = ox;
14119                                                }
14120                                        }
14121                                }
14122                        } else if (as > bs) {
14123                                if (it.isOutputDouble()) {
14124                                        while (it.hasNext()) {
14125                                                double iax = it.aDouble;
14126                                                final double ibx = it.bDouble;
14127                                                long ox;
14128                                                ox = toLong(Math.min(iax, ibx));
14129                                                oai64data[it.oIndex] = ox;
14130                                                for (int j = 1; j < is; j++) {
14131                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14132                                                        ox = toLong(Math.min(iax, ibx));
14133                                                        oai64data[it.oIndex + j] = ox;
14134                                                }
14135                                        }
14136                                } else {
14137                                        while (it.hasNext()) {
14138                                                long iax = it.aLong;
14139                                                final long ibx = it.bLong;
14140                                                long ox;
14141                                                ox = toLong(Math.min(iax, ibx));
14142                                                oai64data[it.oIndex] = ox;
14143                                                for (int j = 1; j < is; j++) {
14144                                                        iax = da.getElementLongAbs(it.aIndex + j);
14145                                                        ox = toLong(Math.min(iax, ibx));
14146                                                        oai64data[it.oIndex + j] = ox;
14147                                                }
14148                                        }
14149                                }
14150                        } else if (as == 1) {
14151                                if (it.isOutputDouble()) {
14152                                        while (it.hasNext()) {
14153                                                final double iax = it.aDouble;
14154                                                final double ibx = it.bDouble;
14155                                                long ox;
14156                                                ox = toLong(Math.min(iax, ibx));
14157                                                for (int j = 0; j < is; j++) {
14158                                                        oai64data[it.oIndex + j] = ox;
14159                                                }
14160                                        }
14161                                } else {
14162                                        while (it.hasNext()) {
14163                                                final long iax = it.aLong;
14164                                                final long ibx = it.bLong;
14165                                                long ox;
14166                                                ox = toLong(Math.min(iax, ibx));
14167                                                for (int j = 0; j < is; j++) {
14168                                                        oai64data[it.oIndex + j] = ox;
14169                                                }
14170                                        }
14171                                }
14172                        } else {
14173                                if (it.isOutputDouble()) {
14174                                        while (it.hasNext()) {
14175                                                double iax = it.aDouble;
14176                                                double ibx = it.bDouble;
14177                                                long ox;
14178                                                ox = toLong(Math.min(iax, ibx));
14179                                                oai64data[it.oIndex] = ox;
14180                                                for (int j = 1; j < is; j++) {
14181                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14182                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14183                                                        ox = toLong(Math.min(iax, ibx));
14184                                                        oai64data[it.oIndex + j] = ox;
14185                                                }
14186                                        }
14187                                } else {
14188                                        while (it.hasNext()) {
14189                                                long iax = it.aLong;
14190                                                long ibx = it.bLong;
14191                                                long ox;
14192                                                ox = toLong(Math.min(iax, ibx));
14193                                                oai64data[it.oIndex] = ox;
14194                                                for (int j = 1; j < is; j++) {
14195                                                        iax = da.getElementLongAbs(it.aIndex + j);
14196                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14197                                                        ox = toLong(Math.min(iax, ibx));
14198                                                        oai64data[it.oIndex + j] = ox;
14199                                                }
14200                                        }
14201                                }
14202                        }
14203                        break;
14204                case Dataset.ARRAYINT32:
14205                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
14206                        if (is == 1) {
14207                                if (it.isOutputDouble()) {
14208                                        while (it.hasNext()) {
14209                                                final double iax = it.aDouble;
14210                                                final double ibx = it.bDouble;
14211                                                int ox;
14212                                                ox = (int) toLong(Math.min(iax, ibx));
14213                                                oai32data[it.oIndex] = ox;
14214                                        }
14215                                } else {
14216                                        while (it.hasNext()) {
14217                                                final long iax = it.aLong;
14218                                                final long ibx = it.bLong;
14219                                                int ox;
14220                                                ox = (int) toLong(Math.min(iax, ibx));
14221                                                oai32data[it.oIndex] = ox;
14222                                        }
14223                                }
14224                        } else if (as < bs) {
14225                                if (it.isOutputDouble()) {
14226                                        while (it.hasNext()) {
14227                                                final double iax = it.aDouble;
14228                                                double ibx = it.bDouble;
14229                                                int ox;
14230                                                ox = (int) toLong(Math.min(iax, ibx));
14231                                                oai32data[it.oIndex] = ox;
14232                                                for (int j = 1; j < is; j++) {
14233                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14234                                                        ox = (int) toLong(Math.min(iax, ibx));
14235                                                        oai32data[it.oIndex + j] = ox;
14236                                                }
14237                                        }
14238                                } else {
14239                                        while (it.hasNext()) {
14240                                                final long iax = it.aLong;
14241                                                long ibx = it.bLong;
14242                                                int ox;
14243                                                ox = (int) toLong(Math.min(iax, ibx));
14244                                                oai32data[it.oIndex] = ox;
14245                                                for (int j = 1; j < is; j++) {
14246                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14247                                                        ox = (int) toLong(Math.min(iax, ibx));
14248                                                        oai32data[it.oIndex + j] = ox;
14249                                                }
14250                                        }
14251                                }
14252                        } else if (as > bs) {
14253                                if (it.isOutputDouble()) {
14254                                        while (it.hasNext()) {
14255                                                double iax = it.aDouble;
14256                                                final double ibx = it.bDouble;
14257                                                int ox;
14258                                                ox = (int) toLong(Math.min(iax, ibx));
14259                                                oai32data[it.oIndex] = ox;
14260                                                for (int j = 1; j < is; j++) {
14261                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14262                                                        ox = (int) toLong(Math.min(iax, ibx));
14263                                                        oai32data[it.oIndex + j] = ox;
14264                                                }
14265                                        }
14266                                } else {
14267                                        while (it.hasNext()) {
14268                                                long iax = it.aLong;
14269                                                final long ibx = it.bLong;
14270                                                int ox;
14271                                                ox = (int) toLong(Math.min(iax, ibx));
14272                                                oai32data[it.oIndex] = ox;
14273                                                for (int j = 1; j < is; j++) {
14274                                                        iax = da.getElementLongAbs(it.aIndex + j);
14275                                                        ox = (int) toLong(Math.min(iax, ibx));
14276                                                        oai32data[it.oIndex + j] = ox;
14277                                                }
14278                                        }
14279                                }
14280                        } else if (as == 1) {
14281                                if (it.isOutputDouble()) {
14282                                        while (it.hasNext()) {
14283                                                final double iax = it.aDouble;
14284                                                final double ibx = it.bDouble;
14285                                                int ox;
14286                                                ox = (int) toLong(Math.min(iax, ibx));
14287                                                for (int j = 0; j < is; j++) {
14288                                                        oai32data[it.oIndex + j] = ox;
14289                                                }
14290                                        }
14291                                } else {
14292                                        while (it.hasNext()) {
14293                                                final long iax = it.aLong;
14294                                                final long ibx = it.bLong;
14295                                                int ox;
14296                                                ox = (int) toLong(Math.min(iax, ibx));
14297                                                for (int j = 0; j < is; j++) {
14298                                                        oai32data[it.oIndex + j] = ox;
14299                                                }
14300                                        }
14301                                }
14302                        } else {
14303                                if (it.isOutputDouble()) {
14304                                        while (it.hasNext()) {
14305                                                double iax = it.aDouble;
14306                                                double ibx = it.bDouble;
14307                                                int ox;
14308                                                ox = (int) toLong(Math.min(iax, ibx));
14309                                                oai32data[it.oIndex] = ox;
14310                                                for (int j = 1; j < is; j++) {
14311                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14312                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14313                                                        ox = (int) toLong(Math.min(iax, ibx));
14314                                                        oai32data[it.oIndex + j] = ox;
14315                                                }
14316                                        }
14317                                } else {
14318                                        while (it.hasNext()) {
14319                                                long iax = it.aLong;
14320                                                long ibx = it.bLong;
14321                                                int ox;
14322                                                ox = (int) toLong(Math.min(iax, ibx));
14323                                                oai32data[it.oIndex] = ox;
14324                                                for (int j = 1; j < is; j++) {
14325                                                        iax = da.getElementLongAbs(it.aIndex + j);
14326                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14327                                                        ox = (int) toLong(Math.min(iax, ibx));
14328                                                        oai32data[it.oIndex + j] = ox;
14329                                                }
14330                                        }
14331                                }
14332                        }
14333                        break;
14334                case Dataset.FLOAT32:
14335                        final float[] of32data = ((FloatDataset) result).getData();
14336                        if (it.isOutputDouble()) {
14337                                while (it.hasNext()) {
14338                                        final double iax = it.aDouble;
14339                                        final double ibx = it.bDouble;
14340                                        float ox;
14341                                        ox = (float) (Math.min(iax, ibx));
14342                                        of32data[it.oIndex] = ox;
14343                                }
14344                        } else {
14345                                while (it.hasNext()) {
14346                                        final long iax = it.aLong;
14347                                        final long ibx = it.bLong;
14348                                        float ox;
14349                                        ox = (float) (Math.min(iax, ibx));
14350                                        of32data[it.oIndex] = ox;
14351                                }
14352                        }
14353                        break;
14354                case Dataset.FLOAT64:
14355                        final double[] of64data = ((DoubleDataset) result).getData();
14356                        if (it.isOutputDouble()) {
14357                                while (it.hasNext()) {
14358                                        final double iax = it.aDouble;
14359                                        final double ibx = it.bDouble;
14360                                        double ox;
14361                                        ox = (Math.min(iax, ibx));
14362                                        of64data[it.oIndex] = ox;
14363                                }
14364                        } else {
14365                                while (it.hasNext()) {
14366                                        final long iax = it.aLong;
14367                                        final long ibx = it.bLong;
14368                                        double ox;
14369                                        ox = (Math.min(iax, ibx));
14370                                        of64data[it.oIndex] = ox;
14371                                }
14372                        }
14373                        break;
14374                case Dataset.ARRAYFLOAT32:
14375                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
14376                        if (is == 1) {
14377                                if (it.isOutputDouble()) {
14378                                        while (it.hasNext()) {
14379                                                final double iax = it.aDouble;
14380                                                final double ibx = it.bDouble;
14381                                                float ox;
14382                                                ox = (float) (Math.min(iax, ibx));
14383                                                oaf32data[it.oIndex] = ox;
14384                                        }
14385                                } else {
14386                                        while (it.hasNext()) {
14387                                                final long iax = it.aLong;
14388                                                final long ibx = it.bLong;
14389                                                float ox;
14390                                                ox = (float) (Math.min(iax, ibx));
14391                                                oaf32data[it.oIndex] = ox;
14392                                        }
14393                                }
14394                        } else if (as < bs) {
14395                                if (it.isOutputDouble()) {
14396                                        while (it.hasNext()) {
14397                                                final double iax = it.aDouble;
14398                                                double ibx = it.bDouble;
14399                                                float ox;
14400                                                ox = (float) (Math.min(iax, ibx));
14401                                                oaf32data[it.oIndex] = ox;
14402                                                for (int j = 1; j < is; j++) {
14403                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14404                                                        ox = (float) (Math.min(iax, ibx));
14405                                                        oaf32data[it.oIndex + j] = ox;
14406                                                }
14407                                        }
14408                                } else {
14409                                        while (it.hasNext()) {
14410                                                final long iax = it.aLong;
14411                                                long ibx = it.bLong;
14412                                                float ox;
14413                                                ox = (float) (Math.min(iax, ibx));
14414                                                oaf32data[it.oIndex] = ox;
14415                                                for (int j = 1; j < is; j++) {
14416                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14417                                                        ox = (float) (Math.min(iax, ibx));
14418                                                        oaf32data[it.oIndex + j] = ox;
14419                                                }
14420                                        }
14421                                }
14422                        } else if (as > bs) {
14423                                if (it.isOutputDouble()) {
14424                                        while (it.hasNext()) {
14425                                                double iax = it.aDouble;
14426                                                final double ibx = it.bDouble;
14427                                                float ox;
14428                                                ox = (float) (Math.min(iax, ibx));
14429                                                oaf32data[it.oIndex] = ox;
14430                                                for (int j = 1; j < is; j++) {
14431                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14432                                                        ox = (float) (Math.min(iax, ibx));
14433                                                        oaf32data[it.oIndex + j] = ox;
14434                                                }
14435                                        }
14436                                } else {
14437                                        while (it.hasNext()) {
14438                                                long iax = it.aLong;
14439                                                final long ibx = it.bLong;
14440                                                float ox;
14441                                                ox = (float) (Math.min(iax, ibx));
14442                                                oaf32data[it.oIndex] = ox;
14443                                                for (int j = 1; j < is; j++) {
14444                                                        iax = da.getElementLongAbs(it.aIndex + j);
14445                                                        ox = (float) (Math.min(iax, ibx));
14446                                                        oaf32data[it.oIndex + j] = ox;
14447                                                }
14448                                        }
14449                                }
14450                        } else if (as == 1) {
14451                                if (it.isOutputDouble()) {
14452                                        while (it.hasNext()) {
14453                                                final double iax = it.aDouble;
14454                                                final double ibx = it.bDouble;
14455                                                float ox;
14456                                                ox = (float) (Math.min(iax, ibx));
14457                                                for (int j = 0; j < is; j++) {
14458                                                        oaf32data[it.oIndex + j] = ox;
14459                                                }
14460                                        }
14461                                } else {
14462                                        while (it.hasNext()) {
14463                                                final long iax = it.aLong;
14464                                                final long ibx = it.bLong;
14465                                                float ox;
14466                                                ox = (float) (Math.min(iax, ibx));
14467                                                for (int j = 0; j < is; j++) {
14468                                                        oaf32data[it.oIndex + j] = ox;
14469                                                }
14470                                        }
14471                                }
14472                        } else {
14473                                if (it.isOutputDouble()) {
14474                                        while (it.hasNext()) {
14475                                                double iax = it.aDouble;
14476                                                double ibx = it.bDouble;
14477                                                float ox;
14478                                                ox = (float) (Math.min(iax, ibx));
14479                                                oaf32data[it.oIndex] = ox;
14480                                                for (int j = 1; j < is; j++) {
14481                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14482                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14483                                                        ox = (float) (Math.min(iax, ibx));
14484                                                        oaf32data[it.oIndex + j] = ox;
14485                                                }
14486                                        }
14487                                } else {
14488                                        while (it.hasNext()) {
14489                                                long iax = it.aLong;
14490                                                long ibx = it.bLong;
14491                                                float ox;
14492                                                ox = (float) (Math.min(iax, ibx));
14493                                                oaf32data[it.oIndex] = ox;
14494                                                for (int j = 1; j < is; j++) {
14495                                                        iax = da.getElementLongAbs(it.aIndex + j);
14496                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14497                                                        ox = (float) (Math.min(iax, ibx));
14498                                                        oaf32data[it.oIndex + j] = ox;
14499                                                }
14500                                        }
14501                                }
14502                        }
14503                        break;
14504                case Dataset.ARRAYFLOAT64:
14505                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
14506                        if (is == 1) {
14507                                if (it.isOutputDouble()) {
14508                                        while (it.hasNext()) {
14509                                                final double iax = it.aDouble;
14510                                                final double ibx = it.bDouble;
14511                                                double ox;
14512                                                ox = (Math.min(iax, ibx));
14513                                                oaf64data[it.oIndex] = ox;
14514                                        }
14515                                } else {
14516                                        while (it.hasNext()) {
14517                                                final long iax = it.aLong;
14518                                                final long ibx = it.bLong;
14519                                                double ox;
14520                                                ox = (Math.min(iax, ibx));
14521                                                oaf64data[it.oIndex] = ox;
14522                                        }
14523                                }
14524                        } else if (as < bs) {
14525                                if (it.isOutputDouble()) {
14526                                        while (it.hasNext()) {
14527                                                final double iax = it.aDouble;
14528                                                double ibx = it.bDouble;
14529                                                double ox;
14530                                                ox = (Math.min(iax, ibx));
14531                                                oaf64data[it.oIndex] = ox;
14532                                                for (int j = 1; j < is; j++) {
14533                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14534                                                        ox = (Math.min(iax, ibx));
14535                                                        oaf64data[it.oIndex + j] = ox;
14536                                                }
14537                                        }
14538                                } else {
14539                                        while (it.hasNext()) {
14540                                                final long iax = it.aLong;
14541                                                long ibx = it.bLong;
14542                                                double ox;
14543                                                ox = (Math.min(iax, ibx));
14544                                                oaf64data[it.oIndex] = ox;
14545                                                for (int j = 1; j < is; j++) {
14546                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14547                                                        ox = (Math.min(iax, ibx));
14548                                                        oaf64data[it.oIndex + j] = ox;
14549                                                }
14550                                        }
14551                                }
14552                        } else if (as > bs) {
14553                                if (it.isOutputDouble()) {
14554                                        while (it.hasNext()) {
14555                                                double iax = it.aDouble;
14556                                                final double ibx = it.bDouble;
14557                                                double ox;
14558                                                ox = (Math.min(iax, ibx));
14559                                                oaf64data[it.oIndex] = ox;
14560                                                for (int j = 1; j < is; j++) {
14561                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14562                                                        ox = (Math.min(iax, ibx));
14563                                                        oaf64data[it.oIndex + j] = ox;
14564                                                }
14565                                        }
14566                                } else {
14567                                        while (it.hasNext()) {
14568                                                long iax = it.aLong;
14569                                                final long ibx = it.bLong;
14570                                                double ox;
14571                                                ox = (Math.min(iax, ibx));
14572                                                oaf64data[it.oIndex] = ox;
14573                                                for (int j = 1; j < is; j++) {
14574                                                        iax = da.getElementLongAbs(it.aIndex + j);
14575                                                        ox = (Math.min(iax, ibx));
14576                                                        oaf64data[it.oIndex + j] = ox;
14577                                                }
14578                                        }
14579                                }
14580                        } else if (as == 1) {
14581                                if (it.isOutputDouble()) {
14582                                        while (it.hasNext()) {
14583                                                final double iax = it.aDouble;
14584                                                final double ibx = it.bDouble;
14585                                                double ox;
14586                                                ox = (Math.min(iax, ibx));
14587                                                for (int j = 0; j < is; j++) {
14588                                                        oaf64data[it.oIndex + j] = ox;
14589                                                }
14590                                        }
14591                                } else {
14592                                        while (it.hasNext()) {
14593                                                final long iax = it.aLong;
14594                                                final long ibx = it.bLong;
14595                                                double ox;
14596                                                ox = (Math.min(iax, ibx));
14597                                                for (int j = 0; j < is; j++) {
14598                                                        oaf64data[it.oIndex + j] = ox;
14599                                                }
14600                                        }
14601                                }
14602                        } else {
14603                                if (it.isOutputDouble()) {
14604                                        while (it.hasNext()) {
14605                                                double iax = it.aDouble;
14606                                                double ibx = it.bDouble;
14607                                                double ox;
14608                                                ox = (Math.min(iax, ibx));
14609                                                oaf64data[it.oIndex] = ox;
14610                                                for (int j = 1; j < is; j++) {
14611                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
14612                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
14613                                                        ox = (Math.min(iax, ibx));
14614                                                        oaf64data[it.oIndex + j] = ox;
14615                                                }
14616                                        }
14617                                } else {
14618                                        while (it.hasNext()) {
14619                                                long iax = it.aLong;
14620                                                long ibx = it.bLong;
14621                                                double ox;
14622                                                ox = (Math.min(iax, ibx));
14623                                                oaf64data[it.oIndex] = ox;
14624                                                for (int j = 1; j < is; j++) {
14625                                                        iax = da.getElementLongAbs(it.aIndex + j);
14626                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14627                                                        ox = (Math.min(iax, ibx));
14628                                                        oaf64data[it.oIndex + j] = ox;
14629                                                }
14630                                        }
14631                                }
14632                        }
14633                        break;
14634                case Dataset.COMPLEX64:
14635                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
14636                        if (!da.isComplex()) {
14637                                if (it.isOutputDouble()) {
14638                                        final double iay = 0;
14639                                        if (db.isComplex()) {
14640                                                while (it.hasNext()) {
14641                                                        final double iax = it.aDouble;
14642                                                        final double ibx = it.bDouble;
14643                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
14644                                                        float ox;
14645                                                        float oy;
14646                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
14647                                                                ox = (float) (iax);
14648                                                                oy = (float) (iay);
14649                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
14650                                                                ox = (float) (ibx);
14651                                                                oy = (float) (iby);
14652                                                        } else {
14653                                                                ox = (float) (Math.min(iax, ibx));
14654                                                                oy = (float) (Math.min(iay, iby));
14655                                                        }
14656                                                        oc64data[it.oIndex] = ox;
14657                                                        oc64data[it.oIndex + 1] = oy;
14658                                                }
14659                                        } else {
14660                                                while (it.hasNext()) {
14661                                                        final double iax = it.aDouble;
14662                                                        final double ibx = it.bDouble;
14663                                                        final double iby = 0;
14664                                                        float ox;
14665                                                        float oy;
14666                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
14667                                                                ox = (float) (iax);
14668                                                                oy = (float) (iay);
14669                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
14670                                                                ox = (float) (ibx);
14671                                                                oy = (float) (iby);
14672                                                        } else {
14673                                                                ox = (float) (Math.min(iax, ibx));
14674                                                                oy = (float) (Math.min(iay, iby));
14675                                                        }
14676                                                        oc64data[it.oIndex] = ox;
14677                                                        oc64data[it.oIndex + 1] = oy;
14678                                                }
14679                                        }
14680                                } else {
14681                                        final long iay = 0;
14682                                        while (it.hasNext()) {
14683                                                final long iax = it.aLong;
14684                                                final long ibx = it.bLong;
14685                                                final long iby = 0;
14686                                                float ox;
14687                                                float oy;
14688                                                if (Double.isNaN(iax) || Double.isNaN(iay)) {
14689                                                        ox = (float) (iax);
14690                                                        oy = (float) (iay);
14691                                                } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
14692                                                        ox = (float) (ibx);
14693                                                        oy = (float) (iby);
14694                                                } else {
14695                                                        ox = (float) (Math.min(iax, ibx));
14696                                                        oy = (float) (Math.min(iay, iby));
14697                                                }
14698                                                oc64data[it.oIndex] = ox;
14699                                                oc64data[it.oIndex + 1] = oy;
14700                                        }
14701                                }
14702                        } else if (!db.isComplex()) {
14703                                final double iby = 0;
14704                                while (it.hasNext()) {
14705                                        final double iax = it.aDouble;
14706                                        final double ibx = it.bDouble;
14707                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
14708                                        float ox;
14709                                        float oy;
14710                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
14711                                                ox = (float) (iax);
14712                                                oy = (float) (iay);
14713                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
14714                                                ox = (float) (ibx);
14715                                                oy = (float) (iby);
14716                                        } else {
14717                                                ox = (float) (Math.min(iax, ibx));
14718                                                oy = (float) (Math.min(iay, iby));
14719                                        }
14720                                        oc64data[it.oIndex] = ox;
14721                                        oc64data[it.oIndex + 1] = oy;
14722                                }
14723                        } else {
14724                                while (it.hasNext()) {
14725                                        final double iax = it.aDouble;
14726                                        final double ibx = it.bDouble;
14727                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
14728                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
14729                                        float ox;
14730                                        float oy;
14731                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
14732                                                ox = (float) (iax);
14733                                                oy = (float) (iay);
14734                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
14735                                                ox = (float) (ibx);
14736                                                oy = (float) (iby);
14737                                        } else {
14738                                                ox = (float) (Math.min(iax, ibx));
14739                                                oy = (float) (Math.min(iay, iby));
14740                                        }
14741                                        oc64data[it.oIndex] = ox;
14742                                        oc64data[it.oIndex + 1] = oy;
14743                                }
14744                        }
14745                        break;
14746                case Dataset.COMPLEX128:
14747                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
14748                        if (!da.isComplex()) {
14749                                if (it.isOutputDouble()) {
14750                                        final double iay = 0;
14751                                        if (db.isComplex()) {
14752                                                while (it.hasNext()) {
14753                                                        final double iax = it.aDouble;
14754                                                        final double ibx = it.bDouble;
14755                                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
14756                                                        double ox;
14757                                                        double oy;
14758                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
14759                                                                ox = (iax);
14760                                                                oy = (iay);
14761                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
14762                                                                ox = (ibx);
14763                                                                oy = (iby);
14764                                                        } else {
14765                                                                ox = (Math.min(iax, ibx));
14766                                                                oy = (Math.min(iay, iby));
14767                                                        }
14768                                                        oc128data[it.oIndex] = ox;
14769                                                        oc128data[it.oIndex + 1] = oy;
14770                                                }
14771                                        } else {
14772                                                while (it.hasNext()) {
14773                                                        final double iax = it.aDouble;
14774                                                        final double ibx = it.bDouble;
14775                                                        final double iby = 0;
14776                                                        double ox;
14777                                                        double oy;
14778                                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
14779                                                                ox = (iax);
14780                                                                oy = (iay);
14781                                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
14782                                                                ox = (ibx);
14783                                                                oy = (iby);
14784                                                        } else {
14785                                                                ox = (Math.min(iax, ibx));
14786                                                                oy = (Math.min(iay, iby));
14787                                                        }
14788                                                        oc128data[it.oIndex] = ox;
14789                                                        oc128data[it.oIndex + 1] = oy;
14790                                                }
14791                                        }
14792                                } else {
14793                                        final long iay = 0;
14794                                        while (it.hasNext()) {
14795                                                final long iax = it.aLong;
14796                                                final long ibx = it.bLong;
14797                                                final long iby = 0;
14798                                                double ox;
14799                                                double oy;
14800                                                if (Double.isNaN(iax) || Double.isNaN(iay)) {
14801                                                        ox = (iax);
14802                                                        oy = (iay);
14803                                                } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
14804                                                        ox = (ibx);
14805                                                        oy = (iby);
14806                                                } else {
14807                                                        ox = (double) (Math.min(iax, ibx));
14808                                                        oy = (double) (Math.min(iay, iby));
14809                                                }
14810                                                oc128data[it.oIndex] = ox;
14811                                                oc128data[it.oIndex + 1] = oy;
14812                                        }
14813                                }
14814                        } else if (!db.isComplex()) {
14815                                final double iby = 0;
14816                                while (it.hasNext()) {
14817                                        final double iax = it.aDouble;
14818                                        final double ibx = it.bDouble;
14819                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
14820                                        double ox;
14821                                        double oy;
14822                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
14823                                                ox = (iax);
14824                                                oy = (iay);
14825                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
14826                                                ox = (ibx);
14827                                                oy = (iby);
14828                                        } else {
14829                                                ox = (Math.min(iax, ibx));
14830                                                oy = (Math.min(iay, iby));
14831                                        }
14832                                        oc128data[it.oIndex] = ox;
14833                                        oc128data[it.oIndex + 1] = oy;
14834                                }
14835                        } else {
14836                                while (it.hasNext()) {
14837                                        final double iax = it.aDouble;
14838                                        final double ibx = it.bDouble;
14839                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
14840                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
14841                                        double ox;
14842                                        double oy;
14843                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
14844                                                ox = (iax);
14845                                                oy = (iay);
14846                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
14847                                                ox = (ibx);
14848                                                oy = (iby);
14849                                        } else {
14850                                                ox = (Math.min(iax, ibx));
14851                                                oy = (Math.min(iay, iby));
14852                                        }
14853                                        oc128data[it.oIndex] = ox;
14854                                        oc128data[it.oIndex + 1] = oy;
14855                                }
14856                        }
14857                        break;
14858                default:
14859                        throw new IllegalArgumentException("minimum supports integer, compound integer, real, compound real, complex datasets only");
14860                }
14861
14862                addBinaryOperatorName(da, db, result, "minimum");
14863                return result;
14864        }
14865
14866        /**
14867         * bitwiseAnd operator
14868         * @param a first operand
14869         * @param b second operand
14870         * @return {@code a & b}, bitwise AND of a and b
14871         */
14872        public static Dataset bitwiseAnd(final Object a, final Object b) {
14873                return bitwiseAnd(a, b, null);
14874        }
14875
14876        /**
14877         * bitwiseAnd operator
14878         * @param a first operand
14879         * @param b second operand
14880         * @param o output can be null - in which case, a new dataset is created
14881         * @return {@code a & b}, bitwise AND of a and b
14882         */
14883        public static Dataset bitwiseAnd(final Object a, final Object b, final Dataset o) {
14884                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
14885                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
14886                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
14887                it.setOutputDouble(false);
14888                final Dataset result = it.getOutput();
14889                if (!result.isComplex()) {
14890                        boolean change = false;
14891                        if (da.isComplex()) {
14892                                da = da.getRealView();
14893                                change = true;
14894                        }
14895                        if (db.isComplex()) {
14896                                db = db.getRealView();
14897                                change = true;
14898                        }
14899                        if (change) {
14900                                it = BroadcastIterator.createIterator(da, db, result, true);
14901                                it.setOutputDouble(false);
14902                        }
14903                }
14904                final int is = result.getElementsPerItem();
14905                final int as = da.getElementsPerItem();
14906                final int bs = db.getElementsPerItem();
14907                final int dt = result.getDType();
14908
14909                switch(dt) {
14910                case Dataset.INT8:
14911                        final byte[] oi8data = ((ByteDataset) result).getData();
14912                        {
14913                                while (it.hasNext()) {
14914                                        final long iax = it.aLong;
14915                                        final long ibx = it.bLong;
14916                                        byte ox;
14917                                        ox = (byte) (iax & ibx);
14918                                        oi8data[it.oIndex] = ox;
14919                                }
14920                        }
14921                        break;
14922                case Dataset.INT16:
14923                        final short[] oi16data = ((ShortDataset) result).getData();
14924                        {
14925                                while (it.hasNext()) {
14926                                        final long iax = it.aLong;
14927                                        final long ibx = it.bLong;
14928                                        short ox;
14929                                        ox = (short) (iax & ibx);
14930                                        oi16data[it.oIndex] = ox;
14931                                }
14932                        }
14933                        break;
14934                case Dataset.INT64:
14935                        final long[] oi64data = ((LongDataset) result).getData();
14936                        {
14937                                while (it.hasNext()) {
14938                                        final long iax = it.aLong;
14939                                        final long ibx = it.bLong;
14940                                        long ox;
14941                                        ox = (iax & ibx);
14942                                        oi64data[it.oIndex] = ox;
14943                                }
14944                        }
14945                        break;
14946                case Dataset.INT32:
14947                        final int[] oi32data = ((IntegerDataset) result).getData();
14948                        {
14949                                while (it.hasNext()) {
14950                                        final long iax = it.aLong;
14951                                        final long ibx = it.bLong;
14952                                        int ox;
14953                                        ox = (int) (iax & ibx);
14954                                        oi32data[it.oIndex] = ox;
14955                                }
14956                        }
14957                        break;
14958                case Dataset.ARRAYINT8:
14959                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
14960                        if (is == 1) {
14961                                {
14962                                        while (it.hasNext()) {
14963                                                final long iax = it.aLong;
14964                                                final long ibx = it.bLong;
14965                                                byte ox;
14966                                                ox = (byte) (iax & ibx);
14967                                                oai8data[it.oIndex] = ox;
14968                                        }
14969                                }
14970                        } else if (as < bs) {
14971                                {
14972                                        while (it.hasNext()) {
14973                                                final long iax = it.aLong;
14974                                                long ibx = it.bLong;
14975                                                byte ox;
14976                                                ox = (byte) (iax & ibx);
14977                                                oai8data[it.oIndex] = ox;
14978                                                for (int j = 1; j < is; j++) {
14979                                                        ibx = db.getElementLongAbs(it.bIndex + j);
14980                                                        ox = (byte) (iax & ibx);
14981                                                        oai8data[it.oIndex + j] = ox;
14982                                                }
14983                                        }
14984                                }
14985                        } else if (as > bs) {
14986                                {
14987                                        while (it.hasNext()) {
14988                                                long iax = it.aLong;
14989                                                final long ibx = it.bLong;
14990                                                byte ox;
14991                                                ox = (byte) (iax & ibx);
14992                                                oai8data[it.oIndex] = ox;
14993                                                for (int j = 1; j < is; j++) {
14994                                                        iax = da.getElementLongAbs(it.aIndex + j);
14995                                                        ox = (byte) (iax & ibx);
14996                                                        oai8data[it.oIndex + j] = ox;
14997                                                }
14998                                        }
14999                                }
15000                        } else if (as == 1) {
15001                                {
15002                                        while (it.hasNext()) {
15003                                                final long iax = it.aLong;
15004                                                final long ibx = it.bLong;
15005                                                byte ox;
15006                                                ox = (byte) (iax & ibx);
15007                                                for (int j = 0; j < is; j++) {
15008                                                        oai8data[it.oIndex + j] = ox;
15009                                                }
15010                                        }
15011                                }
15012                        } else {
15013                                {
15014                                        while (it.hasNext()) {
15015                                                long iax = it.aLong;
15016                                                long ibx = it.bLong;
15017                                                byte ox;
15018                                                ox = (byte) (iax & ibx);
15019                                                oai8data[it.oIndex] = ox;
15020                                                for (int j = 1; j < is; j++) {
15021                                                        iax = da.getElementLongAbs(it.aIndex + j);
15022                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15023                                                        ox = (byte) (iax & ibx);
15024                                                        oai8data[it.oIndex + j] = ox;
15025                                                }
15026                                        }
15027                                }
15028                        }
15029                        break;
15030                case Dataset.ARRAYINT16:
15031                        final short[] oai16data = ((CompoundShortDataset) result).getData();
15032                        if (is == 1) {
15033                                {
15034                                        while (it.hasNext()) {
15035                                                final long iax = it.aLong;
15036                                                final long ibx = it.bLong;
15037                                                short ox;
15038                                                ox = (short) (iax & ibx);
15039                                                oai16data[it.oIndex] = ox;
15040                                        }
15041                                }
15042                        } else if (as < bs) {
15043                                {
15044                                        while (it.hasNext()) {
15045                                                final long iax = it.aLong;
15046                                                long ibx = it.bLong;
15047                                                short ox;
15048                                                ox = (short) (iax & ibx);
15049                                                oai16data[it.oIndex] = ox;
15050                                                for (int j = 1; j < is; j++) {
15051                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15052                                                        ox = (short) (iax & ibx);
15053                                                        oai16data[it.oIndex + j] = ox;
15054                                                }
15055                                        }
15056                                }
15057                        } else if (as > bs) {
15058                                {
15059                                        while (it.hasNext()) {
15060                                                long iax = it.aLong;
15061                                                final long ibx = it.bLong;
15062                                                short ox;
15063                                                ox = (short) (iax & ibx);
15064                                                oai16data[it.oIndex] = ox;
15065                                                for (int j = 1; j < is; j++) {
15066                                                        iax = da.getElementLongAbs(it.aIndex + j);
15067                                                        ox = (short) (iax & ibx);
15068                                                        oai16data[it.oIndex + j] = ox;
15069                                                }
15070                                        }
15071                                }
15072                        } else if (as == 1) {
15073                                {
15074                                        while (it.hasNext()) {
15075                                                final long iax = it.aLong;
15076                                                final long ibx = it.bLong;
15077                                                short ox;
15078                                                ox = (short) (iax & ibx);
15079                                                for (int j = 0; j < is; j++) {
15080                                                        oai16data[it.oIndex + j] = ox;
15081                                                }
15082                                        }
15083                                }
15084                        } else {
15085                                {
15086                                        while (it.hasNext()) {
15087                                                long iax = it.aLong;
15088                                                long ibx = it.bLong;
15089                                                short ox;
15090                                                ox = (short) (iax & ibx);
15091                                                oai16data[it.oIndex] = ox;
15092                                                for (int j = 1; j < is; j++) {
15093                                                        iax = da.getElementLongAbs(it.aIndex + j);
15094                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15095                                                        ox = (short) (iax & ibx);
15096                                                        oai16data[it.oIndex + j] = ox;
15097                                                }
15098                                        }
15099                                }
15100                        }
15101                        break;
15102                case Dataset.ARRAYINT64:
15103                        final long[] oai64data = ((CompoundLongDataset) result).getData();
15104                        if (is == 1) {
15105                                {
15106                                        while (it.hasNext()) {
15107                                                final long iax = it.aLong;
15108                                                final long ibx = it.bLong;
15109                                                long ox;
15110                                                ox = (iax & ibx);
15111                                                oai64data[it.oIndex] = ox;
15112                                        }
15113                                }
15114                        } else if (as < bs) {
15115                                {
15116                                        while (it.hasNext()) {
15117                                                final long iax = it.aLong;
15118                                                long ibx = it.bLong;
15119                                                long ox;
15120                                                ox = (iax & ibx);
15121                                                oai64data[it.oIndex] = ox;
15122                                                for (int j = 1; j < is; j++) {
15123                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15124                                                        ox = (iax & ibx);
15125                                                        oai64data[it.oIndex + j] = ox;
15126                                                }
15127                                        }
15128                                }
15129                        } else if (as > bs) {
15130                                {
15131                                        while (it.hasNext()) {
15132                                                long iax = it.aLong;
15133                                                final long ibx = it.bLong;
15134                                                long ox;
15135                                                ox = (iax & ibx);
15136                                                oai64data[it.oIndex] = ox;
15137                                                for (int j = 1; j < is; j++) {
15138                                                        iax = da.getElementLongAbs(it.aIndex + j);
15139                                                        ox = (iax & ibx);
15140                                                        oai64data[it.oIndex + j] = ox;
15141                                                }
15142                                        }
15143                                }
15144                        } else if (as == 1) {
15145                                {
15146                                        while (it.hasNext()) {
15147                                                final long iax = it.aLong;
15148                                                final long ibx = it.bLong;
15149                                                long ox;
15150                                                ox = (iax & ibx);
15151                                                for (int j = 0; j < is; j++) {
15152                                                        oai64data[it.oIndex + j] = ox;
15153                                                }
15154                                        }
15155                                }
15156                        } else {
15157                                {
15158                                        while (it.hasNext()) {
15159                                                long iax = it.aLong;
15160                                                long ibx = it.bLong;
15161                                                long ox;
15162                                                ox = (iax & ibx);
15163                                                oai64data[it.oIndex] = ox;
15164                                                for (int j = 1; j < is; j++) {
15165                                                        iax = da.getElementLongAbs(it.aIndex + j);
15166                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15167                                                        ox = (iax & ibx);
15168                                                        oai64data[it.oIndex + j] = ox;
15169                                                }
15170                                        }
15171                                }
15172                        }
15173                        break;
15174                case Dataset.ARRAYINT32:
15175                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
15176                        if (is == 1) {
15177                                {
15178                                        while (it.hasNext()) {
15179                                                final long iax = it.aLong;
15180                                                final long ibx = it.bLong;
15181                                                int ox;
15182                                                ox = (int) (iax & ibx);
15183                                                oai32data[it.oIndex] = ox;
15184                                        }
15185                                }
15186                        } else if (as < bs) {
15187                                {
15188                                        while (it.hasNext()) {
15189                                                final long iax = it.aLong;
15190                                                long ibx = it.bLong;
15191                                                int ox;
15192                                                ox = (int) (iax & ibx);
15193                                                oai32data[it.oIndex] = ox;
15194                                                for (int j = 1; j < is; j++) {
15195                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15196                                                        ox = (int) (iax & ibx);
15197                                                        oai32data[it.oIndex + j] = ox;
15198                                                }
15199                                        }
15200                                }
15201                        } else if (as > bs) {
15202                                {
15203                                        while (it.hasNext()) {
15204                                                long iax = it.aLong;
15205                                                final long ibx = it.bLong;
15206                                                int ox;
15207                                                ox = (int) (iax & ibx);
15208                                                oai32data[it.oIndex] = ox;
15209                                                for (int j = 1; j < is; j++) {
15210                                                        iax = da.getElementLongAbs(it.aIndex + j);
15211                                                        ox = (int) (iax & ibx);
15212                                                        oai32data[it.oIndex + j] = ox;
15213                                                }
15214                                        }
15215                                }
15216                        } else if (as == 1) {
15217                                {
15218                                        while (it.hasNext()) {
15219                                                final long iax = it.aLong;
15220                                                final long ibx = it.bLong;
15221                                                int ox;
15222                                                ox = (int) (iax & ibx);
15223                                                for (int j = 0; j < is; j++) {
15224                                                        oai32data[it.oIndex + j] = ox;
15225                                                }
15226                                        }
15227                                }
15228                        } else {
15229                                {
15230                                        while (it.hasNext()) {
15231                                                long iax = it.aLong;
15232                                                long ibx = it.bLong;
15233                                                int ox;
15234                                                ox = (int) (iax & ibx);
15235                                                oai32data[it.oIndex] = ox;
15236                                                for (int j = 1; j < is; j++) {
15237                                                        iax = da.getElementLongAbs(it.aIndex + j);
15238                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15239                                                        ox = (int) (iax & ibx);
15240                                                        oai32data[it.oIndex + j] = ox;
15241                                                }
15242                                        }
15243                                }
15244                        }
15245                        break;
15246                default:
15247                        throw new IllegalArgumentException("bitwiseAnd supports integer, compound integer datasets only");
15248                }
15249
15250                addBinaryOperatorName(da, db, result, "&");
15251                return result;
15252        }
15253
15254        /**
15255         * bitwiseOr operator
15256         * @param a first operand
15257         * @param b second operand
15258         * @return {@code a | b}, bitwise inclusive OR of a and b
15259         */
15260        public static Dataset bitwiseOr(final Object a, final Object b) {
15261                return bitwiseOr(a, b, null);
15262        }
15263
15264        /**
15265         * bitwiseOr operator
15266         * @param a first operand
15267         * @param b second operand
15268         * @param o output can be null - in which case, a new dataset is created
15269         * @return {@code a | b}, bitwise inclusive OR of a and b
15270         */
15271        public static Dataset bitwiseOr(final Object a, final Object b, final Dataset o) {
15272                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
15273                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
15274                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
15275                it.setOutputDouble(false);
15276                final Dataset result = it.getOutput();
15277                if (!result.isComplex()) {
15278                        boolean change = false;
15279                        if (da.isComplex()) {
15280                                da = da.getRealView();
15281                                change = true;
15282                        }
15283                        if (db.isComplex()) {
15284                                db = db.getRealView();
15285                                change = true;
15286                        }
15287                        if (change) {
15288                                it = BroadcastIterator.createIterator(da, db, result, true);
15289                                it.setOutputDouble(false);
15290                        }
15291                }
15292                final int is = result.getElementsPerItem();
15293                final int as = da.getElementsPerItem();
15294                final int bs = db.getElementsPerItem();
15295                final int dt = result.getDType();
15296
15297                switch(dt) {
15298                case Dataset.INT8:
15299                        final byte[] oi8data = ((ByteDataset) result).getData();
15300                        {
15301                                while (it.hasNext()) {
15302                                        final long iax = it.aLong;
15303                                        final long ibx = it.bLong;
15304                                        byte ox;
15305                                        ox = (byte) (iax | ibx);
15306                                        oi8data[it.oIndex] = ox;
15307                                }
15308                        }
15309                        break;
15310                case Dataset.INT16:
15311                        final short[] oi16data = ((ShortDataset) result).getData();
15312                        {
15313                                while (it.hasNext()) {
15314                                        final long iax = it.aLong;
15315                                        final long ibx = it.bLong;
15316                                        short ox;
15317                                        ox = (short) (iax | ibx);
15318                                        oi16data[it.oIndex] = ox;
15319                                }
15320                        }
15321                        break;
15322                case Dataset.INT64:
15323                        final long[] oi64data = ((LongDataset) result).getData();
15324                        {
15325                                while (it.hasNext()) {
15326                                        final long iax = it.aLong;
15327                                        final long ibx = it.bLong;
15328                                        long ox;
15329                                        ox = (iax | ibx);
15330                                        oi64data[it.oIndex] = ox;
15331                                }
15332                        }
15333                        break;
15334                case Dataset.INT32:
15335                        final int[] oi32data = ((IntegerDataset) result).getData();
15336                        {
15337                                while (it.hasNext()) {
15338                                        final long iax = it.aLong;
15339                                        final long ibx = it.bLong;
15340                                        int ox;
15341                                        ox = (int) (iax | ibx);
15342                                        oi32data[it.oIndex] = ox;
15343                                }
15344                        }
15345                        break;
15346                case Dataset.ARRAYINT8:
15347                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
15348                        if (is == 1) {
15349                                {
15350                                        while (it.hasNext()) {
15351                                                final long iax = it.aLong;
15352                                                final long ibx = it.bLong;
15353                                                byte ox;
15354                                                ox = (byte) (iax | ibx);
15355                                                oai8data[it.oIndex] = ox;
15356                                        }
15357                                }
15358                        } else if (as < bs) {
15359                                {
15360                                        while (it.hasNext()) {
15361                                                final long iax = it.aLong;
15362                                                long ibx = it.bLong;
15363                                                byte ox;
15364                                                ox = (byte) (iax | ibx);
15365                                                oai8data[it.oIndex] = ox;
15366                                                for (int j = 1; j < is; j++) {
15367                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15368                                                        ox = (byte) (iax | ibx);
15369                                                        oai8data[it.oIndex + j] = ox;
15370                                                }
15371                                        }
15372                                }
15373                        } else if (as > bs) {
15374                                {
15375                                        while (it.hasNext()) {
15376                                                long iax = it.aLong;
15377                                                final long ibx = it.bLong;
15378                                                byte ox;
15379                                                ox = (byte) (iax | ibx);
15380                                                oai8data[it.oIndex] = ox;
15381                                                for (int j = 1; j < is; j++) {
15382                                                        iax = da.getElementLongAbs(it.aIndex + j);
15383                                                        ox = (byte) (iax | ibx);
15384                                                        oai8data[it.oIndex + j] = ox;
15385                                                }
15386                                        }
15387                                }
15388                        } else if (as == 1) {
15389                                {
15390                                        while (it.hasNext()) {
15391                                                final long iax = it.aLong;
15392                                                final long ibx = it.bLong;
15393                                                byte ox;
15394                                                ox = (byte) (iax | ibx);
15395                                                for (int j = 0; j < is; j++) {
15396                                                        oai8data[it.oIndex + j] = ox;
15397                                                }
15398                                        }
15399                                }
15400                        } else {
15401                                {
15402                                        while (it.hasNext()) {
15403                                                long iax = it.aLong;
15404                                                long ibx = it.bLong;
15405                                                byte ox;
15406                                                ox = (byte) (iax | ibx);
15407                                                oai8data[it.oIndex] = ox;
15408                                                for (int j = 1; j < is; j++) {
15409                                                        iax = da.getElementLongAbs(it.aIndex + j);
15410                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15411                                                        ox = (byte) (iax | ibx);
15412                                                        oai8data[it.oIndex + j] = ox;
15413                                                }
15414                                        }
15415                                }
15416                        }
15417                        break;
15418                case Dataset.ARRAYINT16:
15419                        final short[] oai16data = ((CompoundShortDataset) result).getData();
15420                        if (is == 1) {
15421                                {
15422                                        while (it.hasNext()) {
15423                                                final long iax = it.aLong;
15424                                                final long ibx = it.bLong;
15425                                                short ox;
15426                                                ox = (short) (iax | ibx);
15427                                                oai16data[it.oIndex] = ox;
15428                                        }
15429                                }
15430                        } else if (as < bs) {
15431                                {
15432                                        while (it.hasNext()) {
15433                                                final long iax = it.aLong;
15434                                                long ibx = it.bLong;
15435                                                short ox;
15436                                                ox = (short) (iax | ibx);
15437                                                oai16data[it.oIndex] = ox;
15438                                                for (int j = 1; j < is; j++) {
15439                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15440                                                        ox = (short) (iax | ibx);
15441                                                        oai16data[it.oIndex + j] = ox;
15442                                                }
15443                                        }
15444                                }
15445                        } else if (as > bs) {
15446                                {
15447                                        while (it.hasNext()) {
15448                                                long iax = it.aLong;
15449                                                final long ibx = it.bLong;
15450                                                short ox;
15451                                                ox = (short) (iax | ibx);
15452                                                oai16data[it.oIndex] = ox;
15453                                                for (int j = 1; j < is; j++) {
15454                                                        iax = da.getElementLongAbs(it.aIndex + j);
15455                                                        ox = (short) (iax | ibx);
15456                                                        oai16data[it.oIndex + j] = ox;
15457                                                }
15458                                        }
15459                                }
15460                        } else if (as == 1) {
15461                                {
15462                                        while (it.hasNext()) {
15463                                                final long iax = it.aLong;
15464                                                final long ibx = it.bLong;
15465                                                short ox;
15466                                                ox = (short) (iax | ibx);
15467                                                for (int j = 0; j < is; j++) {
15468                                                        oai16data[it.oIndex + j] = ox;
15469                                                }
15470                                        }
15471                                }
15472                        } else {
15473                                {
15474                                        while (it.hasNext()) {
15475                                                long iax = it.aLong;
15476                                                long ibx = it.bLong;
15477                                                short ox;
15478                                                ox = (short) (iax | ibx);
15479                                                oai16data[it.oIndex] = ox;
15480                                                for (int j = 1; j < is; j++) {
15481                                                        iax = da.getElementLongAbs(it.aIndex + j);
15482                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15483                                                        ox = (short) (iax | ibx);
15484                                                        oai16data[it.oIndex + j] = ox;
15485                                                }
15486                                        }
15487                                }
15488                        }
15489                        break;
15490                case Dataset.ARRAYINT64:
15491                        final long[] oai64data = ((CompoundLongDataset) result).getData();
15492                        if (is == 1) {
15493                                {
15494                                        while (it.hasNext()) {
15495                                                final long iax = it.aLong;
15496                                                final long ibx = it.bLong;
15497                                                long ox;
15498                                                ox = (iax | ibx);
15499                                                oai64data[it.oIndex] = ox;
15500                                        }
15501                                }
15502                        } else if (as < bs) {
15503                                {
15504                                        while (it.hasNext()) {
15505                                                final long iax = it.aLong;
15506                                                long ibx = it.bLong;
15507                                                long ox;
15508                                                ox = (iax | ibx);
15509                                                oai64data[it.oIndex] = ox;
15510                                                for (int j = 1; j < is; j++) {
15511                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15512                                                        ox = (iax | ibx);
15513                                                        oai64data[it.oIndex + j] = ox;
15514                                                }
15515                                        }
15516                                }
15517                        } else if (as > bs) {
15518                                {
15519                                        while (it.hasNext()) {
15520                                                long iax = it.aLong;
15521                                                final long ibx = it.bLong;
15522                                                long ox;
15523                                                ox = (iax | ibx);
15524                                                oai64data[it.oIndex] = ox;
15525                                                for (int j = 1; j < is; j++) {
15526                                                        iax = da.getElementLongAbs(it.aIndex + j);
15527                                                        ox = (iax | ibx);
15528                                                        oai64data[it.oIndex + j] = ox;
15529                                                }
15530                                        }
15531                                }
15532                        } else if (as == 1) {
15533                                {
15534                                        while (it.hasNext()) {
15535                                                final long iax = it.aLong;
15536                                                final long ibx = it.bLong;
15537                                                long ox;
15538                                                ox = (iax | ibx);
15539                                                for (int j = 0; j < is; j++) {
15540                                                        oai64data[it.oIndex + j] = ox;
15541                                                }
15542                                        }
15543                                }
15544                        } else {
15545                                {
15546                                        while (it.hasNext()) {
15547                                                long iax = it.aLong;
15548                                                long ibx = it.bLong;
15549                                                long ox;
15550                                                ox = (iax | ibx);
15551                                                oai64data[it.oIndex] = ox;
15552                                                for (int j = 1; j < is; j++) {
15553                                                        iax = da.getElementLongAbs(it.aIndex + j);
15554                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15555                                                        ox = (iax | ibx);
15556                                                        oai64data[it.oIndex + j] = ox;
15557                                                }
15558                                        }
15559                                }
15560                        }
15561                        break;
15562                case Dataset.ARRAYINT32:
15563                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
15564                        if (is == 1) {
15565                                {
15566                                        while (it.hasNext()) {
15567                                                final long iax = it.aLong;
15568                                                final long ibx = it.bLong;
15569                                                int ox;
15570                                                ox = (int) (iax | ibx);
15571                                                oai32data[it.oIndex] = ox;
15572                                        }
15573                                }
15574                        } else if (as < bs) {
15575                                {
15576                                        while (it.hasNext()) {
15577                                                final long iax = it.aLong;
15578                                                long ibx = it.bLong;
15579                                                int ox;
15580                                                ox = (int) (iax | ibx);
15581                                                oai32data[it.oIndex] = ox;
15582                                                for (int j = 1; j < is; j++) {
15583                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15584                                                        ox = (int) (iax | ibx);
15585                                                        oai32data[it.oIndex + j] = ox;
15586                                                }
15587                                        }
15588                                }
15589                        } else if (as > bs) {
15590                                {
15591                                        while (it.hasNext()) {
15592                                                long iax = it.aLong;
15593                                                final long ibx = it.bLong;
15594                                                int ox;
15595                                                ox = (int) (iax | ibx);
15596                                                oai32data[it.oIndex] = ox;
15597                                                for (int j = 1; j < is; j++) {
15598                                                        iax = da.getElementLongAbs(it.aIndex + j);
15599                                                        ox = (int) (iax | ibx);
15600                                                        oai32data[it.oIndex + j] = ox;
15601                                                }
15602                                        }
15603                                }
15604                        } else if (as == 1) {
15605                                {
15606                                        while (it.hasNext()) {
15607                                                final long iax = it.aLong;
15608                                                final long ibx = it.bLong;
15609                                                int ox;
15610                                                ox = (int) (iax | ibx);
15611                                                for (int j = 0; j < is; j++) {
15612                                                        oai32data[it.oIndex + j] = ox;
15613                                                }
15614                                        }
15615                                }
15616                        } else {
15617                                {
15618                                        while (it.hasNext()) {
15619                                                long iax = it.aLong;
15620                                                long ibx = it.bLong;
15621                                                int ox;
15622                                                ox = (int) (iax | ibx);
15623                                                oai32data[it.oIndex] = ox;
15624                                                for (int j = 1; j < is; j++) {
15625                                                        iax = da.getElementLongAbs(it.aIndex + j);
15626                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15627                                                        ox = (int) (iax | ibx);
15628                                                        oai32data[it.oIndex + j] = ox;
15629                                                }
15630                                        }
15631                                }
15632                        }
15633                        break;
15634                default:
15635                        throw new IllegalArgumentException("bitwiseOr supports integer, compound integer datasets only");
15636                }
15637
15638                addBinaryOperatorName(da, db, result, "|");
15639                return result;
15640        }
15641
15642        /**
15643         * bitwiseXor operator
15644         * @param a first operand
15645         * @param b second operand
15646         * @return {@code a ^ b}, bitwise exclusive OR of a and b
15647         */
15648        public static Dataset bitwiseXor(final Object a, final Object b) {
15649                return bitwiseXor(a, b, null);
15650        }
15651
15652        /**
15653         * bitwiseXor operator
15654         * @param a first operand
15655         * @param b second operand
15656         * @param o output can be null - in which case, a new dataset is created
15657         * @return {@code a ^ b}, bitwise exclusive OR of a and b
15658         */
15659        public static Dataset bitwiseXor(final Object a, final Object b, final Dataset o) {
15660                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
15661                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
15662                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
15663                it.setOutputDouble(false);
15664                final Dataset result = it.getOutput();
15665                if (!result.isComplex()) {
15666                        boolean change = false;
15667                        if (da.isComplex()) {
15668                                da = da.getRealView();
15669                                change = true;
15670                        }
15671                        if (db.isComplex()) {
15672                                db = db.getRealView();
15673                                change = true;
15674                        }
15675                        if (change) {
15676                                it = BroadcastIterator.createIterator(da, db, result, true);
15677                                it.setOutputDouble(false);
15678                        }
15679                }
15680                final int is = result.getElementsPerItem();
15681                final int as = da.getElementsPerItem();
15682                final int bs = db.getElementsPerItem();
15683                final int dt = result.getDType();
15684
15685                switch(dt) {
15686                case Dataset.INT8:
15687                        final byte[] oi8data = ((ByteDataset) result).getData();
15688                        {
15689                                while (it.hasNext()) {
15690                                        final long iax = it.aLong;
15691                                        final long ibx = it.bLong;
15692                                        byte ox;
15693                                        ox = (byte) (iax ^ ibx);
15694                                        oi8data[it.oIndex] = ox;
15695                                }
15696                        }
15697                        break;
15698                case Dataset.INT16:
15699                        final short[] oi16data = ((ShortDataset) result).getData();
15700                        {
15701                                while (it.hasNext()) {
15702                                        final long iax = it.aLong;
15703                                        final long ibx = it.bLong;
15704                                        short ox;
15705                                        ox = (short) (iax ^ ibx);
15706                                        oi16data[it.oIndex] = ox;
15707                                }
15708                        }
15709                        break;
15710                case Dataset.INT64:
15711                        final long[] oi64data = ((LongDataset) result).getData();
15712                        {
15713                                while (it.hasNext()) {
15714                                        final long iax = it.aLong;
15715                                        final long ibx = it.bLong;
15716                                        long ox;
15717                                        ox = (iax ^ ibx);
15718                                        oi64data[it.oIndex] = ox;
15719                                }
15720                        }
15721                        break;
15722                case Dataset.INT32:
15723                        final int[] oi32data = ((IntegerDataset) result).getData();
15724                        {
15725                                while (it.hasNext()) {
15726                                        final long iax = it.aLong;
15727                                        final long ibx = it.bLong;
15728                                        int ox;
15729                                        ox = (int) (iax ^ ibx);
15730                                        oi32data[it.oIndex] = ox;
15731                                }
15732                        }
15733                        break;
15734                case Dataset.ARRAYINT8:
15735                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
15736                        if (is == 1) {
15737                                {
15738                                        while (it.hasNext()) {
15739                                                final long iax = it.aLong;
15740                                                final long ibx = it.bLong;
15741                                                byte ox;
15742                                                ox = (byte) (iax ^ ibx);
15743                                                oai8data[it.oIndex] = ox;
15744                                        }
15745                                }
15746                        } else if (as < bs) {
15747                                {
15748                                        while (it.hasNext()) {
15749                                                final long iax = it.aLong;
15750                                                long ibx = it.bLong;
15751                                                byte ox;
15752                                                ox = (byte) (iax ^ ibx);
15753                                                oai8data[it.oIndex] = ox;
15754                                                for (int j = 1; j < is; j++) {
15755                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15756                                                        ox = (byte) (iax ^ ibx);
15757                                                        oai8data[it.oIndex + j] = ox;
15758                                                }
15759                                        }
15760                                }
15761                        } else if (as > bs) {
15762                                {
15763                                        while (it.hasNext()) {
15764                                                long iax = it.aLong;
15765                                                final long ibx = it.bLong;
15766                                                byte ox;
15767                                                ox = (byte) (iax ^ ibx);
15768                                                oai8data[it.oIndex] = ox;
15769                                                for (int j = 1; j < is; j++) {
15770                                                        iax = da.getElementLongAbs(it.aIndex + j);
15771                                                        ox = (byte) (iax ^ ibx);
15772                                                        oai8data[it.oIndex + j] = ox;
15773                                                }
15774                                        }
15775                                }
15776                        } else if (as == 1) {
15777                                {
15778                                        while (it.hasNext()) {
15779                                                final long iax = it.aLong;
15780                                                final long ibx = it.bLong;
15781                                                byte ox;
15782                                                ox = (byte) (iax ^ ibx);
15783                                                for (int j = 0; j < is; j++) {
15784                                                        oai8data[it.oIndex + j] = ox;
15785                                                }
15786                                        }
15787                                }
15788                        } else {
15789                                {
15790                                        while (it.hasNext()) {
15791                                                long iax = it.aLong;
15792                                                long ibx = it.bLong;
15793                                                byte ox;
15794                                                ox = (byte) (iax ^ ibx);
15795                                                oai8data[it.oIndex] = ox;
15796                                                for (int j = 1; j < is; j++) {
15797                                                        iax = da.getElementLongAbs(it.aIndex + j);
15798                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15799                                                        ox = (byte) (iax ^ ibx);
15800                                                        oai8data[it.oIndex + j] = ox;
15801                                                }
15802                                        }
15803                                }
15804                        }
15805                        break;
15806                case Dataset.ARRAYINT16:
15807                        final short[] oai16data = ((CompoundShortDataset) result).getData();
15808                        if (is == 1) {
15809                                {
15810                                        while (it.hasNext()) {
15811                                                final long iax = it.aLong;
15812                                                final long ibx = it.bLong;
15813                                                short ox;
15814                                                ox = (short) (iax ^ ibx);
15815                                                oai16data[it.oIndex] = ox;
15816                                        }
15817                                }
15818                        } else if (as < bs) {
15819                                {
15820                                        while (it.hasNext()) {
15821                                                final long iax = it.aLong;
15822                                                long ibx = it.bLong;
15823                                                short ox;
15824                                                ox = (short) (iax ^ ibx);
15825                                                oai16data[it.oIndex] = ox;
15826                                                for (int j = 1; j < is; j++) {
15827                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15828                                                        ox = (short) (iax ^ ibx);
15829                                                        oai16data[it.oIndex + j] = ox;
15830                                                }
15831                                        }
15832                                }
15833                        } else if (as > bs) {
15834                                {
15835                                        while (it.hasNext()) {
15836                                                long iax = it.aLong;
15837                                                final long ibx = it.bLong;
15838                                                short ox;
15839                                                ox = (short) (iax ^ ibx);
15840                                                oai16data[it.oIndex] = ox;
15841                                                for (int j = 1; j < is; j++) {
15842                                                        iax = da.getElementLongAbs(it.aIndex + j);
15843                                                        ox = (short) (iax ^ ibx);
15844                                                        oai16data[it.oIndex + j] = ox;
15845                                                }
15846                                        }
15847                                }
15848                        } else if (as == 1) {
15849                                {
15850                                        while (it.hasNext()) {
15851                                                final long iax = it.aLong;
15852                                                final long ibx = it.bLong;
15853                                                short ox;
15854                                                ox = (short) (iax ^ ibx);
15855                                                for (int j = 0; j < is; j++) {
15856                                                        oai16data[it.oIndex + j] = ox;
15857                                                }
15858                                        }
15859                                }
15860                        } else {
15861                                {
15862                                        while (it.hasNext()) {
15863                                                long iax = it.aLong;
15864                                                long ibx = it.bLong;
15865                                                short ox;
15866                                                ox = (short) (iax ^ ibx);
15867                                                oai16data[it.oIndex] = ox;
15868                                                for (int j = 1; j < is; j++) {
15869                                                        iax = da.getElementLongAbs(it.aIndex + j);
15870                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15871                                                        ox = (short) (iax ^ ibx);
15872                                                        oai16data[it.oIndex + j] = ox;
15873                                                }
15874                                        }
15875                                }
15876                        }
15877                        break;
15878                case Dataset.ARRAYINT64:
15879                        final long[] oai64data = ((CompoundLongDataset) result).getData();
15880                        if (is == 1) {
15881                                {
15882                                        while (it.hasNext()) {
15883                                                final long iax = it.aLong;
15884                                                final long ibx = it.bLong;
15885                                                long ox;
15886                                                ox = (iax ^ ibx);
15887                                                oai64data[it.oIndex] = ox;
15888                                        }
15889                                }
15890                        } else if (as < bs) {
15891                                {
15892                                        while (it.hasNext()) {
15893                                                final long iax = it.aLong;
15894                                                long ibx = it.bLong;
15895                                                long ox;
15896                                                ox = (iax ^ ibx);
15897                                                oai64data[it.oIndex] = ox;
15898                                                for (int j = 1; j < is; j++) {
15899                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15900                                                        ox = (iax ^ ibx);
15901                                                        oai64data[it.oIndex + j] = ox;
15902                                                }
15903                                        }
15904                                }
15905                        } else if (as > bs) {
15906                                {
15907                                        while (it.hasNext()) {
15908                                                long iax = it.aLong;
15909                                                final long ibx = it.bLong;
15910                                                long ox;
15911                                                ox = (iax ^ ibx);
15912                                                oai64data[it.oIndex] = ox;
15913                                                for (int j = 1; j < is; j++) {
15914                                                        iax = da.getElementLongAbs(it.aIndex + j);
15915                                                        ox = (iax ^ ibx);
15916                                                        oai64data[it.oIndex + j] = ox;
15917                                                }
15918                                        }
15919                                }
15920                        } else if (as == 1) {
15921                                {
15922                                        while (it.hasNext()) {
15923                                                final long iax = it.aLong;
15924                                                final long ibx = it.bLong;
15925                                                long ox;
15926                                                ox = (iax ^ ibx);
15927                                                for (int j = 0; j < is; j++) {
15928                                                        oai64data[it.oIndex + j] = ox;
15929                                                }
15930                                        }
15931                                }
15932                        } else {
15933                                {
15934                                        while (it.hasNext()) {
15935                                                long iax = it.aLong;
15936                                                long ibx = it.bLong;
15937                                                long ox;
15938                                                ox = (iax ^ ibx);
15939                                                oai64data[it.oIndex] = ox;
15940                                                for (int j = 1; j < is; j++) {
15941                                                        iax = da.getElementLongAbs(it.aIndex + j);
15942                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15943                                                        ox = (iax ^ ibx);
15944                                                        oai64data[it.oIndex + j] = ox;
15945                                                }
15946                                        }
15947                                }
15948                        }
15949                        break;
15950                case Dataset.ARRAYINT32:
15951                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
15952                        if (is == 1) {
15953                                {
15954                                        while (it.hasNext()) {
15955                                                final long iax = it.aLong;
15956                                                final long ibx = it.bLong;
15957                                                int ox;
15958                                                ox = (int) (iax ^ ibx);
15959                                                oai32data[it.oIndex] = ox;
15960                                        }
15961                                }
15962                        } else if (as < bs) {
15963                                {
15964                                        while (it.hasNext()) {
15965                                                final long iax = it.aLong;
15966                                                long ibx = it.bLong;
15967                                                int ox;
15968                                                ox = (int) (iax ^ ibx);
15969                                                oai32data[it.oIndex] = ox;
15970                                                for (int j = 1; j < is; j++) {
15971                                                        ibx = db.getElementLongAbs(it.bIndex + j);
15972                                                        ox = (int) (iax ^ ibx);
15973                                                        oai32data[it.oIndex + j] = ox;
15974                                                }
15975                                        }
15976                                }
15977                        } else if (as > bs) {
15978                                {
15979                                        while (it.hasNext()) {
15980                                                long iax = it.aLong;
15981                                                final long ibx = it.bLong;
15982                                                int ox;
15983                                                ox = (int) (iax ^ ibx);
15984                                                oai32data[it.oIndex] = ox;
15985                                                for (int j = 1; j < is; j++) {
15986                                                        iax = da.getElementLongAbs(it.aIndex + j);
15987                                                        ox = (int) (iax ^ ibx);
15988                                                        oai32data[it.oIndex + j] = ox;
15989                                                }
15990                                        }
15991                                }
15992                        } else if (as == 1) {
15993                                {
15994                                        while (it.hasNext()) {
15995                                                final long iax = it.aLong;
15996                                                final long ibx = it.bLong;
15997                                                int ox;
15998                                                ox = (int) (iax ^ ibx);
15999                                                for (int j = 0; j < is; j++) {
16000                                                        oai32data[it.oIndex + j] = ox;
16001                                                }
16002                                        }
16003                                }
16004                        } else {
16005                                {
16006                                        while (it.hasNext()) {
16007                                                long iax = it.aLong;
16008                                                long ibx = it.bLong;
16009                                                int ox;
16010                                                ox = (int) (iax ^ ibx);
16011                                                oai32data[it.oIndex] = ox;
16012                                                for (int j = 1; j < is; j++) {
16013                                                        iax = da.getElementLongAbs(it.aIndex + j);
16014                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16015                                                        ox = (int) (iax ^ ibx);
16016                                                        oai32data[it.oIndex + j] = ox;
16017                                                }
16018                                        }
16019                                }
16020                        }
16021                        break;
16022                default:
16023                        throw new IllegalArgumentException("bitwiseXor supports integer, compound integer datasets only");
16024                }
16025
16026                addBinaryOperatorName(da, db, result, "^");
16027                return result;
16028        }
16029
16030        /**
16031         * leftShift operator
16032         * @param a first operand
16033         * @param b second operand
16034         * @return {@code a << b}, bitwise left shift of a by b
16035         */
16036        public static Dataset leftShift(final Object a, final Object b) {
16037                return leftShift(a, b, null);
16038        }
16039
16040        /**
16041         * leftShift operator
16042         * @param a first operand
16043         * @param b second operand
16044         * @param o output can be null - in which case, a new dataset is created
16045         * @return {@code a << b}, bitwise left shift of a by b
16046         */
16047        public static Dataset leftShift(final Object a, final Object b, final Dataset o) {
16048                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
16049                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
16050                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
16051                it.setOutputDouble(false);
16052                final Dataset result = it.getOutput();
16053                if (!result.isComplex()) {
16054                        boolean change = false;
16055                        if (da.isComplex()) {
16056                                da = da.getRealView();
16057                                change = true;
16058                        }
16059                        if (db.isComplex()) {
16060                                db = db.getRealView();
16061                                change = true;
16062                        }
16063                        if (change) {
16064                                it = BroadcastIterator.createIterator(da, db, result, true);
16065                                it.setOutputDouble(false);
16066                        }
16067                }
16068                final int is = result.getElementsPerItem();
16069                final int as = da.getElementsPerItem();
16070                final int bs = db.getElementsPerItem();
16071                final int dt = result.getDType();
16072
16073                switch(dt) {
16074                case Dataset.INT8:
16075                        final byte[] oi8data = ((ByteDataset) result).getData();
16076                        {
16077                                while (it.hasNext()) {
16078                                        final long iax = it.aLong;
16079                                        final long ibx = it.bLong;
16080                                        byte ox;
16081                                        ox = (byte) (iax << ibx);
16082                                        oi8data[it.oIndex] = ox;
16083                                }
16084                        }
16085                        break;
16086                case Dataset.INT16:
16087                        final short[] oi16data = ((ShortDataset) result).getData();
16088                        {
16089                                while (it.hasNext()) {
16090                                        final long iax = it.aLong;
16091                                        final long ibx = it.bLong;
16092                                        short ox;
16093                                        ox = (short) (iax << ibx);
16094                                        oi16data[it.oIndex] = ox;
16095                                }
16096                        }
16097                        break;
16098                case Dataset.INT64:
16099                        final long[] oi64data = ((LongDataset) result).getData();
16100                        {
16101                                while (it.hasNext()) {
16102                                        final long iax = it.aLong;
16103                                        final long ibx = it.bLong;
16104                                        long ox;
16105                                        ox = (iax << ibx);
16106                                        oi64data[it.oIndex] = ox;
16107                                }
16108                        }
16109                        break;
16110                case Dataset.INT32:
16111                        final int[] oi32data = ((IntegerDataset) result).getData();
16112                        {
16113                                while (it.hasNext()) {
16114                                        final long iax = it.aLong;
16115                                        final long ibx = it.bLong;
16116                                        int ox;
16117                                        ox = (int) (iax << ibx);
16118                                        oi32data[it.oIndex] = ox;
16119                                }
16120                        }
16121                        break;
16122                case Dataset.ARRAYINT8:
16123                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
16124                        if (is == 1) {
16125                                {
16126                                        while (it.hasNext()) {
16127                                                final long iax = it.aLong;
16128                                                final long ibx = it.bLong;
16129                                                byte ox;
16130                                                ox = (byte) (iax << ibx);
16131                                                oai8data[it.oIndex] = ox;
16132                                        }
16133                                }
16134                        } else if (as < bs) {
16135                                {
16136                                        while (it.hasNext()) {
16137                                                final long iax = it.aLong;
16138                                                long ibx = it.bLong;
16139                                                byte ox;
16140                                                ox = (byte) (iax << ibx);
16141                                                oai8data[it.oIndex] = ox;
16142                                                for (int j = 1; j < is; j++) {
16143                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16144                                                        ox = (byte) (iax << ibx);
16145                                                        oai8data[it.oIndex + j] = ox;
16146                                                }
16147                                        }
16148                                }
16149                        } else if (as > bs) {
16150                                {
16151                                        while (it.hasNext()) {
16152                                                long iax = it.aLong;
16153                                                final long ibx = it.bLong;
16154                                                byte ox;
16155                                                ox = (byte) (iax << ibx);
16156                                                oai8data[it.oIndex] = ox;
16157                                                for (int j = 1; j < is; j++) {
16158                                                        iax = da.getElementLongAbs(it.aIndex + j);
16159                                                        ox = (byte) (iax << ibx);
16160                                                        oai8data[it.oIndex + j] = ox;
16161                                                }
16162                                        }
16163                                }
16164                        } else if (as == 1) {
16165                                {
16166                                        while (it.hasNext()) {
16167                                                final long iax = it.aLong;
16168                                                final long ibx = it.bLong;
16169                                                byte ox;
16170                                                ox = (byte) (iax << ibx);
16171                                                for (int j = 0; j < is; j++) {
16172                                                        oai8data[it.oIndex + j] = ox;
16173                                                }
16174                                        }
16175                                }
16176                        } else {
16177                                {
16178                                        while (it.hasNext()) {
16179                                                long iax = it.aLong;
16180                                                long ibx = it.bLong;
16181                                                byte ox;
16182                                                ox = (byte) (iax << ibx);
16183                                                oai8data[it.oIndex] = ox;
16184                                                for (int j = 1; j < is; j++) {
16185                                                        iax = da.getElementLongAbs(it.aIndex + j);
16186                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16187                                                        ox = (byte) (iax << ibx);
16188                                                        oai8data[it.oIndex + j] = ox;
16189                                                }
16190                                        }
16191                                }
16192                        }
16193                        break;
16194                case Dataset.ARRAYINT16:
16195                        final short[] oai16data = ((CompoundShortDataset) result).getData();
16196                        if (is == 1) {
16197                                {
16198                                        while (it.hasNext()) {
16199                                                final long iax = it.aLong;
16200                                                final long ibx = it.bLong;
16201                                                short ox;
16202                                                ox = (short) (iax << ibx);
16203                                                oai16data[it.oIndex] = ox;
16204                                        }
16205                                }
16206                        } else if (as < bs) {
16207                                {
16208                                        while (it.hasNext()) {
16209                                                final long iax = it.aLong;
16210                                                long ibx = it.bLong;
16211                                                short ox;
16212                                                ox = (short) (iax << ibx);
16213                                                oai16data[it.oIndex] = ox;
16214                                                for (int j = 1; j < is; j++) {
16215                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16216                                                        ox = (short) (iax << ibx);
16217                                                        oai16data[it.oIndex + j] = ox;
16218                                                }
16219                                        }
16220                                }
16221                        } else if (as > bs) {
16222                                {
16223                                        while (it.hasNext()) {
16224                                                long iax = it.aLong;
16225                                                final long ibx = it.bLong;
16226                                                short ox;
16227                                                ox = (short) (iax << ibx);
16228                                                oai16data[it.oIndex] = ox;
16229                                                for (int j = 1; j < is; j++) {
16230                                                        iax = da.getElementLongAbs(it.aIndex + j);
16231                                                        ox = (short) (iax << ibx);
16232                                                        oai16data[it.oIndex + j] = ox;
16233                                                }
16234                                        }
16235                                }
16236                        } else if (as == 1) {
16237                                {
16238                                        while (it.hasNext()) {
16239                                                final long iax = it.aLong;
16240                                                final long ibx = it.bLong;
16241                                                short ox;
16242                                                ox = (short) (iax << ibx);
16243                                                for (int j = 0; j < is; j++) {
16244                                                        oai16data[it.oIndex + j] = ox;
16245                                                }
16246                                        }
16247                                }
16248                        } else {
16249                                {
16250                                        while (it.hasNext()) {
16251                                                long iax = it.aLong;
16252                                                long ibx = it.bLong;
16253                                                short ox;
16254                                                ox = (short) (iax << ibx);
16255                                                oai16data[it.oIndex] = ox;
16256                                                for (int j = 1; j < is; j++) {
16257                                                        iax = da.getElementLongAbs(it.aIndex + j);
16258                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16259                                                        ox = (short) (iax << ibx);
16260                                                        oai16data[it.oIndex + j] = ox;
16261                                                }
16262                                        }
16263                                }
16264                        }
16265                        break;
16266                case Dataset.ARRAYINT64:
16267                        final long[] oai64data = ((CompoundLongDataset) result).getData();
16268                        if (is == 1) {
16269                                {
16270                                        while (it.hasNext()) {
16271                                                final long iax = it.aLong;
16272                                                final long ibx = it.bLong;
16273                                                long ox;
16274                                                ox = (iax << ibx);
16275                                                oai64data[it.oIndex] = ox;
16276                                        }
16277                                }
16278                        } else if (as < bs) {
16279                                {
16280                                        while (it.hasNext()) {
16281                                                final long iax = it.aLong;
16282                                                long ibx = it.bLong;
16283                                                long ox;
16284                                                ox = (iax << ibx);
16285                                                oai64data[it.oIndex] = ox;
16286                                                for (int j = 1; j < is; j++) {
16287                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16288                                                        ox = (iax << ibx);
16289                                                        oai64data[it.oIndex + j] = ox;
16290                                                }
16291                                        }
16292                                }
16293                        } else if (as > bs) {
16294                                {
16295                                        while (it.hasNext()) {
16296                                                long iax = it.aLong;
16297                                                final long ibx = it.bLong;
16298                                                long ox;
16299                                                ox = (iax << ibx);
16300                                                oai64data[it.oIndex] = ox;
16301                                                for (int j = 1; j < is; j++) {
16302                                                        iax = da.getElementLongAbs(it.aIndex + j);
16303                                                        ox = (iax << ibx);
16304                                                        oai64data[it.oIndex + j] = ox;
16305                                                }
16306                                        }
16307                                }
16308                        } else if (as == 1) {
16309                                {
16310                                        while (it.hasNext()) {
16311                                                final long iax = it.aLong;
16312                                                final long ibx = it.bLong;
16313                                                long ox;
16314                                                ox = (iax << ibx);
16315                                                for (int j = 0; j < is; j++) {
16316                                                        oai64data[it.oIndex + j] = ox;
16317                                                }
16318                                        }
16319                                }
16320                        } else {
16321                                {
16322                                        while (it.hasNext()) {
16323                                                long iax = it.aLong;
16324                                                long ibx = it.bLong;
16325                                                long ox;
16326                                                ox = (iax << ibx);
16327                                                oai64data[it.oIndex] = ox;
16328                                                for (int j = 1; j < is; j++) {
16329                                                        iax = da.getElementLongAbs(it.aIndex + j);
16330                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16331                                                        ox = (iax << ibx);
16332                                                        oai64data[it.oIndex + j] = ox;
16333                                                }
16334                                        }
16335                                }
16336                        }
16337                        break;
16338                case Dataset.ARRAYINT32:
16339                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
16340                        if (is == 1) {
16341                                {
16342                                        while (it.hasNext()) {
16343                                                final long iax = it.aLong;
16344                                                final long ibx = it.bLong;
16345                                                int ox;
16346                                                ox = (int) (iax << ibx);
16347                                                oai32data[it.oIndex] = ox;
16348                                        }
16349                                }
16350                        } else if (as < bs) {
16351                                {
16352                                        while (it.hasNext()) {
16353                                                final long iax = it.aLong;
16354                                                long ibx = it.bLong;
16355                                                int ox;
16356                                                ox = (int) (iax << ibx);
16357                                                oai32data[it.oIndex] = ox;
16358                                                for (int j = 1; j < is; j++) {
16359                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16360                                                        ox = (int) (iax << ibx);
16361                                                        oai32data[it.oIndex + j] = ox;
16362                                                }
16363                                        }
16364                                }
16365                        } else if (as > bs) {
16366                                {
16367                                        while (it.hasNext()) {
16368                                                long iax = it.aLong;
16369                                                final long ibx = it.bLong;
16370                                                int ox;
16371                                                ox = (int) (iax << ibx);
16372                                                oai32data[it.oIndex] = ox;
16373                                                for (int j = 1; j < is; j++) {
16374                                                        iax = da.getElementLongAbs(it.aIndex + j);
16375                                                        ox = (int) (iax << ibx);
16376                                                        oai32data[it.oIndex + j] = ox;
16377                                                }
16378                                        }
16379                                }
16380                        } else if (as == 1) {
16381                                {
16382                                        while (it.hasNext()) {
16383                                                final long iax = it.aLong;
16384                                                final long ibx = it.bLong;
16385                                                int ox;
16386                                                ox = (int) (iax << ibx);
16387                                                for (int j = 0; j < is; j++) {
16388                                                        oai32data[it.oIndex + j] = ox;
16389                                                }
16390                                        }
16391                                }
16392                        } else {
16393                                {
16394                                        while (it.hasNext()) {
16395                                                long iax = it.aLong;
16396                                                long ibx = it.bLong;
16397                                                int ox;
16398                                                ox = (int) (iax << ibx);
16399                                                oai32data[it.oIndex] = ox;
16400                                                for (int j = 1; j < is; j++) {
16401                                                        iax = da.getElementLongAbs(it.aIndex + j);
16402                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16403                                                        ox = (int) (iax << ibx);
16404                                                        oai32data[it.oIndex + j] = ox;
16405                                                }
16406                                        }
16407                                }
16408                        }
16409                        break;
16410                default:
16411                        throw new IllegalArgumentException("leftShift supports integer, compound integer datasets only");
16412                }
16413
16414                addBinaryOperatorName(da, db, result, "<<");
16415                return result;
16416        }
16417
16418        /**
16419         * rightShift operator
16420         * @param a first operand
16421         * @param b second operand
16422         * @return {@code a >> b}, bitwise right shift of a by b
16423         */
16424        public static Dataset rightShift(final Object a, final Object b) {
16425                return rightShift(a, b, null);
16426        }
16427
16428        /**
16429         * rightShift operator
16430         * @param a first operand
16431         * @param b second operand
16432         * @param o output can be null - in which case, a new dataset is created
16433         * @return {@code a >> b}, bitwise right shift of a by b
16434         */
16435        public static Dataset rightShift(final Object a, final Object b, final Dataset o) {
16436                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
16437                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
16438                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
16439                it.setOutputDouble(false);
16440                final Dataset result = it.getOutput();
16441                if (!result.isComplex()) {
16442                        boolean change = false;
16443                        if (da.isComplex()) {
16444                                da = da.getRealView();
16445                                change = true;
16446                        }
16447                        if (db.isComplex()) {
16448                                db = db.getRealView();
16449                                change = true;
16450                        }
16451                        if (change) {
16452                                it = BroadcastIterator.createIterator(da, db, result, true);
16453                                it.setOutputDouble(false);
16454                        }
16455                }
16456                final int is = result.getElementsPerItem();
16457                final int as = da.getElementsPerItem();
16458                final int bs = db.getElementsPerItem();
16459                final int dt = result.getDType();
16460
16461                switch(dt) {
16462                case Dataset.INT8:
16463                        final byte[] oi8data = ((ByteDataset) result).getData();
16464                        {
16465                                while (it.hasNext()) {
16466                                        final long iax = it.aLong;
16467                                        final long ibx = it.bLong;
16468                                        byte ox;
16469                                        ox = (byte) (iax >> ibx);
16470                                        oi8data[it.oIndex] = ox;
16471                                }
16472                        }
16473                        break;
16474                case Dataset.INT16:
16475                        final short[] oi16data = ((ShortDataset) result).getData();
16476                        {
16477                                while (it.hasNext()) {
16478                                        final long iax = it.aLong;
16479                                        final long ibx = it.bLong;
16480                                        short ox;
16481                                        ox = (short) (iax >> ibx);
16482                                        oi16data[it.oIndex] = ox;
16483                                }
16484                        }
16485                        break;
16486                case Dataset.INT64:
16487                        final long[] oi64data = ((LongDataset) result).getData();
16488                        {
16489                                while (it.hasNext()) {
16490                                        final long iax = it.aLong;
16491                                        final long ibx = it.bLong;
16492                                        long ox;
16493                                        ox = (iax >> ibx);
16494                                        oi64data[it.oIndex] = ox;
16495                                }
16496                        }
16497                        break;
16498                case Dataset.INT32:
16499                        final int[] oi32data = ((IntegerDataset) result).getData();
16500                        {
16501                                while (it.hasNext()) {
16502                                        final long iax = it.aLong;
16503                                        final long ibx = it.bLong;
16504                                        int ox;
16505                                        ox = (int) (iax >> ibx);
16506                                        oi32data[it.oIndex] = ox;
16507                                }
16508                        }
16509                        break;
16510                case Dataset.ARRAYINT8:
16511                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
16512                        if (is == 1) {
16513                                {
16514                                        while (it.hasNext()) {
16515                                                final long iax = it.aLong;
16516                                                final long ibx = it.bLong;
16517                                                byte ox;
16518                                                ox = (byte) (iax >> ibx);
16519                                                oai8data[it.oIndex] = ox;
16520                                        }
16521                                }
16522                        } else if (as < bs) {
16523                                {
16524                                        while (it.hasNext()) {
16525                                                final long iax = it.aLong;
16526                                                long ibx = it.bLong;
16527                                                byte ox;
16528                                                ox = (byte) (iax >> ibx);
16529                                                oai8data[it.oIndex] = ox;
16530                                                for (int j = 1; j < is; j++) {
16531                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16532                                                        ox = (byte) (iax >> ibx);
16533                                                        oai8data[it.oIndex + j] = ox;
16534                                                }
16535                                        }
16536                                }
16537                        } else if (as > bs) {
16538                                {
16539                                        while (it.hasNext()) {
16540                                                long iax = it.aLong;
16541                                                final long ibx = it.bLong;
16542                                                byte ox;
16543                                                ox = (byte) (iax >> ibx);
16544                                                oai8data[it.oIndex] = ox;
16545                                                for (int j = 1; j < is; j++) {
16546                                                        iax = da.getElementLongAbs(it.aIndex + j);
16547                                                        ox = (byte) (iax >> ibx);
16548                                                        oai8data[it.oIndex + j] = ox;
16549                                                }
16550                                        }
16551                                }
16552                        } else if (as == 1) {
16553                                {
16554                                        while (it.hasNext()) {
16555                                                final long iax = it.aLong;
16556                                                final long ibx = it.bLong;
16557                                                byte ox;
16558                                                ox = (byte) (iax >> ibx);
16559                                                for (int j = 0; j < is; j++) {
16560                                                        oai8data[it.oIndex + j] = ox;
16561                                                }
16562                                        }
16563                                }
16564                        } else {
16565                                {
16566                                        while (it.hasNext()) {
16567                                                long iax = it.aLong;
16568                                                long ibx = it.bLong;
16569                                                byte ox;
16570                                                ox = (byte) (iax >> ibx);
16571                                                oai8data[it.oIndex] = ox;
16572                                                for (int j = 1; j < is; j++) {
16573                                                        iax = da.getElementLongAbs(it.aIndex + j);
16574                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16575                                                        ox = (byte) (iax >> ibx);
16576                                                        oai8data[it.oIndex + j] = ox;
16577                                                }
16578                                        }
16579                                }
16580                        }
16581                        break;
16582                case Dataset.ARRAYINT16:
16583                        final short[] oai16data = ((CompoundShortDataset) result).getData();
16584                        if (is == 1) {
16585                                {
16586                                        while (it.hasNext()) {
16587                                                final long iax = it.aLong;
16588                                                final long ibx = it.bLong;
16589                                                short ox;
16590                                                ox = (short) (iax >> ibx);
16591                                                oai16data[it.oIndex] = ox;
16592                                        }
16593                                }
16594                        } else if (as < bs) {
16595                                {
16596                                        while (it.hasNext()) {
16597                                                final long iax = it.aLong;
16598                                                long ibx = it.bLong;
16599                                                short ox;
16600                                                ox = (short) (iax >> ibx);
16601                                                oai16data[it.oIndex] = ox;
16602                                                for (int j = 1; j < is; j++) {
16603                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16604                                                        ox = (short) (iax >> ibx);
16605                                                        oai16data[it.oIndex + j] = ox;
16606                                                }
16607                                        }
16608                                }
16609                        } else if (as > bs) {
16610                                {
16611                                        while (it.hasNext()) {
16612                                                long iax = it.aLong;
16613                                                final long ibx = it.bLong;
16614                                                short ox;
16615                                                ox = (short) (iax >> ibx);
16616                                                oai16data[it.oIndex] = ox;
16617                                                for (int j = 1; j < is; j++) {
16618                                                        iax = da.getElementLongAbs(it.aIndex + j);
16619                                                        ox = (short) (iax >> ibx);
16620                                                        oai16data[it.oIndex + j] = ox;
16621                                                }
16622                                        }
16623                                }
16624                        } else if (as == 1) {
16625                                {
16626                                        while (it.hasNext()) {
16627                                                final long iax = it.aLong;
16628                                                final long ibx = it.bLong;
16629                                                short ox;
16630                                                ox = (short) (iax >> ibx);
16631                                                for (int j = 0; j < is; j++) {
16632                                                        oai16data[it.oIndex + j] = ox;
16633                                                }
16634                                        }
16635                                }
16636                        } else {
16637                                {
16638                                        while (it.hasNext()) {
16639                                                long iax = it.aLong;
16640                                                long ibx = it.bLong;
16641                                                short ox;
16642                                                ox = (short) (iax >> ibx);
16643                                                oai16data[it.oIndex] = ox;
16644                                                for (int j = 1; j < is; j++) {
16645                                                        iax = da.getElementLongAbs(it.aIndex + j);
16646                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16647                                                        ox = (short) (iax >> ibx);
16648                                                        oai16data[it.oIndex + j] = ox;
16649                                                }
16650                                        }
16651                                }
16652                        }
16653                        break;
16654                case Dataset.ARRAYINT64:
16655                        final long[] oai64data = ((CompoundLongDataset) result).getData();
16656                        if (is == 1) {
16657                                {
16658                                        while (it.hasNext()) {
16659                                                final long iax = it.aLong;
16660                                                final long ibx = it.bLong;
16661                                                long ox;
16662                                                ox = (iax >> ibx);
16663                                                oai64data[it.oIndex] = ox;
16664                                        }
16665                                }
16666                        } else if (as < bs) {
16667                                {
16668                                        while (it.hasNext()) {
16669                                                final long iax = it.aLong;
16670                                                long ibx = it.bLong;
16671                                                long ox;
16672                                                ox = (iax >> ibx);
16673                                                oai64data[it.oIndex] = ox;
16674                                                for (int j = 1; j < is; j++) {
16675                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16676                                                        ox = (iax >> ibx);
16677                                                        oai64data[it.oIndex + j] = ox;
16678                                                }
16679                                        }
16680                                }
16681                        } else if (as > bs) {
16682                                {
16683                                        while (it.hasNext()) {
16684                                                long iax = it.aLong;
16685                                                final long ibx = it.bLong;
16686                                                long ox;
16687                                                ox = (iax >> ibx);
16688                                                oai64data[it.oIndex] = ox;
16689                                                for (int j = 1; j < is; j++) {
16690                                                        iax = da.getElementLongAbs(it.aIndex + j);
16691                                                        ox = (iax >> ibx);
16692                                                        oai64data[it.oIndex + j] = ox;
16693                                                }
16694                                        }
16695                                }
16696                        } else if (as == 1) {
16697                                {
16698                                        while (it.hasNext()) {
16699                                                final long iax = it.aLong;
16700                                                final long ibx = it.bLong;
16701                                                long ox;
16702                                                ox = (iax >> ibx);
16703                                                for (int j = 0; j < is; j++) {
16704                                                        oai64data[it.oIndex + j] = ox;
16705                                                }
16706                                        }
16707                                }
16708                        } else {
16709                                {
16710                                        while (it.hasNext()) {
16711                                                long iax = it.aLong;
16712                                                long ibx = it.bLong;
16713                                                long ox;
16714                                                ox = (iax >> ibx);
16715                                                oai64data[it.oIndex] = ox;
16716                                                for (int j = 1; j < is; j++) {
16717                                                        iax = da.getElementLongAbs(it.aIndex + j);
16718                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16719                                                        ox = (iax >> ibx);
16720                                                        oai64data[it.oIndex + j] = ox;
16721                                                }
16722                                        }
16723                                }
16724                        }
16725                        break;
16726                case Dataset.ARRAYINT32:
16727                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
16728                        if (is == 1) {
16729                                {
16730                                        while (it.hasNext()) {
16731                                                final long iax = it.aLong;
16732                                                final long ibx = it.bLong;
16733                                                int ox;
16734                                                ox = (int) (iax >> ibx);
16735                                                oai32data[it.oIndex] = ox;
16736                                        }
16737                                }
16738                        } else if (as < bs) {
16739                                {
16740                                        while (it.hasNext()) {
16741                                                final long iax = it.aLong;
16742                                                long ibx = it.bLong;
16743                                                int ox;
16744                                                ox = (int) (iax >> ibx);
16745                                                oai32data[it.oIndex] = ox;
16746                                                for (int j = 1; j < is; j++) {
16747                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16748                                                        ox = (int) (iax >> ibx);
16749                                                        oai32data[it.oIndex + j] = ox;
16750                                                }
16751                                        }
16752                                }
16753                        } else if (as > bs) {
16754                                {
16755                                        while (it.hasNext()) {
16756                                                long iax = it.aLong;
16757                                                final long ibx = it.bLong;
16758                                                int ox;
16759                                                ox = (int) (iax >> ibx);
16760                                                oai32data[it.oIndex] = ox;
16761                                                for (int j = 1; j < is; j++) {
16762                                                        iax = da.getElementLongAbs(it.aIndex + j);
16763                                                        ox = (int) (iax >> ibx);
16764                                                        oai32data[it.oIndex + j] = ox;
16765                                                }
16766                                        }
16767                                }
16768                        } else if (as == 1) {
16769                                {
16770                                        while (it.hasNext()) {
16771                                                final long iax = it.aLong;
16772                                                final long ibx = it.bLong;
16773                                                int ox;
16774                                                ox = (int) (iax >> ibx);
16775                                                for (int j = 0; j < is; j++) {
16776                                                        oai32data[it.oIndex + j] = ox;
16777                                                }
16778                                        }
16779                                }
16780                        } else {
16781                                {
16782                                        while (it.hasNext()) {
16783                                                long iax = it.aLong;
16784                                                long ibx = it.bLong;
16785                                                int ox;
16786                                                ox = (int) (iax >> ibx);
16787                                                oai32data[it.oIndex] = ox;
16788                                                for (int j = 1; j < is; j++) {
16789                                                        iax = da.getElementLongAbs(it.aIndex + j);
16790                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16791                                                        ox = (int) (iax >> ibx);
16792                                                        oai32data[it.oIndex + j] = ox;
16793                                                }
16794                                        }
16795                                }
16796                        }
16797                        break;
16798                default:
16799                        throw new IllegalArgumentException("rightShift supports integer, compound integer datasets only");
16800                }
16801
16802                addBinaryOperatorName(da, db, result, ">>");
16803                return result;
16804        }
16805
16806        /**
16807         * unsignedRightShift operator
16808         * @param a first operand
16809         * @param b second operand
16810         * @return {@code a >>> b}, bitwise right shift of a by b with zeros added
16811         */
16812        public static Dataset unsignedRightShift(final Object a, final Object b) {
16813                return unsignedRightShift(a, b, null);
16814        }
16815
16816        /**
16817         * unsignedRightShift operator
16818         * @param a first operand
16819         * @param b second operand
16820         * @param o output can be null - in which case, a new dataset is created
16821         * @return {@code a >>> b}, bitwise right shift of a by b with zeros added
16822         */
16823        public static Dataset unsignedRightShift(final Object a, final Object b, final Dataset o) {
16824                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
16825                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
16826                BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
16827                it.setOutputDouble(false);
16828                final long unsignedMask;
16829                final Dataset result = it.getOutput();
16830                if (!result.isComplex()) {
16831                        boolean change = false;
16832                        if (da.isComplex()) {
16833                                da = da.getRealView();
16834                                change = true;
16835                        }
16836                        if (db.isComplex()) {
16837                                db = db.getRealView();
16838                                change = true;
16839                        }
16840                        if (change) {
16841                                it = BroadcastIterator.createIterator(da, db, result, true);
16842                                it.setOutputDouble(false);
16843                        }
16844                }
16845                final int is = result.getElementsPerItem();
16846                final int as = da.getElementsPerItem();
16847                final int bs = db.getElementsPerItem();
16848                final int dt = result.getDType();
16849
16850                switch(dt) {
16851                case Dataset.INT8:
16852                        final byte[] oi8data = ((ByteDataset) result).getData();
16853                        unsignedMask = 0xffL;
16854                        {
16855                                while (it.hasNext()) {
16856                                        final long iax = it.aLong;
16857                                        final long ibx = it.bLong;
16858                                        byte ox;
16859                                        ox = (byte) ((unsignedMask & iax) >>> ibx);
16860                                        oi8data[it.oIndex] = ox;
16861                                }
16862                        }
16863                        break;
16864                case Dataset.INT16:
16865                        final short[] oi16data = ((ShortDataset) result).getData();
16866                        unsignedMask = 0xffffL;
16867                        {
16868                                while (it.hasNext()) {
16869                                        final long iax = it.aLong;
16870                                        final long ibx = it.bLong;
16871                                        short ox;
16872                                        ox = (short) ((unsignedMask & iax) >>> ibx);
16873                                        oi16data[it.oIndex] = ox;
16874                                }
16875                        }
16876                        break;
16877                case Dataset.INT64:
16878                        final long[] oi64data = ((LongDataset) result).getData();
16879                        unsignedMask = 0xffffffffffffffffL;
16880                        {
16881                                while (it.hasNext()) {
16882                                        final long iax = it.aLong;
16883                                        final long ibx = it.bLong;
16884                                        long ox;
16885                                        ox = ((unsignedMask & iax) >>> ibx);
16886                                        oi64data[it.oIndex] = ox;
16887                                }
16888                        }
16889                        break;
16890                case Dataset.INT32:
16891                        final int[] oi32data = ((IntegerDataset) result).getData();
16892                        unsignedMask = 0xffffffffL;
16893                        {
16894                                while (it.hasNext()) {
16895                                        final long iax = it.aLong;
16896                                        final long ibx = it.bLong;
16897                                        int ox;
16898                                        ox = (int) ((unsignedMask & iax) >>> ibx);
16899                                        oi32data[it.oIndex] = ox;
16900                                }
16901                        }
16902                        break;
16903                case Dataset.ARRAYINT8:
16904                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
16905                        unsignedMask = 0xffL;
16906                        if (is == 1) {
16907                                {
16908                                        while (it.hasNext()) {
16909                                                final long iax = it.aLong;
16910                                                final long ibx = it.bLong;
16911                                                byte ox;
16912                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
16913                                                oai8data[it.oIndex] = ox;
16914                                        }
16915                                }
16916                        } else if (as < bs) {
16917                                {
16918                                        while (it.hasNext()) {
16919                                                final long iax = it.aLong;
16920                                                long ibx = it.bLong;
16921                                                byte ox;
16922                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
16923                                                oai8data[it.oIndex] = ox;
16924                                                for (int j = 1; j < is; j++) {
16925                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16926                                                        ox = (byte) ((unsignedMask & iax) >>> ibx);
16927                                                        oai8data[it.oIndex + j] = ox;
16928                                                }
16929                                        }
16930                                }
16931                        } else if (as > bs) {
16932                                {
16933                                        while (it.hasNext()) {
16934                                                long iax = it.aLong;
16935                                                final long ibx = it.bLong;
16936                                                byte ox;
16937                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
16938                                                oai8data[it.oIndex] = ox;
16939                                                for (int j = 1; j < is; j++) {
16940                                                        iax = da.getElementLongAbs(it.aIndex + j);
16941                                                        ox = (byte) ((unsignedMask & iax) >>> ibx);
16942                                                        oai8data[it.oIndex + j] = ox;
16943                                                }
16944                                        }
16945                                }
16946                        } else if (as == 1) {
16947                                {
16948                                        while (it.hasNext()) {
16949                                                final long iax = it.aLong;
16950                                                final long ibx = it.bLong;
16951                                                byte ox;
16952                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
16953                                                for (int j = 0; j < is; j++) {
16954                                                        oai8data[it.oIndex + j] = ox;
16955                                                }
16956                                        }
16957                                }
16958                        } else {
16959                                {
16960                                        while (it.hasNext()) {
16961                                                long iax = it.aLong;
16962                                                long ibx = it.bLong;
16963                                                byte ox;
16964                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
16965                                                oai8data[it.oIndex] = ox;
16966                                                for (int j = 1; j < is; j++) {
16967                                                        iax = da.getElementLongAbs(it.aIndex + j);
16968                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16969                                                        ox = (byte) ((unsignedMask & iax) >>> ibx);
16970                                                        oai8data[it.oIndex + j] = ox;
16971                                                }
16972                                        }
16973                                }
16974                        }
16975                        break;
16976                case Dataset.ARRAYINT16:
16977                        final short[] oai16data = ((CompoundShortDataset) result).getData();
16978                        unsignedMask = 0xffffL;
16979                        if (is == 1) {
16980                                {
16981                                        while (it.hasNext()) {
16982                                                final long iax = it.aLong;
16983                                                final long ibx = it.bLong;
16984                                                short ox;
16985                                                ox = (short) ((unsignedMask & iax) >>> ibx);
16986                                                oai16data[it.oIndex] = ox;
16987                                        }
16988                                }
16989                        } else if (as < bs) {
16990                                {
16991                                        while (it.hasNext()) {
16992                                                final long iax = it.aLong;
16993                                                long ibx = it.bLong;
16994                                                short ox;
16995                                                ox = (short) ((unsignedMask & iax) >>> ibx);
16996                                                oai16data[it.oIndex] = ox;
16997                                                for (int j = 1; j < is; j++) {
16998                                                        ibx = db.getElementLongAbs(it.bIndex + j);
16999                                                        ox = (short) ((unsignedMask & iax) >>> ibx);
17000                                                        oai16data[it.oIndex + j] = ox;
17001                                                }
17002                                        }
17003                                }
17004                        } else if (as > bs) {
17005                                {
17006                                        while (it.hasNext()) {
17007                                                long iax = it.aLong;
17008                                                final long ibx = it.bLong;
17009                                                short ox;
17010                                                ox = (short) ((unsignedMask & iax) >>> ibx);
17011                                                oai16data[it.oIndex] = ox;
17012                                                for (int j = 1; j < is; j++) {
17013                                                        iax = da.getElementLongAbs(it.aIndex + j);
17014                                                        ox = (short) ((unsignedMask & iax) >>> ibx);
17015                                                        oai16data[it.oIndex + j] = ox;
17016                                                }
17017                                        }
17018                                }
17019                        } else if (as == 1) {
17020                                {
17021                                        while (it.hasNext()) {
17022                                                final long iax = it.aLong;
17023                                                final long ibx = it.bLong;
17024                                                short ox;
17025                                                ox = (short) ((unsignedMask & iax) >>> ibx);
17026                                                for (int j = 0; j < is; j++) {
17027                                                        oai16data[it.oIndex + j] = ox;
17028                                                }
17029                                        }
17030                                }
17031                        } else {
17032                                {
17033                                        while (it.hasNext()) {
17034                                                long iax = it.aLong;
17035                                                long ibx = it.bLong;
17036                                                short ox;
17037                                                ox = (short) ((unsignedMask & iax) >>> ibx);
17038                                                oai16data[it.oIndex] = ox;
17039                                                for (int j = 1; j < is; j++) {
17040                                                        iax = da.getElementLongAbs(it.aIndex + j);
17041                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17042                                                        ox = (short) ((unsignedMask & iax) >>> ibx);
17043                                                        oai16data[it.oIndex + j] = ox;
17044                                                }
17045                                        }
17046                                }
17047                        }
17048                        break;
17049                case Dataset.ARRAYINT64:
17050                        final long[] oai64data = ((CompoundLongDataset) result).getData();
17051                        unsignedMask = 0xffffffffffffffffL;
17052                        if (is == 1) {
17053                                {
17054                                        while (it.hasNext()) {
17055                                                final long iax = it.aLong;
17056                                                final long ibx = it.bLong;
17057                                                long ox;
17058                                                ox = ((unsignedMask & iax) >>> ibx);
17059                                                oai64data[it.oIndex] = ox;
17060                                        }
17061                                }
17062                        } else if (as < bs) {
17063                                {
17064                                        while (it.hasNext()) {
17065                                                final long iax = it.aLong;
17066                                                long ibx = it.bLong;
17067                                                long ox;
17068                                                ox = ((unsignedMask & iax) >>> ibx);
17069                                                oai64data[it.oIndex] = ox;
17070                                                for (int j = 1; j < is; j++) {
17071                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17072                                                        ox = ((unsignedMask & iax) >>> ibx);
17073                                                        oai64data[it.oIndex + j] = ox;
17074                                                }
17075                                        }
17076                                }
17077                        } else if (as > bs) {
17078                                {
17079                                        while (it.hasNext()) {
17080                                                long iax = it.aLong;
17081                                                final long ibx = it.bLong;
17082                                                long ox;
17083                                                ox = ((unsignedMask & iax) >>> ibx);
17084                                                oai64data[it.oIndex] = ox;
17085                                                for (int j = 1; j < is; j++) {
17086                                                        iax = da.getElementLongAbs(it.aIndex + j);
17087                                                        ox = ((unsignedMask & iax) >>> ibx);
17088                                                        oai64data[it.oIndex + j] = ox;
17089                                                }
17090                                        }
17091                                }
17092                        } else if (as == 1) {
17093                                {
17094                                        while (it.hasNext()) {
17095                                                final long iax = it.aLong;
17096                                                final long ibx = it.bLong;
17097                                                long ox;
17098                                                ox = ((unsignedMask & iax) >>> ibx);
17099                                                for (int j = 0; j < is; j++) {
17100                                                        oai64data[it.oIndex + j] = ox;
17101                                                }
17102                                        }
17103                                }
17104                        } else {
17105                                {
17106                                        while (it.hasNext()) {
17107                                                long iax = it.aLong;
17108                                                long ibx = it.bLong;
17109                                                long ox;
17110                                                ox = ((unsignedMask & iax) >>> ibx);
17111                                                oai64data[it.oIndex] = ox;
17112                                                for (int j = 1; j < is; j++) {
17113                                                        iax = da.getElementLongAbs(it.aIndex + j);
17114                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17115                                                        ox = ((unsignedMask & iax) >>> ibx);
17116                                                        oai64data[it.oIndex + j] = ox;
17117                                                }
17118                                        }
17119                                }
17120                        }
17121                        break;
17122                case Dataset.ARRAYINT32:
17123                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
17124                        unsignedMask = 0xffffffffL;
17125                        if (is == 1) {
17126                                {
17127                                        while (it.hasNext()) {
17128                                                final long iax = it.aLong;
17129                                                final long ibx = it.bLong;
17130                                                int ox;
17131                                                ox = (int) ((unsignedMask & iax) >>> ibx);
17132                                                oai32data[it.oIndex] = ox;
17133                                        }
17134                                }
17135                        } else if (as < bs) {
17136                                {
17137                                        while (it.hasNext()) {
17138                                                final long iax = it.aLong;
17139                                                long ibx = it.bLong;
17140                                                int ox;
17141                                                ox = (int) ((unsignedMask & iax) >>> ibx);
17142                                                oai32data[it.oIndex] = ox;
17143                                                for (int j = 1; j < is; j++) {
17144                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17145                                                        ox = (int) ((unsignedMask & iax) >>> ibx);
17146                                                        oai32data[it.oIndex + j] = ox;
17147                                                }
17148                                        }
17149                                }
17150                        } else if (as > bs) {
17151                                {
17152                                        while (it.hasNext()) {
17153                                                long iax = it.aLong;
17154                                                final long ibx = it.bLong;
17155                                                int ox;
17156                                                ox = (int) ((unsignedMask & iax) >>> ibx);
17157                                                oai32data[it.oIndex] = ox;
17158                                                for (int j = 1; j < is; j++) {
17159                                                        iax = da.getElementLongAbs(it.aIndex + j);
17160                                                        ox = (int) ((unsignedMask & iax) >>> ibx);
17161                                                        oai32data[it.oIndex + j] = ox;
17162                                                }
17163                                        }
17164                                }
17165                        } else if (as == 1) {
17166                                {
17167                                        while (it.hasNext()) {
17168                                                final long iax = it.aLong;
17169                                                final long ibx = it.bLong;
17170                                                int ox;
17171                                                ox = (int) ((unsignedMask & iax) >>> ibx);
17172                                                for (int j = 0; j < is; j++) {
17173                                                        oai32data[it.oIndex + j] = ox;
17174                                                }
17175                                        }
17176                                }
17177                        } else {
17178                                {
17179                                        while (it.hasNext()) {
17180                                                long iax = it.aLong;
17181                                                long ibx = it.bLong;
17182                                                int ox;
17183                                                ox = (int) ((unsignedMask & iax) >>> ibx);
17184                                                oai32data[it.oIndex] = ox;
17185                                                for (int j = 1; j < is; j++) {
17186                                                        iax = da.getElementLongAbs(it.aIndex + j);
17187                                                        ibx = db.getElementLongAbs(it.bIndex + j);
17188                                                        ox = (int) ((unsignedMask & iax) >>> ibx);
17189                                                        oai32data[it.oIndex + j] = ox;
17190                                                }
17191                                        }
17192                                }
17193                        }
17194                        break;
17195                default:
17196                        throw new IllegalArgumentException("unsignedRightShift supports integer, compound integer datasets only");
17197                }
17198
17199                addBinaryOperatorName(da, db, result, ">>>");
17200                return result;
17201        }
17202
17203        /**
17204         * bitwiseInvert - {@code ~a}, bitwise invert (or NOT) each element
17205         * @param a single operand
17206         * @return dataset
17207         */
17208        public static Dataset bitwiseInvert(final Object a) {
17209                return bitwiseInvert(a, null);
17210        }
17211
17212        /**
17213         * bitwiseInvert - {@code ~a}, bitwise invert (or NOT) each element
17214         * @param a single operand
17215         * @param o output can be null - in which case, a new dataset is created
17216         * @return dataset
17217         */
17218        public static Dataset bitwiseInvert(final Object a, final Dataset o) {
17219                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
17220                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true, true, true);
17221                final Dataset result = it.getOutput();
17222                if (!result.isComplex()) {
17223                        if (da.isComplex()) {
17224                                da = da.getRealView();
17225                                it = new SingleInputBroadcastIterator(da, result, true, true, true);
17226                        }
17227                }
17228                final int is = result.getElementsPerItem();
17229                final int as = da.getElementsPerItem();
17230                final int dt = result.getDType();
17231
17232                switch(dt) {
17233                case Dataset.INT8:
17234                        final byte[] oi8data = ((ByteDataset) result).getData();
17235                        {
17236                                while (it.hasNext()) {
17237                                        final long ix = it.aLong;
17238                                        byte ox;
17239                                        ox = (byte) toLong(~ix);
17240                                        oi8data[it.oIndex] = ox;
17241                                }
17242                        }
17243                        break;
17244                case Dataset.INT16:
17245                        final short[] oi16data = ((ShortDataset) result).getData();
17246                        {
17247                                while (it.hasNext()) {
17248                                        final long ix = it.aLong;
17249                                        short ox;
17250                                        ox = (short) toLong(~ix);
17251                                        oi16data[it.oIndex] = ox;
17252                                }
17253                        }
17254                        break;
17255                case Dataset.INT64:
17256                        final long[] oi64data = ((LongDataset) result).getData();
17257                        {
17258                                while (it.hasNext()) {
17259                                        final long ix = it.aLong;
17260                                        long ox;
17261                                        ox = toLong(~ix);
17262                                        oi64data[it.oIndex] = ox;
17263                                }
17264                        }
17265                        break;
17266                case Dataset.INT32:
17267                        final int[] oi32data = ((IntegerDataset) result).getData();
17268                        {
17269                                while (it.hasNext()) {
17270                                        final long ix = it.aLong;
17271                                        int ox;
17272                                        ox = (int) toLong(~ix);
17273                                        oi32data[it.oIndex] = ox;
17274                                }
17275                        }
17276                        break;
17277                case Dataset.ARRAYINT8:
17278                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
17279                        if (is == 1) {
17280                                {
17281                                        while (it.hasNext()) {
17282                                                final long ix = it.aLong;
17283                                                byte ox;
17284                                                ox = (byte) toLong(~ix);
17285                                                oai8data[it.oIndex] = ox;
17286                                        }
17287                                }
17288                        } else if (as == 1) {
17289                                {
17290                                        while (it.hasNext()) {
17291                                                final long ix = it.aLong;
17292                                                byte ox;
17293                                                ox = (byte) toLong(~ix);
17294                                                for (int j = 0; j < is; j++) {
17295                                                        oai8data[it.oIndex + j] = ox;
17296                                                }
17297                                        }
17298                                }
17299                        } else {
17300                                {
17301                                        while (it.hasNext()) {
17302                                                for (int j = 0; j < is; j++) {
17303                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17304                                                        byte ox;
17305                                                        ox = (byte) toLong(~ix);
17306                                                        oai8data[it.oIndex + j] = ox;
17307                                                }
17308                                        }
17309                                }
17310                        }
17311                        break;
17312                case Dataset.ARRAYINT16:
17313                        final short[] oai16data = ((CompoundShortDataset) result).getData();
17314                        if (is == 1) {
17315                                {
17316                                        while (it.hasNext()) {
17317                                                final long ix = it.aLong;
17318                                                short ox;
17319                                                ox = (short) toLong(~ix);
17320                                                oai16data[it.oIndex] = ox;
17321                                        }
17322                                }
17323                        } else if (as == 1) {
17324                                {
17325                                        while (it.hasNext()) {
17326                                                final long ix = it.aLong;
17327                                                short ox;
17328                                                ox = (short) toLong(~ix);
17329                                                for (int j = 0; j < is; j++) {
17330                                                        oai16data[it.oIndex + j] = ox;
17331                                                }
17332                                        }
17333                                }
17334                        } else {
17335                                {
17336                                        while (it.hasNext()) {
17337                                                for (int j = 0; j < is; j++) {
17338                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17339                                                        short ox;
17340                                                        ox = (short) toLong(~ix);
17341                                                        oai16data[it.oIndex + j] = ox;
17342                                                }
17343                                        }
17344                                }
17345                        }
17346                        break;
17347                case Dataset.ARRAYINT64:
17348                        final long[] oai64data = ((CompoundLongDataset) result).getData();
17349                        if (is == 1) {
17350                                {
17351                                        while (it.hasNext()) {
17352                                                final long ix = it.aLong;
17353                                                long ox;
17354                                                ox = toLong(~ix);
17355                                                oai64data[it.oIndex] = ox;
17356                                        }
17357                                }
17358                        } else if (as == 1) {
17359                                {
17360                                        while (it.hasNext()) {
17361                                                final long ix = it.aLong;
17362                                                long ox;
17363                                                ox = toLong(~ix);
17364                                                for (int j = 0; j < is; j++) {
17365                                                        oai64data[it.oIndex + j] = ox;
17366                                                }
17367                                        }
17368                                }
17369                        } else {
17370                                {
17371                                        while (it.hasNext()) {
17372                                                for (int j = 0; j < is; j++) {
17373                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17374                                                        long ox;
17375                                                        ox = toLong(~ix);
17376                                                        oai64data[it.oIndex + j] = ox;
17377                                                }
17378                                        }
17379                                }
17380                        }
17381                        break;
17382                case Dataset.ARRAYINT32:
17383                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
17384                        if (is == 1) {
17385                                {
17386                                        while (it.hasNext()) {
17387                                                final long ix = it.aLong;
17388                                                int ox;
17389                                                ox = (int) toLong(~ix);
17390                                                oai32data[it.oIndex] = ox;
17391                                        }
17392                                }
17393                        } else if (as == 1) {
17394                                {
17395                                        while (it.hasNext()) {
17396                                                final long ix = it.aLong;
17397                                                int ox;
17398                                                ox = (int) toLong(~ix);
17399                                                for (int j = 0; j < is; j++) {
17400                                                        oai32data[it.oIndex + j] = ox;
17401                                                }
17402                                        }
17403                                }
17404                        } else {
17405                                {
17406                                        while (it.hasNext()) {
17407                                                for (int j = 0; j < is; j++) {
17408                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17409                                                        int ox;
17410                                                        ox = (int) toLong(~ix);
17411                                                        oai32data[it.oIndex + j] = ox;
17412                                                }
17413                                        }
17414                                }
17415                        }
17416                        break;
17417                default:
17418                        throw new IllegalArgumentException("bitwiseInvert supports integer, compound integer datasets only");
17419                }
17420
17421                addFunctionName(result, "bitwiseInvert");
17422                return result;
17423        }
17424
17425        /**
17426         * sin - evaluate the sine function on each element of the dataset
17427         * @param a single operand
17428         * @return dataset
17429         */
17430        public static Dataset sin(final Object a) {
17431                return sin(a, null);
17432        }
17433
17434        /**
17435         * sin - evaluate the sine function on each element of the dataset
17436         * @param a single operand
17437         * @param o output can be null - in which case, a new dataset is created
17438         * @return dataset
17439         */
17440        public static Dataset sin(final Object a, final Dataset o) {
17441                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
17442                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
17443                final Dataset result = it.getOutput();
17444                if (!result.isComplex()) {
17445                        if (da.isComplex()) {
17446                                da = da.getRealView();
17447                                it = new SingleInputBroadcastIterator(da, result, true);
17448                        }
17449                }
17450                final int is = result.getElementsPerItem();
17451                final int as = da.getElementsPerItem();
17452                final int dt = result.getDType();
17453
17454                switch(dt) {
17455                case Dataset.INT8:
17456                        final byte[] oi8data = ((ByteDataset) result).getData();
17457                        if (it.isOutputDouble()) {
17458                                while (it.hasNext()) {
17459                                        final double ix = it.aDouble;
17460                                        byte ox;
17461                                        ox = (byte) toLong(Math.sin(ix));
17462                                        oi8data[it.oIndex] = ox;
17463                                }
17464                        } else {
17465                                while (it.hasNext()) {
17466                                        final long ix = it.aLong;
17467                                        byte ox;
17468                                        ox = (byte) toLong(Math.sin(ix));
17469                                        oi8data[it.oIndex] = ox;
17470                                }
17471                        }
17472                        break;
17473                case Dataset.INT16:
17474                        final short[] oi16data = ((ShortDataset) result).getData();
17475                        if (it.isOutputDouble()) {
17476                                while (it.hasNext()) {
17477                                        final double ix = it.aDouble;
17478                                        short ox;
17479                                        ox = (short) toLong(Math.sin(ix));
17480                                        oi16data[it.oIndex] = ox;
17481                                }
17482                        } else {
17483                                while (it.hasNext()) {
17484                                        final long ix = it.aLong;
17485                                        short ox;
17486                                        ox = (short) toLong(Math.sin(ix));
17487                                        oi16data[it.oIndex] = ox;
17488                                }
17489                        }
17490                        break;
17491                case Dataset.INT64:
17492                        final long[] oi64data = ((LongDataset) result).getData();
17493                        if (it.isOutputDouble()) {
17494                                while (it.hasNext()) {
17495                                        final double ix = it.aDouble;
17496                                        long ox;
17497                                        ox = toLong(Math.sin(ix));
17498                                        oi64data[it.oIndex] = ox;
17499                                }
17500                        } else {
17501                                while (it.hasNext()) {
17502                                        final long ix = it.aLong;
17503                                        long ox;
17504                                        ox = toLong(Math.sin(ix));
17505                                        oi64data[it.oIndex] = ox;
17506                                }
17507                        }
17508                        break;
17509                case Dataset.INT32:
17510                        final int[] oi32data = ((IntegerDataset) result).getData();
17511                        if (it.isOutputDouble()) {
17512                                while (it.hasNext()) {
17513                                        final double ix = it.aDouble;
17514                                        int ox;
17515                                        ox = (int) toLong(Math.sin(ix));
17516                                        oi32data[it.oIndex] = ox;
17517                                }
17518                        } else {
17519                                while (it.hasNext()) {
17520                                        final long ix = it.aLong;
17521                                        int ox;
17522                                        ox = (int) toLong(Math.sin(ix));
17523                                        oi32data[it.oIndex] = ox;
17524                                }
17525                        }
17526                        break;
17527                case Dataset.ARRAYINT8:
17528                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
17529                        if (is == 1) {
17530                                if (it.isOutputDouble()) {
17531                                        while (it.hasNext()) {
17532                                                final double ix = it.aDouble;
17533                                                byte ox;
17534                                                ox = (byte) toLong(Math.sin(ix));
17535                                                oai8data[it.oIndex] = ox;
17536                                        }
17537                                } else {
17538                                        while (it.hasNext()) {
17539                                                final long ix = it.aLong;
17540                                                byte ox;
17541                                                ox = (byte) toLong(Math.sin(ix));
17542                                                oai8data[it.oIndex] = ox;
17543                                        }
17544                                }
17545                        } else if (as == 1) {
17546                                if (it.isOutputDouble()) {
17547                                        while (it.hasNext()) {
17548                                                final double ix = it.aDouble;
17549                                                byte ox;
17550                                                ox = (byte) toLong(Math.sin(ix));
17551                                                for (int j = 0; j < is; j++) {
17552                                                        oai8data[it.oIndex + j] = ox;
17553                                                }
17554                                        }
17555                                } else {
17556                                        while (it.hasNext()) {
17557                                                final long ix = it.aLong;
17558                                                byte ox;
17559                                                ox = (byte) toLong(Math.sin(ix));
17560                                                for (int j = 0; j < is; j++) {
17561                                                        oai8data[it.oIndex + j] = ox;
17562                                                }
17563                                        }
17564                                }
17565                        } else {
17566                                if (it.isOutputDouble()) {
17567                                        while (it.hasNext()) {
17568                                                for (int j = 0; j < is; j++) {
17569                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
17570                                                        byte ox;
17571                                                        ox = (byte) toLong(Math.sin(ix));
17572                                                        oai8data[it.oIndex + j] = ox;
17573                                                }
17574                                        }
17575                                } else {
17576                                        while (it.hasNext()) {
17577                                                for (int j = 0; j < is; j++) {
17578                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17579                                                        byte ox;
17580                                                        ox = (byte) toLong(Math.sin(ix));
17581                                                        oai8data[it.oIndex + j] = ox;
17582                                                }
17583                                        }
17584                                }
17585                        }
17586                        break;
17587                case Dataset.ARRAYINT16:
17588                        final short[] oai16data = ((CompoundShortDataset) result).getData();
17589                        if (is == 1) {
17590                                if (it.isOutputDouble()) {
17591                                        while (it.hasNext()) {
17592                                                final double ix = it.aDouble;
17593                                                short ox;
17594                                                ox = (short) toLong(Math.sin(ix));
17595                                                oai16data[it.oIndex] = ox;
17596                                        }
17597                                } else {
17598                                        while (it.hasNext()) {
17599                                                final long ix = it.aLong;
17600                                                short ox;
17601                                                ox = (short) toLong(Math.sin(ix));
17602                                                oai16data[it.oIndex] = ox;
17603                                        }
17604                                }
17605                        } else if (as == 1) {
17606                                if (it.isOutputDouble()) {
17607                                        while (it.hasNext()) {
17608                                                final double ix = it.aDouble;
17609                                                short ox;
17610                                                ox = (short) toLong(Math.sin(ix));
17611                                                for (int j = 0; j < is; j++) {
17612                                                        oai16data[it.oIndex + j] = ox;
17613                                                }
17614                                        }
17615                                } else {
17616                                        while (it.hasNext()) {
17617                                                final long ix = it.aLong;
17618                                                short ox;
17619                                                ox = (short) toLong(Math.sin(ix));
17620                                                for (int j = 0; j < is; j++) {
17621                                                        oai16data[it.oIndex + j] = ox;
17622                                                }
17623                                        }
17624                                }
17625                        } else {
17626                                if (it.isOutputDouble()) {
17627                                        while (it.hasNext()) {
17628                                                for (int j = 0; j < is; j++) {
17629                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
17630                                                        short ox;
17631                                                        ox = (short) toLong(Math.sin(ix));
17632                                                        oai16data[it.oIndex + j] = ox;
17633                                                }
17634                                        }
17635                                } else {
17636                                        while (it.hasNext()) {
17637                                                for (int j = 0; j < is; j++) {
17638                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17639                                                        short ox;
17640                                                        ox = (short) toLong(Math.sin(ix));
17641                                                        oai16data[it.oIndex + j] = ox;
17642                                                }
17643                                        }
17644                                }
17645                        }
17646                        break;
17647                case Dataset.ARRAYINT64:
17648                        final long[] oai64data = ((CompoundLongDataset) result).getData();
17649                        if (is == 1) {
17650                                if (it.isOutputDouble()) {
17651                                        while (it.hasNext()) {
17652                                                final double ix = it.aDouble;
17653                                                long ox;
17654                                                ox = toLong(Math.sin(ix));
17655                                                oai64data[it.oIndex] = ox;
17656                                        }
17657                                } else {
17658                                        while (it.hasNext()) {
17659                                                final long ix = it.aLong;
17660                                                long ox;
17661                                                ox = toLong(Math.sin(ix));
17662                                                oai64data[it.oIndex] = ox;
17663                                        }
17664                                }
17665                        } else if (as == 1) {
17666                                if (it.isOutputDouble()) {
17667                                        while (it.hasNext()) {
17668                                                final double ix = it.aDouble;
17669                                                long ox;
17670                                                ox = toLong(Math.sin(ix));
17671                                                for (int j = 0; j < is; j++) {
17672                                                        oai64data[it.oIndex + j] = ox;
17673                                                }
17674                                        }
17675                                } else {
17676                                        while (it.hasNext()) {
17677                                                final long ix = it.aLong;
17678                                                long ox;
17679                                                ox = toLong(Math.sin(ix));
17680                                                for (int j = 0; j < is; j++) {
17681                                                        oai64data[it.oIndex + j] = ox;
17682                                                }
17683                                        }
17684                                }
17685                        } else {
17686                                if (it.isOutputDouble()) {
17687                                        while (it.hasNext()) {
17688                                                for (int j = 0; j < is; j++) {
17689                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
17690                                                        long ox;
17691                                                        ox = toLong(Math.sin(ix));
17692                                                        oai64data[it.oIndex + j] = ox;
17693                                                }
17694                                        }
17695                                } else {
17696                                        while (it.hasNext()) {
17697                                                for (int j = 0; j < is; j++) {
17698                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17699                                                        long ox;
17700                                                        ox = toLong(Math.sin(ix));
17701                                                        oai64data[it.oIndex + j] = ox;
17702                                                }
17703                                        }
17704                                }
17705                        }
17706                        break;
17707                case Dataset.ARRAYINT32:
17708                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
17709                        if (is == 1) {
17710                                if (it.isOutputDouble()) {
17711                                        while (it.hasNext()) {
17712                                                final double ix = it.aDouble;
17713                                                int ox;
17714                                                ox = (int) toLong(Math.sin(ix));
17715                                                oai32data[it.oIndex] = ox;
17716                                        }
17717                                } else {
17718                                        while (it.hasNext()) {
17719                                                final long ix = it.aLong;
17720                                                int ox;
17721                                                ox = (int) toLong(Math.sin(ix));
17722                                                oai32data[it.oIndex] = ox;
17723                                        }
17724                                }
17725                        } else if (as == 1) {
17726                                if (it.isOutputDouble()) {
17727                                        while (it.hasNext()) {
17728                                                final double ix = it.aDouble;
17729                                                int ox;
17730                                                ox = (int) toLong(Math.sin(ix));
17731                                                for (int j = 0; j < is; j++) {
17732                                                        oai32data[it.oIndex + j] = ox;
17733                                                }
17734                                        }
17735                                } else {
17736                                        while (it.hasNext()) {
17737                                                final long ix = it.aLong;
17738                                                int ox;
17739                                                ox = (int) toLong(Math.sin(ix));
17740                                                for (int j = 0; j < is; j++) {
17741                                                        oai32data[it.oIndex + j] = ox;
17742                                                }
17743                                        }
17744                                }
17745                        } else {
17746                                if (it.isOutputDouble()) {
17747                                        while (it.hasNext()) {
17748                                                for (int j = 0; j < is; j++) {
17749                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
17750                                                        int ox;
17751                                                        ox = (int) toLong(Math.sin(ix));
17752                                                        oai32data[it.oIndex + j] = ox;
17753                                                }
17754                                        }
17755                                } else {
17756                                        while (it.hasNext()) {
17757                                                for (int j = 0; j < is; j++) {
17758                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17759                                                        int ox;
17760                                                        ox = (int) toLong(Math.sin(ix));
17761                                                        oai32data[it.oIndex + j] = ox;
17762                                                }
17763                                        }
17764                                }
17765                        }
17766                        break;
17767                case Dataset.FLOAT32:
17768                        final float[] of32data = ((FloatDataset) result).getData();
17769                        if (it.isOutputDouble()) {
17770                                while (it.hasNext()) {
17771                                        final double ix = it.aDouble;
17772                                        float ox;
17773                                        ox = (float) (Math.sin(ix));
17774                                        of32data[it.oIndex] = ox;
17775                                }
17776                        } else {
17777                                while (it.hasNext()) {
17778                                        final long ix = it.aLong;
17779                                        float ox;
17780                                        ox = (float) (Math.sin(ix));
17781                                        of32data[it.oIndex] = ox;
17782                                }
17783                        }
17784                        break;
17785                case Dataset.FLOAT64:
17786                        final double[] of64data = ((DoubleDataset) result).getData();
17787                        if (it.isOutputDouble()) {
17788                                while (it.hasNext()) {
17789                                        final double ix = it.aDouble;
17790                                        double ox;
17791                                        ox = (Math.sin(ix));
17792                                        of64data[it.oIndex] = ox;
17793                                }
17794                        } else {
17795                                while (it.hasNext()) {
17796                                        final long ix = it.aLong;
17797                                        double ox;
17798                                        ox = (Math.sin(ix));
17799                                        of64data[it.oIndex] = ox;
17800                                }
17801                        }
17802                        break;
17803                case Dataset.ARRAYFLOAT32:
17804                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
17805                        if (is == 1) {
17806                                if (it.isOutputDouble()) {
17807                                        while (it.hasNext()) {
17808                                                final double ix = it.aDouble;
17809                                                float ox;
17810                                                ox = (float) (Math.sin(ix));
17811                                                oaf32data[it.oIndex] = ox;
17812                                        }
17813                                } else {
17814                                        while (it.hasNext()) {
17815                                                final long ix = it.aLong;
17816                                                float ox;
17817                                                ox = (float) (Math.sin(ix));
17818                                                oaf32data[it.oIndex] = ox;
17819                                        }
17820                                }
17821                        } else if (as == 1) {
17822                                if (it.isOutputDouble()) {
17823                                        while (it.hasNext()) {
17824                                                final double ix = it.aDouble;
17825                                                float ox;
17826                                                ox = (float) (Math.sin(ix));
17827                                                for (int j = 0; j < is; j++) {
17828                                                        oaf32data[it.oIndex + j] = ox;
17829                                                }
17830                                        }
17831                                } else {
17832                                        while (it.hasNext()) {
17833                                                final long ix = it.aLong;
17834                                                float ox;
17835                                                ox = (float) (Math.sin(ix));
17836                                                for (int j = 0; j < is; j++) {
17837                                                        oaf32data[it.oIndex + j] = ox;
17838                                                }
17839                                        }
17840                                }
17841                        } else {
17842                                if (it.isOutputDouble()) {
17843                                        while (it.hasNext()) {
17844                                                for (int j = 0; j < is; j++) {
17845                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
17846                                                        float ox;
17847                                                        ox = (float) (Math.sin(ix));
17848                                                        oaf32data[it.oIndex + j] = ox;
17849                                                }
17850                                        }
17851                                } else {
17852                                        while (it.hasNext()) {
17853                                                for (int j = 0; j < is; j++) {
17854                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17855                                                        float ox;
17856                                                        ox = (float) (Math.sin(ix));
17857                                                        oaf32data[it.oIndex + j] = ox;
17858                                                }
17859                                        }
17860                                }
17861                        }
17862                        break;
17863                case Dataset.ARRAYFLOAT64:
17864                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
17865                        if (is == 1) {
17866                                if (it.isOutputDouble()) {
17867                                        while (it.hasNext()) {
17868                                                final double ix = it.aDouble;
17869                                                double ox;
17870                                                ox = (Math.sin(ix));
17871                                                oaf64data[it.oIndex] = ox;
17872                                        }
17873                                } else {
17874                                        while (it.hasNext()) {
17875                                                final long ix = it.aLong;
17876                                                double ox;
17877                                                ox = (Math.sin(ix));
17878                                                oaf64data[it.oIndex] = ox;
17879                                        }
17880                                }
17881                        } else if (as == 1) {
17882                                if (it.isOutputDouble()) {
17883                                        while (it.hasNext()) {
17884                                                final double ix = it.aDouble;
17885                                                double ox;
17886                                                ox = (Math.sin(ix));
17887                                                for (int j = 0; j < is; j++) {
17888                                                        oaf64data[it.oIndex + j] = ox;
17889                                                }
17890                                        }
17891                                } else {
17892                                        while (it.hasNext()) {
17893                                                final long ix = it.aLong;
17894                                                double ox;
17895                                                ox = (Math.sin(ix));
17896                                                for (int j = 0; j < is; j++) {
17897                                                        oaf64data[it.oIndex + j] = ox;
17898                                                }
17899                                        }
17900                                }
17901                        } else {
17902                                if (it.isOutputDouble()) {
17903                                        while (it.hasNext()) {
17904                                                for (int j = 0; j < is; j++) {
17905                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
17906                                                        double ox;
17907                                                        ox = (Math.sin(ix));
17908                                                        oaf64data[it.oIndex + j] = ox;
17909                                                }
17910                                        }
17911                                } else {
17912                                        while (it.hasNext()) {
17913                                                for (int j = 0; j < is; j++) {
17914                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
17915                                                        double ox;
17916                                                        ox = (Math.sin(ix));
17917                                                        oaf64data[it.oIndex + j] = ox;
17918                                                }
17919                                        }
17920                                }
17921                        }
17922                        break;
17923                case Dataset.COMPLEX64:
17924                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
17925                        if (!da.isComplex()) {
17926                                if (it.isOutputDouble()) {
17927                                        final double iy = 0;
17928                                        while (it.hasNext()) {
17929                                                final double ix = it.aDouble;
17930                                                float ox;
17931                                                float oy;
17932                                                ox = (float) (Math.sin(ix)*Math.cosh(iy));
17933                                                oy = (float) (Math.cos(ix)*Math.sinh(iy));
17934                                                oc64data[it.oIndex] = ox;
17935                                                oc64data[it.oIndex + 1] = oy;
17936                                        }
17937                                } else {
17938                                        final long iy = 0;
17939                                        while (it.hasNext()) {
17940                                                final long ix = it.aLong;
17941                                                float ox;
17942                                                float oy;
17943                                                ox = (float) toLong(Math.sin(ix)*Math.cosh(iy));
17944                                                oy = (float) toLong(Math.cos(ix)*Math.sinh(iy));
17945                                                oc64data[it.oIndex] = ox;
17946                                                oc64data[it.oIndex + 1] = oy;
17947                                        }
17948                                }
17949                        } else {
17950                                while (it.hasNext()) {
17951                                        final double ix = it.aDouble;
17952                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
17953                                        float ox;
17954                                        float oy;
17955                                        ox = (float) (Math.sin(ix)*Math.cosh(iy));
17956                                        oy = (float) (Math.cos(ix)*Math.sinh(iy));
17957                                        oc64data[it.oIndex] = ox;
17958                                        oc64data[it.oIndex + 1] = oy;
17959                                }
17960                        }
17961                        break;
17962                case Dataset.COMPLEX128:
17963                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
17964                        if (!da.isComplex()) {
17965                                if (it.isOutputDouble()) {
17966                                        final double iy = 0;
17967                                        while (it.hasNext()) {
17968                                                final double ix = it.aDouble;
17969                                                double ox;
17970                                                double oy;
17971                                                ox = (Math.sin(ix)*Math.cosh(iy));
17972                                                oy = (Math.cos(ix)*Math.sinh(iy));
17973                                                oc128data[it.oIndex] = ox;
17974                                                oc128data[it.oIndex + 1] = oy;
17975                                        }
17976                                } else {
17977                                        final long iy = 0;
17978                                        while (it.hasNext()) {
17979                                                final long ix = it.aLong;
17980                                                double ox;
17981                                                double oy;
17982                                                ox = (double) (Math.sin(ix)*Math.cosh(iy));
17983                                                oy = (double) (Math.cos(ix)*Math.sinh(iy));
17984                                                oc128data[it.oIndex] = ox;
17985                                                oc128data[it.oIndex + 1] = oy;
17986                                        }
17987                                }
17988                        } else {
17989                                while (it.hasNext()) {
17990                                        final double ix = it.aDouble;
17991                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
17992                                        double ox;
17993                                        double oy;
17994                                        ox = (Math.sin(ix)*Math.cosh(iy));
17995                                        oy = (Math.cos(ix)*Math.sinh(iy));
17996                                        oc128data[it.oIndex] = ox;
17997                                        oc128data[it.oIndex + 1] = oy;
17998                                }
17999                        }
18000                        break;
18001                default:
18002                        throw new IllegalArgumentException("sin supports integer, compound integer, real, compound real, complex datasets only");
18003                }
18004
18005                addFunctionName(result, "sin");
18006                return result;
18007        }
18008
18009        /**
18010         * cos - evaluate the cosine function on each element of the dataset
18011         * @param a single operand
18012         * @return dataset
18013         */
18014        public static Dataset cos(final Object a) {
18015                return cos(a, null);
18016        }
18017
18018        /**
18019         * cos - evaluate the cosine function on each element of the dataset
18020         * @param a single operand
18021         * @param o output can be null - in which case, a new dataset is created
18022         * @return dataset
18023         */
18024        public static Dataset cos(final Object a, final Dataset o) {
18025                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
18026                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
18027                final Dataset result = it.getOutput();
18028                if (!result.isComplex()) {
18029                        if (da.isComplex()) {
18030                                da = da.getRealView();
18031                                it = new SingleInputBroadcastIterator(da, result, true);
18032                        }
18033                }
18034                final int is = result.getElementsPerItem();
18035                final int as = da.getElementsPerItem();
18036                final int dt = result.getDType();
18037
18038                switch(dt) {
18039                case Dataset.INT8:
18040                        final byte[] oi8data = ((ByteDataset) result).getData();
18041                        if (it.isOutputDouble()) {
18042                                while (it.hasNext()) {
18043                                        final double ix = it.aDouble;
18044                                        byte ox;
18045                                        ox = (byte) toLong(Math.cos(ix));
18046                                        oi8data[it.oIndex] = ox;
18047                                }
18048                        } else {
18049                                while (it.hasNext()) {
18050                                        final long ix = it.aLong;
18051                                        byte ox;
18052                                        ox = (byte) toLong(Math.cos(ix));
18053                                        oi8data[it.oIndex] = ox;
18054                                }
18055                        }
18056                        break;
18057                case Dataset.INT16:
18058                        final short[] oi16data = ((ShortDataset) result).getData();
18059                        if (it.isOutputDouble()) {
18060                                while (it.hasNext()) {
18061                                        final double ix = it.aDouble;
18062                                        short ox;
18063                                        ox = (short) toLong(Math.cos(ix));
18064                                        oi16data[it.oIndex] = ox;
18065                                }
18066                        } else {
18067                                while (it.hasNext()) {
18068                                        final long ix = it.aLong;
18069                                        short ox;
18070                                        ox = (short) toLong(Math.cos(ix));
18071                                        oi16data[it.oIndex] = ox;
18072                                }
18073                        }
18074                        break;
18075                case Dataset.INT64:
18076                        final long[] oi64data = ((LongDataset) result).getData();
18077                        if (it.isOutputDouble()) {
18078                                while (it.hasNext()) {
18079                                        final double ix = it.aDouble;
18080                                        long ox;
18081                                        ox = toLong(Math.cos(ix));
18082                                        oi64data[it.oIndex] = ox;
18083                                }
18084                        } else {
18085                                while (it.hasNext()) {
18086                                        final long ix = it.aLong;
18087                                        long ox;
18088                                        ox = toLong(Math.cos(ix));
18089                                        oi64data[it.oIndex] = ox;
18090                                }
18091                        }
18092                        break;
18093                case Dataset.INT32:
18094                        final int[] oi32data = ((IntegerDataset) result).getData();
18095                        if (it.isOutputDouble()) {
18096                                while (it.hasNext()) {
18097                                        final double ix = it.aDouble;
18098                                        int ox;
18099                                        ox = (int) toLong(Math.cos(ix));
18100                                        oi32data[it.oIndex] = ox;
18101                                }
18102                        } else {
18103                                while (it.hasNext()) {
18104                                        final long ix = it.aLong;
18105                                        int ox;
18106                                        ox = (int) toLong(Math.cos(ix));
18107                                        oi32data[it.oIndex] = ox;
18108                                }
18109                        }
18110                        break;
18111                case Dataset.ARRAYINT8:
18112                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
18113                        if (is == 1) {
18114                                if (it.isOutputDouble()) {
18115                                        while (it.hasNext()) {
18116                                                final double ix = it.aDouble;
18117                                                byte ox;
18118                                                ox = (byte) toLong(Math.cos(ix));
18119                                                oai8data[it.oIndex] = ox;
18120                                        }
18121                                } else {
18122                                        while (it.hasNext()) {
18123                                                final long ix = it.aLong;
18124                                                byte ox;
18125                                                ox = (byte) toLong(Math.cos(ix));
18126                                                oai8data[it.oIndex] = ox;
18127                                        }
18128                                }
18129                        } else if (as == 1) {
18130                                if (it.isOutputDouble()) {
18131                                        while (it.hasNext()) {
18132                                                final double ix = it.aDouble;
18133                                                byte ox;
18134                                                ox = (byte) toLong(Math.cos(ix));
18135                                                for (int j = 0; j < is; j++) {
18136                                                        oai8data[it.oIndex + j] = ox;
18137                                                }
18138                                        }
18139                                } else {
18140                                        while (it.hasNext()) {
18141                                                final long ix = it.aLong;
18142                                                byte ox;
18143                                                ox = (byte) toLong(Math.cos(ix));
18144                                                for (int j = 0; j < is; j++) {
18145                                                        oai8data[it.oIndex + j] = ox;
18146                                                }
18147                                        }
18148                                }
18149                        } else {
18150                                if (it.isOutputDouble()) {
18151                                        while (it.hasNext()) {
18152                                                for (int j = 0; j < is; j++) {
18153                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18154                                                        byte ox;
18155                                                        ox = (byte) toLong(Math.cos(ix));
18156                                                        oai8data[it.oIndex + j] = ox;
18157                                                }
18158                                        }
18159                                } else {
18160                                        while (it.hasNext()) {
18161                                                for (int j = 0; j < is; j++) {
18162                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18163                                                        byte ox;
18164                                                        ox = (byte) toLong(Math.cos(ix));
18165                                                        oai8data[it.oIndex + j] = ox;
18166                                                }
18167                                        }
18168                                }
18169                        }
18170                        break;
18171                case Dataset.ARRAYINT16:
18172                        final short[] oai16data = ((CompoundShortDataset) result).getData();
18173                        if (is == 1) {
18174                                if (it.isOutputDouble()) {
18175                                        while (it.hasNext()) {
18176                                                final double ix = it.aDouble;
18177                                                short ox;
18178                                                ox = (short) toLong(Math.cos(ix));
18179                                                oai16data[it.oIndex] = ox;
18180                                        }
18181                                } else {
18182                                        while (it.hasNext()) {
18183                                                final long ix = it.aLong;
18184                                                short ox;
18185                                                ox = (short) toLong(Math.cos(ix));
18186                                                oai16data[it.oIndex] = ox;
18187                                        }
18188                                }
18189                        } else if (as == 1) {
18190                                if (it.isOutputDouble()) {
18191                                        while (it.hasNext()) {
18192                                                final double ix = it.aDouble;
18193                                                short ox;
18194                                                ox = (short) toLong(Math.cos(ix));
18195                                                for (int j = 0; j < is; j++) {
18196                                                        oai16data[it.oIndex + j] = ox;
18197                                                }
18198                                        }
18199                                } else {
18200                                        while (it.hasNext()) {
18201                                                final long ix = it.aLong;
18202                                                short ox;
18203                                                ox = (short) toLong(Math.cos(ix));
18204                                                for (int j = 0; j < is; j++) {
18205                                                        oai16data[it.oIndex + j] = ox;
18206                                                }
18207                                        }
18208                                }
18209                        } else {
18210                                if (it.isOutputDouble()) {
18211                                        while (it.hasNext()) {
18212                                                for (int j = 0; j < is; j++) {
18213                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18214                                                        short ox;
18215                                                        ox = (short) toLong(Math.cos(ix));
18216                                                        oai16data[it.oIndex + j] = ox;
18217                                                }
18218                                        }
18219                                } else {
18220                                        while (it.hasNext()) {
18221                                                for (int j = 0; j < is; j++) {
18222                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18223                                                        short ox;
18224                                                        ox = (short) toLong(Math.cos(ix));
18225                                                        oai16data[it.oIndex + j] = ox;
18226                                                }
18227                                        }
18228                                }
18229                        }
18230                        break;
18231                case Dataset.ARRAYINT64:
18232                        final long[] oai64data = ((CompoundLongDataset) result).getData();
18233                        if (is == 1) {
18234                                if (it.isOutputDouble()) {
18235                                        while (it.hasNext()) {
18236                                                final double ix = it.aDouble;
18237                                                long ox;
18238                                                ox = toLong(Math.cos(ix));
18239                                                oai64data[it.oIndex] = ox;
18240                                        }
18241                                } else {
18242                                        while (it.hasNext()) {
18243                                                final long ix = it.aLong;
18244                                                long ox;
18245                                                ox = toLong(Math.cos(ix));
18246                                                oai64data[it.oIndex] = ox;
18247                                        }
18248                                }
18249                        } else if (as == 1) {
18250                                if (it.isOutputDouble()) {
18251                                        while (it.hasNext()) {
18252                                                final double ix = it.aDouble;
18253                                                long ox;
18254                                                ox = toLong(Math.cos(ix));
18255                                                for (int j = 0; j < is; j++) {
18256                                                        oai64data[it.oIndex + j] = ox;
18257                                                }
18258                                        }
18259                                } else {
18260                                        while (it.hasNext()) {
18261                                                final long ix = it.aLong;
18262                                                long ox;
18263                                                ox = toLong(Math.cos(ix));
18264                                                for (int j = 0; j < is; j++) {
18265                                                        oai64data[it.oIndex + j] = ox;
18266                                                }
18267                                        }
18268                                }
18269                        } else {
18270                                if (it.isOutputDouble()) {
18271                                        while (it.hasNext()) {
18272                                                for (int j = 0; j < is; j++) {
18273                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18274                                                        long ox;
18275                                                        ox = toLong(Math.cos(ix));
18276                                                        oai64data[it.oIndex + j] = ox;
18277                                                }
18278                                        }
18279                                } else {
18280                                        while (it.hasNext()) {
18281                                                for (int j = 0; j < is; j++) {
18282                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18283                                                        long ox;
18284                                                        ox = toLong(Math.cos(ix));
18285                                                        oai64data[it.oIndex + j] = ox;
18286                                                }
18287                                        }
18288                                }
18289                        }
18290                        break;
18291                case Dataset.ARRAYINT32:
18292                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
18293                        if (is == 1) {
18294                                if (it.isOutputDouble()) {
18295                                        while (it.hasNext()) {
18296                                                final double ix = it.aDouble;
18297                                                int ox;
18298                                                ox = (int) toLong(Math.cos(ix));
18299                                                oai32data[it.oIndex] = ox;
18300                                        }
18301                                } else {
18302                                        while (it.hasNext()) {
18303                                                final long ix = it.aLong;
18304                                                int ox;
18305                                                ox = (int) toLong(Math.cos(ix));
18306                                                oai32data[it.oIndex] = ox;
18307                                        }
18308                                }
18309                        } else if (as == 1) {
18310                                if (it.isOutputDouble()) {
18311                                        while (it.hasNext()) {
18312                                                final double ix = it.aDouble;
18313                                                int ox;
18314                                                ox = (int) toLong(Math.cos(ix));
18315                                                for (int j = 0; j < is; j++) {
18316                                                        oai32data[it.oIndex + j] = ox;
18317                                                }
18318                                        }
18319                                } else {
18320                                        while (it.hasNext()) {
18321                                                final long ix = it.aLong;
18322                                                int ox;
18323                                                ox = (int) toLong(Math.cos(ix));
18324                                                for (int j = 0; j < is; j++) {
18325                                                        oai32data[it.oIndex + j] = ox;
18326                                                }
18327                                        }
18328                                }
18329                        } else {
18330                                if (it.isOutputDouble()) {
18331                                        while (it.hasNext()) {
18332                                                for (int j = 0; j < is; j++) {
18333                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18334                                                        int ox;
18335                                                        ox = (int) toLong(Math.cos(ix));
18336                                                        oai32data[it.oIndex + j] = ox;
18337                                                }
18338                                        }
18339                                } else {
18340                                        while (it.hasNext()) {
18341                                                for (int j = 0; j < is; j++) {
18342                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18343                                                        int ox;
18344                                                        ox = (int) toLong(Math.cos(ix));
18345                                                        oai32data[it.oIndex + j] = ox;
18346                                                }
18347                                        }
18348                                }
18349                        }
18350                        break;
18351                case Dataset.FLOAT32:
18352                        final float[] of32data = ((FloatDataset) result).getData();
18353                        if (it.isOutputDouble()) {
18354                                while (it.hasNext()) {
18355                                        final double ix = it.aDouble;
18356                                        float ox;
18357                                        ox = (float) (Math.cos(ix));
18358                                        of32data[it.oIndex] = ox;
18359                                }
18360                        } else {
18361                                while (it.hasNext()) {
18362                                        final long ix = it.aLong;
18363                                        float ox;
18364                                        ox = (float) (Math.cos(ix));
18365                                        of32data[it.oIndex] = ox;
18366                                }
18367                        }
18368                        break;
18369                case Dataset.FLOAT64:
18370                        final double[] of64data = ((DoubleDataset) result).getData();
18371                        if (it.isOutputDouble()) {
18372                                while (it.hasNext()) {
18373                                        final double ix = it.aDouble;
18374                                        double ox;
18375                                        ox = (Math.cos(ix));
18376                                        of64data[it.oIndex] = ox;
18377                                }
18378                        } else {
18379                                while (it.hasNext()) {
18380                                        final long ix = it.aLong;
18381                                        double ox;
18382                                        ox = (Math.cos(ix));
18383                                        of64data[it.oIndex] = ox;
18384                                }
18385                        }
18386                        break;
18387                case Dataset.ARRAYFLOAT32:
18388                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
18389                        if (is == 1) {
18390                                if (it.isOutputDouble()) {
18391                                        while (it.hasNext()) {
18392                                                final double ix = it.aDouble;
18393                                                float ox;
18394                                                ox = (float) (Math.cos(ix));
18395                                                oaf32data[it.oIndex] = ox;
18396                                        }
18397                                } else {
18398                                        while (it.hasNext()) {
18399                                                final long ix = it.aLong;
18400                                                float ox;
18401                                                ox = (float) (Math.cos(ix));
18402                                                oaf32data[it.oIndex] = ox;
18403                                        }
18404                                }
18405                        } else if (as == 1) {
18406                                if (it.isOutputDouble()) {
18407                                        while (it.hasNext()) {
18408                                                final double ix = it.aDouble;
18409                                                float ox;
18410                                                ox = (float) (Math.cos(ix));
18411                                                for (int j = 0; j < is; j++) {
18412                                                        oaf32data[it.oIndex + j] = ox;
18413                                                }
18414                                        }
18415                                } else {
18416                                        while (it.hasNext()) {
18417                                                final long ix = it.aLong;
18418                                                float ox;
18419                                                ox = (float) (Math.cos(ix));
18420                                                for (int j = 0; j < is; j++) {
18421                                                        oaf32data[it.oIndex + j] = ox;
18422                                                }
18423                                        }
18424                                }
18425                        } else {
18426                                if (it.isOutputDouble()) {
18427                                        while (it.hasNext()) {
18428                                                for (int j = 0; j < is; j++) {
18429                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18430                                                        float ox;
18431                                                        ox = (float) (Math.cos(ix));
18432                                                        oaf32data[it.oIndex + j] = ox;
18433                                                }
18434                                        }
18435                                } else {
18436                                        while (it.hasNext()) {
18437                                                for (int j = 0; j < is; j++) {
18438                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18439                                                        float ox;
18440                                                        ox = (float) (Math.cos(ix));
18441                                                        oaf32data[it.oIndex + j] = ox;
18442                                                }
18443                                        }
18444                                }
18445                        }
18446                        break;
18447                case Dataset.ARRAYFLOAT64:
18448                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
18449                        if (is == 1) {
18450                                if (it.isOutputDouble()) {
18451                                        while (it.hasNext()) {
18452                                                final double ix = it.aDouble;
18453                                                double ox;
18454                                                ox = (Math.cos(ix));
18455                                                oaf64data[it.oIndex] = ox;
18456                                        }
18457                                } else {
18458                                        while (it.hasNext()) {
18459                                                final long ix = it.aLong;
18460                                                double ox;
18461                                                ox = (Math.cos(ix));
18462                                                oaf64data[it.oIndex] = ox;
18463                                        }
18464                                }
18465                        } else if (as == 1) {
18466                                if (it.isOutputDouble()) {
18467                                        while (it.hasNext()) {
18468                                                final double ix = it.aDouble;
18469                                                double ox;
18470                                                ox = (Math.cos(ix));
18471                                                for (int j = 0; j < is; j++) {
18472                                                        oaf64data[it.oIndex + j] = ox;
18473                                                }
18474                                        }
18475                                } else {
18476                                        while (it.hasNext()) {
18477                                                final long ix = it.aLong;
18478                                                double ox;
18479                                                ox = (Math.cos(ix));
18480                                                for (int j = 0; j < is; j++) {
18481                                                        oaf64data[it.oIndex + j] = ox;
18482                                                }
18483                                        }
18484                                }
18485                        } else {
18486                                if (it.isOutputDouble()) {
18487                                        while (it.hasNext()) {
18488                                                for (int j = 0; j < is; j++) {
18489                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18490                                                        double ox;
18491                                                        ox = (Math.cos(ix));
18492                                                        oaf64data[it.oIndex + j] = ox;
18493                                                }
18494                                        }
18495                                } else {
18496                                        while (it.hasNext()) {
18497                                                for (int j = 0; j < is; j++) {
18498                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18499                                                        double ox;
18500                                                        ox = (Math.cos(ix));
18501                                                        oaf64data[it.oIndex + j] = ox;
18502                                                }
18503                                        }
18504                                }
18505                        }
18506                        break;
18507                case Dataset.COMPLEX64:
18508                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
18509                        if (!da.isComplex()) {
18510                                if (it.isOutputDouble()) {
18511                                        final double iy = 0;
18512                                        while (it.hasNext()) {
18513                                                final double ix = it.aDouble;
18514                                                float ox;
18515                                                float oy;
18516                                                ox = (float) (Math.cos(ix)*Math.cosh(iy));
18517                                                oy = (float) (-Math.sin(ix)*Math.sinh(iy));
18518                                                oc64data[it.oIndex] = ox;
18519                                                oc64data[it.oIndex + 1] = oy;
18520                                        }
18521                                } else {
18522                                        final long iy = 0;
18523                                        while (it.hasNext()) {
18524                                                final long ix = it.aLong;
18525                                                float ox;
18526                                                float oy;
18527                                                ox = (float) toLong(Math.cos(ix)*Math.cosh(iy));
18528                                                oy = (float) toLong(-Math.sin(ix)*Math.sinh(iy));
18529                                                oc64data[it.oIndex] = ox;
18530                                                oc64data[it.oIndex + 1] = oy;
18531                                        }
18532                                }
18533                        } else {
18534                                while (it.hasNext()) {
18535                                        final double ix = it.aDouble;
18536                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
18537                                        float ox;
18538                                        float oy;
18539                                        ox = (float) (Math.cos(ix)*Math.cosh(iy));
18540                                        oy = (float) (-Math.sin(ix)*Math.sinh(iy));
18541                                        oc64data[it.oIndex] = ox;
18542                                        oc64data[it.oIndex + 1] = oy;
18543                                }
18544                        }
18545                        break;
18546                case Dataset.COMPLEX128:
18547                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
18548                        if (!da.isComplex()) {
18549                                if (it.isOutputDouble()) {
18550                                        final double iy = 0;
18551                                        while (it.hasNext()) {
18552                                                final double ix = it.aDouble;
18553                                                double ox;
18554                                                double oy;
18555                                                ox = (Math.cos(ix)*Math.cosh(iy));
18556                                                oy = (-Math.sin(ix)*Math.sinh(iy));
18557                                                oc128data[it.oIndex] = ox;
18558                                                oc128data[it.oIndex + 1] = oy;
18559                                        }
18560                                } else {
18561                                        final long iy = 0;
18562                                        while (it.hasNext()) {
18563                                                final long ix = it.aLong;
18564                                                double ox;
18565                                                double oy;
18566                                                ox = (double) (Math.cos(ix)*Math.cosh(iy));
18567                                                oy = (double) (-Math.sin(ix)*Math.sinh(iy));
18568                                                oc128data[it.oIndex] = ox;
18569                                                oc128data[it.oIndex + 1] = oy;
18570                                        }
18571                                }
18572                        } else {
18573                                while (it.hasNext()) {
18574                                        final double ix = it.aDouble;
18575                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
18576                                        double ox;
18577                                        double oy;
18578                                        ox = (Math.cos(ix)*Math.cosh(iy));
18579                                        oy = (-Math.sin(ix)*Math.sinh(iy));
18580                                        oc128data[it.oIndex] = ox;
18581                                        oc128data[it.oIndex + 1] = oy;
18582                                }
18583                        }
18584                        break;
18585                default:
18586                        throw new IllegalArgumentException("cos supports integer, compound integer, real, compound real, complex datasets only");
18587                }
18588
18589                addFunctionName(result, "cos");
18590                return result;
18591        }
18592
18593        /**
18594         * tan - evaluate the tangent function on each element of the dataset
18595         * @param a single operand
18596         * @return dataset
18597         */
18598        public static Dataset tan(final Object a) {
18599                return tan(a, null);
18600        }
18601
18602        /**
18603         * tan - evaluate the tangent function on each element of the dataset
18604         * @param a single operand
18605         * @param o output can be null - in which case, a new dataset is created
18606         * @return dataset
18607         */
18608        public static Dataset tan(final Object a, final Dataset o) {
18609                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
18610                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
18611                final Dataset result = it.getOutput();
18612                if (!result.isComplex()) {
18613                        if (da.isComplex()) {
18614                                da = da.getRealView();
18615                                it = new SingleInputBroadcastIterator(da, result, true);
18616                        }
18617                }
18618                final int is = result.getElementsPerItem();
18619                final int as = da.getElementsPerItem();
18620                final int dt = result.getDType();
18621
18622                switch(dt) {
18623                case Dataset.INT8:
18624                        final byte[] oi8data = ((ByteDataset) result).getData();
18625                        if (it.isOutputDouble()) {
18626                                while (it.hasNext()) {
18627                                        final double ix = it.aDouble;
18628                                        byte ox;
18629                                        ox = (byte) toLong(Math.tan(ix));
18630                                        oi8data[it.oIndex] = ox;
18631                                }
18632                        } else {
18633                                while (it.hasNext()) {
18634                                        final long ix = it.aLong;
18635                                        byte ox;
18636                                        ox = (byte) toLong(Math.tan(ix));
18637                                        oi8data[it.oIndex] = ox;
18638                                }
18639                        }
18640                        break;
18641                case Dataset.INT16:
18642                        final short[] oi16data = ((ShortDataset) result).getData();
18643                        if (it.isOutputDouble()) {
18644                                while (it.hasNext()) {
18645                                        final double ix = it.aDouble;
18646                                        short ox;
18647                                        ox = (short) toLong(Math.tan(ix));
18648                                        oi16data[it.oIndex] = ox;
18649                                }
18650                        } else {
18651                                while (it.hasNext()) {
18652                                        final long ix = it.aLong;
18653                                        short ox;
18654                                        ox = (short) toLong(Math.tan(ix));
18655                                        oi16data[it.oIndex] = ox;
18656                                }
18657                        }
18658                        break;
18659                case Dataset.INT64:
18660                        final long[] oi64data = ((LongDataset) result).getData();
18661                        if (it.isOutputDouble()) {
18662                                while (it.hasNext()) {
18663                                        final double ix = it.aDouble;
18664                                        long ox;
18665                                        ox = toLong(Math.tan(ix));
18666                                        oi64data[it.oIndex] = ox;
18667                                }
18668                        } else {
18669                                while (it.hasNext()) {
18670                                        final long ix = it.aLong;
18671                                        long ox;
18672                                        ox = toLong(Math.tan(ix));
18673                                        oi64data[it.oIndex] = ox;
18674                                }
18675                        }
18676                        break;
18677                case Dataset.INT32:
18678                        final int[] oi32data = ((IntegerDataset) result).getData();
18679                        if (it.isOutputDouble()) {
18680                                while (it.hasNext()) {
18681                                        final double ix = it.aDouble;
18682                                        int ox;
18683                                        ox = (int) toLong(Math.tan(ix));
18684                                        oi32data[it.oIndex] = ox;
18685                                }
18686                        } else {
18687                                while (it.hasNext()) {
18688                                        final long ix = it.aLong;
18689                                        int ox;
18690                                        ox = (int) toLong(Math.tan(ix));
18691                                        oi32data[it.oIndex] = ox;
18692                                }
18693                        }
18694                        break;
18695                case Dataset.ARRAYINT8:
18696                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
18697                        if (is == 1) {
18698                                if (it.isOutputDouble()) {
18699                                        while (it.hasNext()) {
18700                                                final double ix = it.aDouble;
18701                                                byte ox;
18702                                                ox = (byte) toLong(Math.tan(ix));
18703                                                oai8data[it.oIndex] = ox;
18704                                        }
18705                                } else {
18706                                        while (it.hasNext()) {
18707                                                final long ix = it.aLong;
18708                                                byte ox;
18709                                                ox = (byte) toLong(Math.tan(ix));
18710                                                oai8data[it.oIndex] = ox;
18711                                        }
18712                                }
18713                        } else if (as == 1) {
18714                                if (it.isOutputDouble()) {
18715                                        while (it.hasNext()) {
18716                                                final double ix = it.aDouble;
18717                                                byte ox;
18718                                                ox = (byte) toLong(Math.tan(ix));
18719                                                for (int j = 0; j < is; j++) {
18720                                                        oai8data[it.oIndex + j] = ox;
18721                                                }
18722                                        }
18723                                } else {
18724                                        while (it.hasNext()) {
18725                                                final long ix = it.aLong;
18726                                                byte ox;
18727                                                ox = (byte) toLong(Math.tan(ix));
18728                                                for (int j = 0; j < is; j++) {
18729                                                        oai8data[it.oIndex + j] = ox;
18730                                                }
18731                                        }
18732                                }
18733                        } else {
18734                                if (it.isOutputDouble()) {
18735                                        while (it.hasNext()) {
18736                                                for (int j = 0; j < is; j++) {
18737                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18738                                                        byte ox;
18739                                                        ox = (byte) toLong(Math.tan(ix));
18740                                                        oai8data[it.oIndex + j] = ox;
18741                                                }
18742                                        }
18743                                } else {
18744                                        while (it.hasNext()) {
18745                                                for (int j = 0; j < is; j++) {
18746                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18747                                                        byte ox;
18748                                                        ox = (byte) toLong(Math.tan(ix));
18749                                                        oai8data[it.oIndex + j] = ox;
18750                                                }
18751                                        }
18752                                }
18753                        }
18754                        break;
18755                case Dataset.ARRAYINT16:
18756                        final short[] oai16data = ((CompoundShortDataset) result).getData();
18757                        if (is == 1) {
18758                                if (it.isOutputDouble()) {
18759                                        while (it.hasNext()) {
18760                                                final double ix = it.aDouble;
18761                                                short ox;
18762                                                ox = (short) toLong(Math.tan(ix));
18763                                                oai16data[it.oIndex] = ox;
18764                                        }
18765                                } else {
18766                                        while (it.hasNext()) {
18767                                                final long ix = it.aLong;
18768                                                short ox;
18769                                                ox = (short) toLong(Math.tan(ix));
18770                                                oai16data[it.oIndex] = ox;
18771                                        }
18772                                }
18773                        } else if (as == 1) {
18774                                if (it.isOutputDouble()) {
18775                                        while (it.hasNext()) {
18776                                                final double ix = it.aDouble;
18777                                                short ox;
18778                                                ox = (short) toLong(Math.tan(ix));
18779                                                for (int j = 0; j < is; j++) {
18780                                                        oai16data[it.oIndex + j] = ox;
18781                                                }
18782                                        }
18783                                } else {
18784                                        while (it.hasNext()) {
18785                                                final long ix = it.aLong;
18786                                                short ox;
18787                                                ox = (short) toLong(Math.tan(ix));
18788                                                for (int j = 0; j < is; j++) {
18789                                                        oai16data[it.oIndex + j] = ox;
18790                                                }
18791                                        }
18792                                }
18793                        } else {
18794                                if (it.isOutputDouble()) {
18795                                        while (it.hasNext()) {
18796                                                for (int j = 0; j < is; j++) {
18797                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18798                                                        short ox;
18799                                                        ox = (short) toLong(Math.tan(ix));
18800                                                        oai16data[it.oIndex + j] = ox;
18801                                                }
18802                                        }
18803                                } else {
18804                                        while (it.hasNext()) {
18805                                                for (int j = 0; j < is; j++) {
18806                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18807                                                        short ox;
18808                                                        ox = (short) toLong(Math.tan(ix));
18809                                                        oai16data[it.oIndex + j] = ox;
18810                                                }
18811                                        }
18812                                }
18813                        }
18814                        break;
18815                case Dataset.ARRAYINT64:
18816                        final long[] oai64data = ((CompoundLongDataset) result).getData();
18817                        if (is == 1) {
18818                                if (it.isOutputDouble()) {
18819                                        while (it.hasNext()) {
18820                                                final double ix = it.aDouble;
18821                                                long ox;
18822                                                ox = toLong(Math.tan(ix));
18823                                                oai64data[it.oIndex] = ox;
18824                                        }
18825                                } else {
18826                                        while (it.hasNext()) {
18827                                                final long ix = it.aLong;
18828                                                long ox;
18829                                                ox = toLong(Math.tan(ix));
18830                                                oai64data[it.oIndex] = ox;
18831                                        }
18832                                }
18833                        } else if (as == 1) {
18834                                if (it.isOutputDouble()) {
18835                                        while (it.hasNext()) {
18836                                                final double ix = it.aDouble;
18837                                                long ox;
18838                                                ox = toLong(Math.tan(ix));
18839                                                for (int j = 0; j < is; j++) {
18840                                                        oai64data[it.oIndex + j] = ox;
18841                                                }
18842                                        }
18843                                } else {
18844                                        while (it.hasNext()) {
18845                                                final long ix = it.aLong;
18846                                                long ox;
18847                                                ox = toLong(Math.tan(ix));
18848                                                for (int j = 0; j < is; j++) {
18849                                                        oai64data[it.oIndex + j] = ox;
18850                                                }
18851                                        }
18852                                }
18853                        } else {
18854                                if (it.isOutputDouble()) {
18855                                        while (it.hasNext()) {
18856                                                for (int j = 0; j < is; j++) {
18857                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18858                                                        long ox;
18859                                                        ox = toLong(Math.tan(ix));
18860                                                        oai64data[it.oIndex + j] = ox;
18861                                                }
18862                                        }
18863                                } else {
18864                                        while (it.hasNext()) {
18865                                                for (int j = 0; j < is; j++) {
18866                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18867                                                        long ox;
18868                                                        ox = toLong(Math.tan(ix));
18869                                                        oai64data[it.oIndex + j] = ox;
18870                                                }
18871                                        }
18872                                }
18873                        }
18874                        break;
18875                case Dataset.ARRAYINT32:
18876                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
18877                        if (is == 1) {
18878                                if (it.isOutputDouble()) {
18879                                        while (it.hasNext()) {
18880                                                final double ix = it.aDouble;
18881                                                int ox;
18882                                                ox = (int) toLong(Math.tan(ix));
18883                                                oai32data[it.oIndex] = ox;
18884                                        }
18885                                } else {
18886                                        while (it.hasNext()) {
18887                                                final long ix = it.aLong;
18888                                                int ox;
18889                                                ox = (int) toLong(Math.tan(ix));
18890                                                oai32data[it.oIndex] = ox;
18891                                        }
18892                                }
18893                        } else if (as == 1) {
18894                                if (it.isOutputDouble()) {
18895                                        while (it.hasNext()) {
18896                                                final double ix = it.aDouble;
18897                                                int ox;
18898                                                ox = (int) toLong(Math.tan(ix));
18899                                                for (int j = 0; j < is; j++) {
18900                                                        oai32data[it.oIndex + j] = ox;
18901                                                }
18902                                        }
18903                                } else {
18904                                        while (it.hasNext()) {
18905                                                final long ix = it.aLong;
18906                                                int ox;
18907                                                ox = (int) toLong(Math.tan(ix));
18908                                                for (int j = 0; j < is; j++) {
18909                                                        oai32data[it.oIndex + j] = ox;
18910                                                }
18911                                        }
18912                                }
18913                        } else {
18914                                if (it.isOutputDouble()) {
18915                                        while (it.hasNext()) {
18916                                                for (int j = 0; j < is; j++) {
18917                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
18918                                                        int ox;
18919                                                        ox = (int) toLong(Math.tan(ix));
18920                                                        oai32data[it.oIndex + j] = ox;
18921                                                }
18922                                        }
18923                                } else {
18924                                        while (it.hasNext()) {
18925                                                for (int j = 0; j < is; j++) {
18926                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
18927                                                        int ox;
18928                                                        ox = (int) toLong(Math.tan(ix));
18929                                                        oai32data[it.oIndex + j] = ox;
18930                                                }
18931                                        }
18932                                }
18933                        }
18934                        break;
18935                case Dataset.FLOAT32:
18936                        final float[] of32data = ((FloatDataset) result).getData();
18937                        if (it.isOutputDouble()) {
18938                                while (it.hasNext()) {
18939                                        final double ix = it.aDouble;
18940                                        float ox;
18941                                        ox = (float) (Math.tan(ix));
18942                                        of32data[it.oIndex] = ox;
18943                                }
18944                        } else {
18945                                while (it.hasNext()) {
18946                                        final long ix = it.aLong;
18947                                        float ox;
18948                                        ox = (float) (Math.tan(ix));
18949                                        of32data[it.oIndex] = ox;
18950                                }
18951                        }
18952                        break;
18953                case Dataset.FLOAT64:
18954                        final double[] of64data = ((DoubleDataset) result).getData();
18955                        if (it.isOutputDouble()) {
18956                                while (it.hasNext()) {
18957                                        final double ix = it.aDouble;
18958                                        double ox;
18959                                        ox = (Math.tan(ix));
18960                                        of64data[it.oIndex] = ox;
18961                                }
18962                        } else {
18963                                while (it.hasNext()) {
18964                                        final long ix = it.aLong;
18965                                        double ox;
18966                                        ox = (Math.tan(ix));
18967                                        of64data[it.oIndex] = ox;
18968                                }
18969                        }
18970                        break;
18971                case Dataset.ARRAYFLOAT32:
18972                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
18973                        if (is == 1) {
18974                                if (it.isOutputDouble()) {
18975                                        while (it.hasNext()) {
18976                                                final double ix = it.aDouble;
18977                                                float ox;
18978                                                ox = (float) (Math.tan(ix));
18979                                                oaf32data[it.oIndex] = ox;
18980                                        }
18981                                } else {
18982                                        while (it.hasNext()) {
18983                                                final long ix = it.aLong;
18984                                                float ox;
18985                                                ox = (float) (Math.tan(ix));
18986                                                oaf32data[it.oIndex] = ox;
18987                                        }
18988                                }
18989                        } else if (as == 1) {
18990                                if (it.isOutputDouble()) {
18991                                        while (it.hasNext()) {
18992                                                final double ix = it.aDouble;
18993                                                float ox;
18994                                                ox = (float) (Math.tan(ix));
18995                                                for (int j = 0; j < is; j++) {
18996                                                        oaf32data[it.oIndex + j] = ox;
18997                                                }
18998                                        }
18999                                } else {
19000                                        while (it.hasNext()) {
19001                                                final long ix = it.aLong;
19002                                                float ox;
19003                                                ox = (float) (Math.tan(ix));
19004                                                for (int j = 0; j < is; j++) {
19005                                                        oaf32data[it.oIndex + j] = ox;
19006                                                }
19007                                        }
19008                                }
19009                        } else {
19010                                if (it.isOutputDouble()) {
19011                                        while (it.hasNext()) {
19012                                                for (int j = 0; j < is; j++) {
19013                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19014                                                        float ox;
19015                                                        ox = (float) (Math.tan(ix));
19016                                                        oaf32data[it.oIndex + j] = ox;
19017                                                }
19018                                        }
19019                                } else {
19020                                        while (it.hasNext()) {
19021                                                for (int j = 0; j < is; j++) {
19022                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19023                                                        float ox;
19024                                                        ox = (float) (Math.tan(ix));
19025                                                        oaf32data[it.oIndex + j] = ox;
19026                                                }
19027                                        }
19028                                }
19029                        }
19030                        break;
19031                case Dataset.ARRAYFLOAT64:
19032                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
19033                        if (is == 1) {
19034                                if (it.isOutputDouble()) {
19035                                        while (it.hasNext()) {
19036                                                final double ix = it.aDouble;
19037                                                double ox;
19038                                                ox = (Math.tan(ix));
19039                                                oaf64data[it.oIndex] = ox;
19040                                        }
19041                                } else {
19042                                        while (it.hasNext()) {
19043                                                final long ix = it.aLong;
19044                                                double ox;
19045                                                ox = (Math.tan(ix));
19046                                                oaf64data[it.oIndex] = ox;
19047                                        }
19048                                }
19049                        } else if (as == 1) {
19050                                if (it.isOutputDouble()) {
19051                                        while (it.hasNext()) {
19052                                                final double ix = it.aDouble;
19053                                                double ox;
19054                                                ox = (Math.tan(ix));
19055                                                for (int j = 0; j < is; j++) {
19056                                                        oaf64data[it.oIndex + j] = ox;
19057                                                }
19058                                        }
19059                                } else {
19060                                        while (it.hasNext()) {
19061                                                final long ix = it.aLong;
19062                                                double ox;
19063                                                ox = (Math.tan(ix));
19064                                                for (int j = 0; j < is; j++) {
19065                                                        oaf64data[it.oIndex + j] = ox;
19066                                                }
19067                                        }
19068                                }
19069                        } else {
19070                                if (it.isOutputDouble()) {
19071                                        while (it.hasNext()) {
19072                                                for (int j = 0; j < is; j++) {
19073                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19074                                                        double ox;
19075                                                        ox = (Math.tan(ix));
19076                                                        oaf64data[it.oIndex + j] = ox;
19077                                                }
19078                                        }
19079                                } else {
19080                                        while (it.hasNext()) {
19081                                                for (int j = 0; j < is; j++) {
19082                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19083                                                        double ox;
19084                                                        ox = (Math.tan(ix));
19085                                                        oaf64data[it.oIndex + j] = ox;
19086                                                }
19087                                        }
19088                                }
19089                        }
19090                        break;
19091                case Dataset.COMPLEX64:
19092                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
19093                        if (!da.isComplex()) {
19094                                if (it.isOutputDouble()) {
19095                                        final double iy = 0;
19096                                        while (it.hasNext()) {
19097                                                final double ix = it.aDouble;
19098                                                float x;
19099                                                float y;
19100                                                float tf;
19101                                                float ox;
19102                                                float oy;
19103                                                x = (float) (2.*ix);
19104                                                y = (float) (2.*iy);
19105                                                tf = (float) (1./(Math.cos(x)+Math.cosh(y)));
19106                                                ox = (float) (tf*Math.sin(x));
19107                                                oy = (float) (tf*Math.sinh(y));
19108                                                oc64data[it.oIndex] = ox;
19109                                                oc64data[it.oIndex + 1] = oy;
19110                                        }
19111                                } else {
19112                                        final long iy = 0;
19113                                        while (it.hasNext()) {
19114                                                final long ix = it.aLong;
19115                                                float x;
19116                                                float y;
19117                                                float tf;
19118                                                float ox;
19119                                                float oy;
19120                                                x = (float) toLong(2.*ix);
19121                                                y = (float) toLong(2.*iy);
19122                                                tf = (float) toLong(1./(Math.cos(x)+Math.cosh(y)));
19123                                                ox = (float) toLong(tf*Math.sin(x));
19124                                                oy = (float) toLong(tf*Math.sinh(y));
19125                                                oc64data[it.oIndex] = ox;
19126                                                oc64data[it.oIndex + 1] = oy;
19127                                        }
19128                                }
19129                        } else {
19130                                while (it.hasNext()) {
19131                                        final double ix = it.aDouble;
19132                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
19133                                        float x;
19134                                        float y;
19135                                        float tf;
19136                                        float ox;
19137                                        float oy;
19138                                        x = (float) (2.*ix);
19139                                        y = (float) (2.*iy);
19140                                        tf = (float) (1./(Math.cos(x)+Math.cosh(y)));
19141                                        ox = (float) (tf*Math.sin(x));
19142                                        oy = (float) (tf*Math.sinh(y));
19143                                        oc64data[it.oIndex] = ox;
19144                                        oc64data[it.oIndex + 1] = oy;
19145                                }
19146                        }
19147                        break;
19148                case Dataset.COMPLEX128:
19149                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
19150                        if (!da.isComplex()) {
19151                                if (it.isOutputDouble()) {
19152                                        final double iy = 0;
19153                                        while (it.hasNext()) {
19154                                                final double ix = it.aDouble;
19155                                                double x;
19156                                                double y;
19157                                                double tf;
19158                                                double ox;
19159                                                double oy;
19160                                                x = (2.*ix);
19161                                                y = (2.*iy);
19162                                                tf = (1./(Math.cos(x)+Math.cosh(y)));
19163                                                ox = (tf*Math.sin(x));
19164                                                oy = (tf*Math.sinh(y));
19165                                                oc128data[it.oIndex] = ox;
19166                                                oc128data[it.oIndex + 1] = oy;
19167                                        }
19168                                } else {
19169                                        final long iy = 0;
19170                                        while (it.hasNext()) {
19171                                                final long ix = it.aLong;
19172                                                double x;
19173                                                double y;
19174                                                double tf;
19175                                                double ox;
19176                                                double oy;
19177                                                x = (2.*ix);
19178                                                y = (2.*iy);
19179                                                tf = (double) (1./(Math.cos(x)+Math.cosh(y)));
19180                                                ox = (double) (tf*Math.sin(x));
19181                                                oy = (double) (tf*Math.sinh(y));
19182                                                oc128data[it.oIndex] = ox;
19183                                                oc128data[it.oIndex + 1] = oy;
19184                                        }
19185                                }
19186                        } else {
19187                                while (it.hasNext()) {
19188                                        final double ix = it.aDouble;
19189                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
19190                                        double x;
19191                                        double y;
19192                                        double tf;
19193                                        double ox;
19194                                        double oy;
19195                                        x = (2.*ix);
19196                                        y = (2.*iy);
19197                                        tf = (1./(Math.cos(x)+Math.cosh(y)));
19198                                        ox = (tf*Math.sin(x));
19199                                        oy = (tf*Math.sinh(y));
19200                                        oc128data[it.oIndex] = ox;
19201                                        oc128data[it.oIndex + 1] = oy;
19202                                }
19203                        }
19204                        break;
19205                default:
19206                        throw new IllegalArgumentException("tan supports integer, compound integer, real, compound real, complex datasets only");
19207                }
19208
19209                addFunctionName(result, "tan");
19210                return result;
19211        }
19212
19213        /**
19214         * arcsin - evaluate the inverse sine function on each element of the dataset
19215         * @param a single operand
19216         * @return dataset
19217         */
19218        public static Dataset arcsin(final Object a) {
19219                return arcsin(a, null);
19220        }
19221
19222        /**
19223         * arcsin - evaluate the inverse sine function on each element of the dataset
19224         * @param a single operand
19225         * @param o output can be null - in which case, a new dataset is created
19226         * @return dataset
19227         */
19228        public static Dataset arcsin(final Object a, final Dataset o) {
19229                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
19230                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
19231                final Dataset result = it.getOutput();
19232                if (!result.isComplex()) {
19233                        if (da.isComplex()) {
19234                                da = da.getRealView();
19235                                it = new SingleInputBroadcastIterator(da, result, true);
19236                        }
19237                }
19238                final int is = result.getElementsPerItem();
19239                final int as = da.getElementsPerItem();
19240                final int dt = result.getDType();
19241
19242                switch(dt) {
19243                case Dataset.INT8:
19244                        final byte[] oi8data = ((ByteDataset) result).getData();
19245                        if (it.isOutputDouble()) {
19246                                while (it.hasNext()) {
19247                                        final double ix = it.aDouble;
19248                                        byte ox;
19249                                        ox = (byte) toLong(Math.asin(ix));
19250                                        oi8data[it.oIndex] = ox;
19251                                }
19252                        } else {
19253                                while (it.hasNext()) {
19254                                        final long ix = it.aLong;
19255                                        byte ox;
19256                                        ox = (byte) toLong(Math.asin(ix));
19257                                        oi8data[it.oIndex] = ox;
19258                                }
19259                        }
19260                        break;
19261                case Dataset.INT16:
19262                        final short[] oi16data = ((ShortDataset) result).getData();
19263                        if (it.isOutputDouble()) {
19264                                while (it.hasNext()) {
19265                                        final double ix = it.aDouble;
19266                                        short ox;
19267                                        ox = (short) toLong(Math.asin(ix));
19268                                        oi16data[it.oIndex] = ox;
19269                                }
19270                        } else {
19271                                while (it.hasNext()) {
19272                                        final long ix = it.aLong;
19273                                        short ox;
19274                                        ox = (short) toLong(Math.asin(ix));
19275                                        oi16data[it.oIndex] = ox;
19276                                }
19277                        }
19278                        break;
19279                case Dataset.INT64:
19280                        final long[] oi64data = ((LongDataset) result).getData();
19281                        if (it.isOutputDouble()) {
19282                                while (it.hasNext()) {
19283                                        final double ix = it.aDouble;
19284                                        long ox;
19285                                        ox = toLong(Math.asin(ix));
19286                                        oi64data[it.oIndex] = ox;
19287                                }
19288                        } else {
19289                                while (it.hasNext()) {
19290                                        final long ix = it.aLong;
19291                                        long ox;
19292                                        ox = toLong(Math.asin(ix));
19293                                        oi64data[it.oIndex] = ox;
19294                                }
19295                        }
19296                        break;
19297                case Dataset.INT32:
19298                        final int[] oi32data = ((IntegerDataset) result).getData();
19299                        if (it.isOutputDouble()) {
19300                                while (it.hasNext()) {
19301                                        final double ix = it.aDouble;
19302                                        int ox;
19303                                        ox = (int) toLong(Math.asin(ix));
19304                                        oi32data[it.oIndex] = ox;
19305                                }
19306                        } else {
19307                                while (it.hasNext()) {
19308                                        final long ix = it.aLong;
19309                                        int ox;
19310                                        ox = (int) toLong(Math.asin(ix));
19311                                        oi32data[it.oIndex] = ox;
19312                                }
19313                        }
19314                        break;
19315                case Dataset.ARRAYINT8:
19316                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
19317                        if (is == 1) {
19318                                if (it.isOutputDouble()) {
19319                                        while (it.hasNext()) {
19320                                                final double ix = it.aDouble;
19321                                                byte ox;
19322                                                ox = (byte) toLong(Math.asin(ix));
19323                                                oai8data[it.oIndex] = ox;
19324                                        }
19325                                } else {
19326                                        while (it.hasNext()) {
19327                                                final long ix = it.aLong;
19328                                                byte ox;
19329                                                ox = (byte) toLong(Math.asin(ix));
19330                                                oai8data[it.oIndex] = ox;
19331                                        }
19332                                }
19333                        } else if (as == 1) {
19334                                if (it.isOutputDouble()) {
19335                                        while (it.hasNext()) {
19336                                                final double ix = it.aDouble;
19337                                                byte ox;
19338                                                ox = (byte) toLong(Math.asin(ix));
19339                                                for (int j = 0; j < is; j++) {
19340                                                        oai8data[it.oIndex + j] = ox;
19341                                                }
19342                                        }
19343                                } else {
19344                                        while (it.hasNext()) {
19345                                                final long ix = it.aLong;
19346                                                byte ox;
19347                                                ox = (byte) toLong(Math.asin(ix));
19348                                                for (int j = 0; j < is; j++) {
19349                                                        oai8data[it.oIndex + j] = ox;
19350                                                }
19351                                        }
19352                                }
19353                        } else {
19354                                if (it.isOutputDouble()) {
19355                                        while (it.hasNext()) {
19356                                                for (int j = 0; j < is; j++) {
19357                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19358                                                        byte ox;
19359                                                        ox = (byte) toLong(Math.asin(ix));
19360                                                        oai8data[it.oIndex + j] = ox;
19361                                                }
19362                                        }
19363                                } else {
19364                                        while (it.hasNext()) {
19365                                                for (int j = 0; j < is; j++) {
19366                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19367                                                        byte ox;
19368                                                        ox = (byte) toLong(Math.asin(ix));
19369                                                        oai8data[it.oIndex + j] = ox;
19370                                                }
19371                                        }
19372                                }
19373                        }
19374                        break;
19375                case Dataset.ARRAYINT16:
19376                        final short[] oai16data = ((CompoundShortDataset) result).getData();
19377                        if (is == 1) {
19378                                if (it.isOutputDouble()) {
19379                                        while (it.hasNext()) {
19380                                                final double ix = it.aDouble;
19381                                                short ox;
19382                                                ox = (short) toLong(Math.asin(ix));
19383                                                oai16data[it.oIndex] = ox;
19384                                        }
19385                                } else {
19386                                        while (it.hasNext()) {
19387                                                final long ix = it.aLong;
19388                                                short ox;
19389                                                ox = (short) toLong(Math.asin(ix));
19390                                                oai16data[it.oIndex] = ox;
19391                                        }
19392                                }
19393                        } else if (as == 1) {
19394                                if (it.isOutputDouble()) {
19395                                        while (it.hasNext()) {
19396                                                final double ix = it.aDouble;
19397                                                short ox;
19398                                                ox = (short) toLong(Math.asin(ix));
19399                                                for (int j = 0; j < is; j++) {
19400                                                        oai16data[it.oIndex + j] = ox;
19401                                                }
19402                                        }
19403                                } else {
19404                                        while (it.hasNext()) {
19405                                                final long ix = it.aLong;
19406                                                short ox;
19407                                                ox = (short) toLong(Math.asin(ix));
19408                                                for (int j = 0; j < is; j++) {
19409                                                        oai16data[it.oIndex + j] = ox;
19410                                                }
19411                                        }
19412                                }
19413                        } else {
19414                                if (it.isOutputDouble()) {
19415                                        while (it.hasNext()) {
19416                                                for (int j = 0; j < is; j++) {
19417                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19418                                                        short ox;
19419                                                        ox = (short) toLong(Math.asin(ix));
19420                                                        oai16data[it.oIndex + j] = ox;
19421                                                }
19422                                        }
19423                                } else {
19424                                        while (it.hasNext()) {
19425                                                for (int j = 0; j < is; j++) {
19426                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19427                                                        short ox;
19428                                                        ox = (short) toLong(Math.asin(ix));
19429                                                        oai16data[it.oIndex + j] = ox;
19430                                                }
19431                                        }
19432                                }
19433                        }
19434                        break;
19435                case Dataset.ARRAYINT64:
19436                        final long[] oai64data = ((CompoundLongDataset) result).getData();
19437                        if (is == 1) {
19438                                if (it.isOutputDouble()) {
19439                                        while (it.hasNext()) {
19440                                                final double ix = it.aDouble;
19441                                                long ox;
19442                                                ox = toLong(Math.asin(ix));
19443                                                oai64data[it.oIndex] = ox;
19444                                        }
19445                                } else {
19446                                        while (it.hasNext()) {
19447                                                final long ix = it.aLong;
19448                                                long ox;
19449                                                ox = toLong(Math.asin(ix));
19450                                                oai64data[it.oIndex] = ox;
19451                                        }
19452                                }
19453                        } else if (as == 1) {
19454                                if (it.isOutputDouble()) {
19455                                        while (it.hasNext()) {
19456                                                final double ix = it.aDouble;
19457                                                long ox;
19458                                                ox = toLong(Math.asin(ix));
19459                                                for (int j = 0; j < is; j++) {
19460                                                        oai64data[it.oIndex + j] = ox;
19461                                                }
19462                                        }
19463                                } else {
19464                                        while (it.hasNext()) {
19465                                                final long ix = it.aLong;
19466                                                long ox;
19467                                                ox = toLong(Math.asin(ix));
19468                                                for (int j = 0; j < is; j++) {
19469                                                        oai64data[it.oIndex + j] = ox;
19470                                                }
19471                                        }
19472                                }
19473                        } else {
19474                                if (it.isOutputDouble()) {
19475                                        while (it.hasNext()) {
19476                                                for (int j = 0; j < is; j++) {
19477                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19478                                                        long ox;
19479                                                        ox = toLong(Math.asin(ix));
19480                                                        oai64data[it.oIndex + j] = ox;
19481                                                }
19482                                        }
19483                                } else {
19484                                        while (it.hasNext()) {
19485                                                for (int j = 0; j < is; j++) {
19486                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19487                                                        long ox;
19488                                                        ox = toLong(Math.asin(ix));
19489                                                        oai64data[it.oIndex + j] = ox;
19490                                                }
19491                                        }
19492                                }
19493                        }
19494                        break;
19495                case Dataset.ARRAYINT32:
19496                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
19497                        if (is == 1) {
19498                                if (it.isOutputDouble()) {
19499                                        while (it.hasNext()) {
19500                                                final double ix = it.aDouble;
19501                                                int ox;
19502                                                ox = (int) toLong(Math.asin(ix));
19503                                                oai32data[it.oIndex] = ox;
19504                                        }
19505                                } else {
19506                                        while (it.hasNext()) {
19507                                                final long ix = it.aLong;
19508                                                int ox;
19509                                                ox = (int) toLong(Math.asin(ix));
19510                                                oai32data[it.oIndex] = ox;
19511                                        }
19512                                }
19513                        } else if (as == 1) {
19514                                if (it.isOutputDouble()) {
19515                                        while (it.hasNext()) {
19516                                                final double ix = it.aDouble;
19517                                                int ox;
19518                                                ox = (int) toLong(Math.asin(ix));
19519                                                for (int j = 0; j < is; j++) {
19520                                                        oai32data[it.oIndex + j] = ox;
19521                                                }
19522                                        }
19523                                } else {
19524                                        while (it.hasNext()) {
19525                                                final long ix = it.aLong;
19526                                                int ox;
19527                                                ox = (int) toLong(Math.asin(ix));
19528                                                for (int j = 0; j < is; j++) {
19529                                                        oai32data[it.oIndex + j] = ox;
19530                                                }
19531                                        }
19532                                }
19533                        } else {
19534                                if (it.isOutputDouble()) {
19535                                        while (it.hasNext()) {
19536                                                for (int j = 0; j < is; j++) {
19537                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19538                                                        int ox;
19539                                                        ox = (int) toLong(Math.asin(ix));
19540                                                        oai32data[it.oIndex + j] = ox;
19541                                                }
19542                                        }
19543                                } else {
19544                                        while (it.hasNext()) {
19545                                                for (int j = 0; j < is; j++) {
19546                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19547                                                        int ox;
19548                                                        ox = (int) toLong(Math.asin(ix));
19549                                                        oai32data[it.oIndex + j] = ox;
19550                                                }
19551                                        }
19552                                }
19553                        }
19554                        break;
19555                case Dataset.FLOAT32:
19556                        final float[] of32data = ((FloatDataset) result).getData();
19557                        if (it.isOutputDouble()) {
19558                                while (it.hasNext()) {
19559                                        final double ix = it.aDouble;
19560                                        float ox;
19561                                        ox = (float) (Math.asin(ix));
19562                                        of32data[it.oIndex] = ox;
19563                                }
19564                        } else {
19565                                while (it.hasNext()) {
19566                                        final long ix = it.aLong;
19567                                        float ox;
19568                                        ox = (float) (Math.asin(ix));
19569                                        of32data[it.oIndex] = ox;
19570                                }
19571                        }
19572                        break;
19573                case Dataset.FLOAT64:
19574                        final double[] of64data = ((DoubleDataset) result).getData();
19575                        if (it.isOutputDouble()) {
19576                                while (it.hasNext()) {
19577                                        final double ix = it.aDouble;
19578                                        double ox;
19579                                        ox = (Math.asin(ix));
19580                                        of64data[it.oIndex] = ox;
19581                                }
19582                        } else {
19583                                while (it.hasNext()) {
19584                                        final long ix = it.aLong;
19585                                        double ox;
19586                                        ox = (Math.asin(ix));
19587                                        of64data[it.oIndex] = ox;
19588                                }
19589                        }
19590                        break;
19591                case Dataset.ARRAYFLOAT32:
19592                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
19593                        if (is == 1) {
19594                                if (it.isOutputDouble()) {
19595                                        while (it.hasNext()) {
19596                                                final double ix = it.aDouble;
19597                                                float ox;
19598                                                ox = (float) (Math.asin(ix));
19599                                                oaf32data[it.oIndex] = ox;
19600                                        }
19601                                } else {
19602                                        while (it.hasNext()) {
19603                                                final long ix = it.aLong;
19604                                                float ox;
19605                                                ox = (float) (Math.asin(ix));
19606                                                oaf32data[it.oIndex] = ox;
19607                                        }
19608                                }
19609                        } else if (as == 1) {
19610                                if (it.isOutputDouble()) {
19611                                        while (it.hasNext()) {
19612                                                final double ix = it.aDouble;
19613                                                float ox;
19614                                                ox = (float) (Math.asin(ix));
19615                                                for (int j = 0; j < is; j++) {
19616                                                        oaf32data[it.oIndex + j] = ox;
19617                                                }
19618                                        }
19619                                } else {
19620                                        while (it.hasNext()) {
19621                                                final long ix = it.aLong;
19622                                                float ox;
19623                                                ox = (float) (Math.asin(ix));
19624                                                for (int j = 0; j < is; j++) {
19625                                                        oaf32data[it.oIndex + j] = ox;
19626                                                }
19627                                        }
19628                                }
19629                        } else {
19630                                if (it.isOutputDouble()) {
19631                                        while (it.hasNext()) {
19632                                                for (int j = 0; j < is; j++) {
19633                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19634                                                        float ox;
19635                                                        ox = (float) (Math.asin(ix));
19636                                                        oaf32data[it.oIndex + j] = ox;
19637                                                }
19638                                        }
19639                                } else {
19640                                        while (it.hasNext()) {
19641                                                for (int j = 0; j < is; j++) {
19642                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19643                                                        float ox;
19644                                                        ox = (float) (Math.asin(ix));
19645                                                        oaf32data[it.oIndex + j] = ox;
19646                                                }
19647                                        }
19648                                }
19649                        }
19650                        break;
19651                case Dataset.ARRAYFLOAT64:
19652                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
19653                        if (is == 1) {
19654                                if (it.isOutputDouble()) {
19655                                        while (it.hasNext()) {
19656                                                final double ix = it.aDouble;
19657                                                double ox;
19658                                                ox = (Math.asin(ix));
19659                                                oaf64data[it.oIndex] = ox;
19660                                        }
19661                                } else {
19662                                        while (it.hasNext()) {
19663                                                final long ix = it.aLong;
19664                                                double ox;
19665                                                ox = (Math.asin(ix));
19666                                                oaf64data[it.oIndex] = ox;
19667                                        }
19668                                }
19669                        } else if (as == 1) {
19670                                if (it.isOutputDouble()) {
19671                                        while (it.hasNext()) {
19672                                                final double ix = it.aDouble;
19673                                                double ox;
19674                                                ox = (Math.asin(ix));
19675                                                for (int j = 0; j < is; j++) {
19676                                                        oaf64data[it.oIndex + j] = ox;
19677                                                }
19678                                        }
19679                                } else {
19680                                        while (it.hasNext()) {
19681                                                final long ix = it.aLong;
19682                                                double ox;
19683                                                ox = (Math.asin(ix));
19684                                                for (int j = 0; j < is; j++) {
19685                                                        oaf64data[it.oIndex + j] = ox;
19686                                                }
19687                                        }
19688                                }
19689                        } else {
19690                                if (it.isOutputDouble()) {
19691                                        while (it.hasNext()) {
19692                                                for (int j = 0; j < is; j++) {
19693                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19694                                                        double ox;
19695                                                        ox = (Math.asin(ix));
19696                                                        oaf64data[it.oIndex + j] = ox;
19697                                                }
19698                                        }
19699                                } else {
19700                                        while (it.hasNext()) {
19701                                                for (int j = 0; j < is; j++) {
19702                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19703                                                        double ox;
19704                                                        ox = (Math.asin(ix));
19705                                                        oaf64data[it.oIndex + j] = ox;
19706                                                }
19707                                        }
19708                                }
19709                        }
19710                        break;
19711                case Dataset.COMPLEX64:
19712                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
19713                        if (!da.isComplex()) {
19714                                if (it.isOutputDouble()) {
19715                                        final double iy = 0;
19716                                        while (it.hasNext()) {
19717                                                final double ix = it.aDouble;
19718                                                Complex tz;
19719                                                float ox;
19720                                                float oy;
19721                                                tz = new Complex(ix, iy).asin();
19722                                                ox = (float) (tz.getReal());
19723                                                oy = (float) (tz.getImaginary());
19724                                                oc64data[it.oIndex] = ox;
19725                                                oc64data[it.oIndex + 1] = oy;
19726                                        }
19727                                } else {
19728                                        final long iy = 0;
19729                                        while (it.hasNext()) {
19730                                                final long ix = it.aLong;
19731                                                Complex tz;
19732                                                float ox;
19733                                                float oy;
19734                                                tz = new Complex(ix, iy).asin();
19735                                                ox = (float) toLong(tz.getReal());
19736                                                oy = (float) toLong(tz.getImaginary());
19737                                                oc64data[it.oIndex] = ox;
19738                                                oc64data[it.oIndex + 1] = oy;
19739                                        }
19740                                }
19741                        } else {
19742                                while (it.hasNext()) {
19743                                        final double ix = it.aDouble;
19744                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
19745                                        Complex tz;
19746                                        float ox;
19747                                        float oy;
19748                                        tz = new Complex(ix, iy).asin();
19749                                        ox = (float) (tz.getReal());
19750                                        oy = (float) (tz.getImaginary());
19751                                        oc64data[it.oIndex] = ox;
19752                                        oc64data[it.oIndex + 1] = oy;
19753                                }
19754                        }
19755                        break;
19756                case Dataset.COMPLEX128:
19757                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
19758                        if (!da.isComplex()) {
19759                                if (it.isOutputDouble()) {
19760                                        final double iy = 0;
19761                                        while (it.hasNext()) {
19762                                                final double ix = it.aDouble;
19763                                                Complex tz;
19764                                                double ox;
19765                                                double oy;
19766                                                tz = new Complex(ix, iy).asin();
19767                                                ox = (tz.getReal());
19768                                                oy = (tz.getImaginary());
19769                                                oc128data[it.oIndex] = ox;
19770                                                oc128data[it.oIndex + 1] = oy;
19771                                        }
19772                                } else {
19773                                        final long iy = 0;
19774                                        while (it.hasNext()) {
19775                                                final long ix = it.aLong;
19776                                                Complex tz;
19777                                                double ox;
19778                                                double oy;
19779                                                tz = new Complex(ix, iy).asin();
19780                                                ox = (tz.getReal());
19781                                                oy = (tz.getImaginary());
19782                                                oc128data[it.oIndex] = ox;
19783                                                oc128data[it.oIndex + 1] = oy;
19784                                        }
19785                                }
19786                        } else {
19787                                while (it.hasNext()) {
19788                                        final double ix = it.aDouble;
19789                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
19790                                        Complex tz;
19791                                        double ox;
19792                                        double oy;
19793                                        tz = new Complex(ix, iy).asin();
19794                                        ox = (tz.getReal());
19795                                        oy = (tz.getImaginary());
19796                                        oc128data[it.oIndex] = ox;
19797                                        oc128data[it.oIndex + 1] = oy;
19798                                }
19799                        }
19800                        break;
19801                default:
19802                        throw new IllegalArgumentException("arcsin supports integer, compound integer, real, compound real, complex datasets only");
19803                }
19804
19805                addFunctionName(result, "arcsin");
19806                return result;
19807        }
19808
19809        /**
19810         * arccos - evaluate the inverse cosine function on each element of the dataset
19811         * @param a single operand
19812         * @return dataset
19813         */
19814        public static Dataset arccos(final Object a) {
19815                return arccos(a, null);
19816        }
19817
19818        /**
19819         * arccos - evaluate the inverse cosine function on each element of the dataset
19820         * @param a single operand
19821         * @param o output can be null - in which case, a new dataset is created
19822         * @return dataset
19823         */
19824        public static Dataset arccos(final Object a, final Dataset o) {
19825                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
19826                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
19827                final Dataset result = it.getOutput();
19828                if (!result.isComplex()) {
19829                        if (da.isComplex()) {
19830                                da = da.getRealView();
19831                                it = new SingleInputBroadcastIterator(da, result, true);
19832                        }
19833                }
19834                final int is = result.getElementsPerItem();
19835                final int as = da.getElementsPerItem();
19836                final int dt = result.getDType();
19837
19838                switch(dt) {
19839                case Dataset.INT8:
19840                        final byte[] oi8data = ((ByteDataset) result).getData();
19841                        if (it.isOutputDouble()) {
19842                                while (it.hasNext()) {
19843                                        final double ix = it.aDouble;
19844                                        byte ox;
19845                                        ox = (byte) toLong(Math.acos(ix));
19846                                        oi8data[it.oIndex] = ox;
19847                                }
19848                        } else {
19849                                while (it.hasNext()) {
19850                                        final long ix = it.aLong;
19851                                        byte ox;
19852                                        ox = (byte) toLong(Math.acos(ix));
19853                                        oi8data[it.oIndex] = ox;
19854                                }
19855                        }
19856                        break;
19857                case Dataset.INT16:
19858                        final short[] oi16data = ((ShortDataset) result).getData();
19859                        if (it.isOutputDouble()) {
19860                                while (it.hasNext()) {
19861                                        final double ix = it.aDouble;
19862                                        short ox;
19863                                        ox = (short) toLong(Math.acos(ix));
19864                                        oi16data[it.oIndex] = ox;
19865                                }
19866                        } else {
19867                                while (it.hasNext()) {
19868                                        final long ix = it.aLong;
19869                                        short ox;
19870                                        ox = (short) toLong(Math.acos(ix));
19871                                        oi16data[it.oIndex] = ox;
19872                                }
19873                        }
19874                        break;
19875                case Dataset.INT64:
19876                        final long[] oi64data = ((LongDataset) result).getData();
19877                        if (it.isOutputDouble()) {
19878                                while (it.hasNext()) {
19879                                        final double ix = it.aDouble;
19880                                        long ox;
19881                                        ox = toLong(Math.acos(ix));
19882                                        oi64data[it.oIndex] = ox;
19883                                }
19884                        } else {
19885                                while (it.hasNext()) {
19886                                        final long ix = it.aLong;
19887                                        long ox;
19888                                        ox = toLong(Math.acos(ix));
19889                                        oi64data[it.oIndex] = ox;
19890                                }
19891                        }
19892                        break;
19893                case Dataset.INT32:
19894                        final int[] oi32data = ((IntegerDataset) result).getData();
19895                        if (it.isOutputDouble()) {
19896                                while (it.hasNext()) {
19897                                        final double ix = it.aDouble;
19898                                        int ox;
19899                                        ox = (int) toLong(Math.acos(ix));
19900                                        oi32data[it.oIndex] = ox;
19901                                }
19902                        } else {
19903                                while (it.hasNext()) {
19904                                        final long ix = it.aLong;
19905                                        int ox;
19906                                        ox = (int) toLong(Math.acos(ix));
19907                                        oi32data[it.oIndex] = ox;
19908                                }
19909                        }
19910                        break;
19911                case Dataset.ARRAYINT8:
19912                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
19913                        if (is == 1) {
19914                                if (it.isOutputDouble()) {
19915                                        while (it.hasNext()) {
19916                                                final double ix = it.aDouble;
19917                                                byte ox;
19918                                                ox = (byte) toLong(Math.acos(ix));
19919                                                oai8data[it.oIndex] = ox;
19920                                        }
19921                                } else {
19922                                        while (it.hasNext()) {
19923                                                final long ix = it.aLong;
19924                                                byte ox;
19925                                                ox = (byte) toLong(Math.acos(ix));
19926                                                oai8data[it.oIndex] = ox;
19927                                        }
19928                                }
19929                        } else if (as == 1) {
19930                                if (it.isOutputDouble()) {
19931                                        while (it.hasNext()) {
19932                                                final double ix = it.aDouble;
19933                                                byte ox;
19934                                                ox = (byte) toLong(Math.acos(ix));
19935                                                for (int j = 0; j < is; j++) {
19936                                                        oai8data[it.oIndex + j] = ox;
19937                                                }
19938                                        }
19939                                } else {
19940                                        while (it.hasNext()) {
19941                                                final long ix = it.aLong;
19942                                                byte ox;
19943                                                ox = (byte) toLong(Math.acos(ix));
19944                                                for (int j = 0; j < is; j++) {
19945                                                        oai8data[it.oIndex + j] = ox;
19946                                                }
19947                                        }
19948                                }
19949                        } else {
19950                                if (it.isOutputDouble()) {
19951                                        while (it.hasNext()) {
19952                                                for (int j = 0; j < is; j++) {
19953                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
19954                                                        byte ox;
19955                                                        ox = (byte) toLong(Math.acos(ix));
19956                                                        oai8data[it.oIndex + j] = ox;
19957                                                }
19958                                        }
19959                                } else {
19960                                        while (it.hasNext()) {
19961                                                for (int j = 0; j < is; j++) {
19962                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
19963                                                        byte ox;
19964                                                        ox = (byte) toLong(Math.acos(ix));
19965                                                        oai8data[it.oIndex + j] = ox;
19966                                                }
19967                                        }
19968                                }
19969                        }
19970                        break;
19971                case Dataset.ARRAYINT16:
19972                        final short[] oai16data = ((CompoundShortDataset) result).getData();
19973                        if (is == 1) {
19974                                if (it.isOutputDouble()) {
19975                                        while (it.hasNext()) {
19976                                                final double ix = it.aDouble;
19977                                                short ox;
19978                                                ox = (short) toLong(Math.acos(ix));
19979                                                oai16data[it.oIndex] = ox;
19980                                        }
19981                                } else {
19982                                        while (it.hasNext()) {
19983                                                final long ix = it.aLong;
19984                                                short ox;
19985                                                ox = (short) toLong(Math.acos(ix));
19986                                                oai16data[it.oIndex] = ox;
19987                                        }
19988                                }
19989                        } else if (as == 1) {
19990                                if (it.isOutputDouble()) {
19991                                        while (it.hasNext()) {
19992                                                final double ix = it.aDouble;
19993                                                short ox;
19994                                                ox = (short) toLong(Math.acos(ix));
19995                                                for (int j = 0; j < is; j++) {
19996                                                        oai16data[it.oIndex + j] = ox;
19997                                                }
19998                                        }
19999                                } else {
20000                                        while (it.hasNext()) {
20001                                                final long ix = it.aLong;
20002                                                short ox;
20003                                                ox = (short) toLong(Math.acos(ix));
20004                                                for (int j = 0; j < is; j++) {
20005                                                        oai16data[it.oIndex + j] = ox;
20006                                                }
20007                                        }
20008                                }
20009                        } else {
20010                                if (it.isOutputDouble()) {
20011                                        while (it.hasNext()) {
20012                                                for (int j = 0; j < is; j++) {
20013                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20014                                                        short ox;
20015                                                        ox = (short) toLong(Math.acos(ix));
20016                                                        oai16data[it.oIndex + j] = ox;
20017                                                }
20018                                        }
20019                                } else {
20020                                        while (it.hasNext()) {
20021                                                for (int j = 0; j < is; j++) {
20022                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20023                                                        short ox;
20024                                                        ox = (short) toLong(Math.acos(ix));
20025                                                        oai16data[it.oIndex + j] = ox;
20026                                                }
20027                                        }
20028                                }
20029                        }
20030                        break;
20031                case Dataset.ARRAYINT64:
20032                        final long[] oai64data = ((CompoundLongDataset) result).getData();
20033                        if (is == 1) {
20034                                if (it.isOutputDouble()) {
20035                                        while (it.hasNext()) {
20036                                                final double ix = it.aDouble;
20037                                                long ox;
20038                                                ox = toLong(Math.acos(ix));
20039                                                oai64data[it.oIndex] = ox;
20040                                        }
20041                                } else {
20042                                        while (it.hasNext()) {
20043                                                final long ix = it.aLong;
20044                                                long ox;
20045                                                ox = toLong(Math.acos(ix));
20046                                                oai64data[it.oIndex] = ox;
20047                                        }
20048                                }
20049                        } else if (as == 1) {
20050                                if (it.isOutputDouble()) {
20051                                        while (it.hasNext()) {
20052                                                final double ix = it.aDouble;
20053                                                long ox;
20054                                                ox = toLong(Math.acos(ix));
20055                                                for (int j = 0; j < is; j++) {
20056                                                        oai64data[it.oIndex + j] = ox;
20057                                                }
20058                                        }
20059                                } else {
20060                                        while (it.hasNext()) {
20061                                                final long ix = it.aLong;
20062                                                long ox;
20063                                                ox = toLong(Math.acos(ix));
20064                                                for (int j = 0; j < is; j++) {
20065                                                        oai64data[it.oIndex + j] = ox;
20066                                                }
20067                                        }
20068                                }
20069                        } else {
20070                                if (it.isOutputDouble()) {
20071                                        while (it.hasNext()) {
20072                                                for (int j = 0; j < is; j++) {
20073                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20074                                                        long ox;
20075                                                        ox = toLong(Math.acos(ix));
20076                                                        oai64data[it.oIndex + j] = ox;
20077                                                }
20078                                        }
20079                                } else {
20080                                        while (it.hasNext()) {
20081                                                for (int j = 0; j < is; j++) {
20082                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20083                                                        long ox;
20084                                                        ox = toLong(Math.acos(ix));
20085                                                        oai64data[it.oIndex + j] = ox;
20086                                                }
20087                                        }
20088                                }
20089                        }
20090                        break;
20091                case Dataset.ARRAYINT32:
20092                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
20093                        if (is == 1) {
20094                                if (it.isOutputDouble()) {
20095                                        while (it.hasNext()) {
20096                                                final double ix = it.aDouble;
20097                                                int ox;
20098                                                ox = (int) toLong(Math.acos(ix));
20099                                                oai32data[it.oIndex] = ox;
20100                                        }
20101                                } else {
20102                                        while (it.hasNext()) {
20103                                                final long ix = it.aLong;
20104                                                int ox;
20105                                                ox = (int) toLong(Math.acos(ix));
20106                                                oai32data[it.oIndex] = ox;
20107                                        }
20108                                }
20109                        } else if (as == 1) {
20110                                if (it.isOutputDouble()) {
20111                                        while (it.hasNext()) {
20112                                                final double ix = it.aDouble;
20113                                                int ox;
20114                                                ox = (int) toLong(Math.acos(ix));
20115                                                for (int j = 0; j < is; j++) {
20116                                                        oai32data[it.oIndex + j] = ox;
20117                                                }
20118                                        }
20119                                } else {
20120                                        while (it.hasNext()) {
20121                                                final long ix = it.aLong;
20122                                                int ox;
20123                                                ox = (int) toLong(Math.acos(ix));
20124                                                for (int j = 0; j < is; j++) {
20125                                                        oai32data[it.oIndex + j] = ox;
20126                                                }
20127                                        }
20128                                }
20129                        } else {
20130                                if (it.isOutputDouble()) {
20131                                        while (it.hasNext()) {
20132                                                for (int j = 0; j < is; j++) {
20133                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20134                                                        int ox;
20135                                                        ox = (int) toLong(Math.acos(ix));
20136                                                        oai32data[it.oIndex + j] = ox;
20137                                                }
20138                                        }
20139                                } else {
20140                                        while (it.hasNext()) {
20141                                                for (int j = 0; j < is; j++) {
20142                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20143                                                        int ox;
20144                                                        ox = (int) toLong(Math.acos(ix));
20145                                                        oai32data[it.oIndex + j] = ox;
20146                                                }
20147                                        }
20148                                }
20149                        }
20150                        break;
20151                case Dataset.FLOAT32:
20152                        final float[] of32data = ((FloatDataset) result).getData();
20153                        if (it.isOutputDouble()) {
20154                                while (it.hasNext()) {
20155                                        final double ix = it.aDouble;
20156                                        float ox;
20157                                        ox = (float) (Math.acos(ix));
20158                                        of32data[it.oIndex] = ox;
20159                                }
20160                        } else {
20161                                while (it.hasNext()) {
20162                                        final long ix = it.aLong;
20163                                        float ox;
20164                                        ox = (float) (Math.acos(ix));
20165                                        of32data[it.oIndex] = ox;
20166                                }
20167                        }
20168                        break;
20169                case Dataset.FLOAT64:
20170                        final double[] of64data = ((DoubleDataset) result).getData();
20171                        if (it.isOutputDouble()) {
20172                                while (it.hasNext()) {
20173                                        final double ix = it.aDouble;
20174                                        double ox;
20175                                        ox = (Math.acos(ix));
20176                                        of64data[it.oIndex] = ox;
20177                                }
20178                        } else {
20179                                while (it.hasNext()) {
20180                                        final long ix = it.aLong;
20181                                        double ox;
20182                                        ox = (Math.acos(ix));
20183                                        of64data[it.oIndex] = ox;
20184                                }
20185                        }
20186                        break;
20187                case Dataset.ARRAYFLOAT32:
20188                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
20189                        if (is == 1) {
20190                                if (it.isOutputDouble()) {
20191                                        while (it.hasNext()) {
20192                                                final double ix = it.aDouble;
20193                                                float ox;
20194                                                ox = (float) (Math.acos(ix));
20195                                                oaf32data[it.oIndex] = ox;
20196                                        }
20197                                } else {
20198                                        while (it.hasNext()) {
20199                                                final long ix = it.aLong;
20200                                                float ox;
20201                                                ox = (float) (Math.acos(ix));
20202                                                oaf32data[it.oIndex] = ox;
20203                                        }
20204                                }
20205                        } else if (as == 1) {
20206                                if (it.isOutputDouble()) {
20207                                        while (it.hasNext()) {
20208                                                final double ix = it.aDouble;
20209                                                float ox;
20210                                                ox = (float) (Math.acos(ix));
20211                                                for (int j = 0; j < is; j++) {
20212                                                        oaf32data[it.oIndex + j] = ox;
20213                                                }
20214                                        }
20215                                } else {
20216                                        while (it.hasNext()) {
20217                                                final long ix = it.aLong;
20218                                                float ox;
20219                                                ox = (float) (Math.acos(ix));
20220                                                for (int j = 0; j < is; j++) {
20221                                                        oaf32data[it.oIndex + j] = ox;
20222                                                }
20223                                        }
20224                                }
20225                        } else {
20226                                if (it.isOutputDouble()) {
20227                                        while (it.hasNext()) {
20228                                                for (int j = 0; j < is; j++) {
20229                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20230                                                        float ox;
20231                                                        ox = (float) (Math.acos(ix));
20232                                                        oaf32data[it.oIndex + j] = ox;
20233                                                }
20234                                        }
20235                                } else {
20236                                        while (it.hasNext()) {
20237                                                for (int j = 0; j < is; j++) {
20238                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20239                                                        float ox;
20240                                                        ox = (float) (Math.acos(ix));
20241                                                        oaf32data[it.oIndex + j] = ox;
20242                                                }
20243                                        }
20244                                }
20245                        }
20246                        break;
20247                case Dataset.ARRAYFLOAT64:
20248                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
20249                        if (is == 1) {
20250                                if (it.isOutputDouble()) {
20251                                        while (it.hasNext()) {
20252                                                final double ix = it.aDouble;
20253                                                double ox;
20254                                                ox = (Math.acos(ix));
20255                                                oaf64data[it.oIndex] = ox;
20256                                        }
20257                                } else {
20258                                        while (it.hasNext()) {
20259                                                final long ix = it.aLong;
20260                                                double ox;
20261                                                ox = (Math.acos(ix));
20262                                                oaf64data[it.oIndex] = ox;
20263                                        }
20264                                }
20265                        } else if (as == 1) {
20266                                if (it.isOutputDouble()) {
20267                                        while (it.hasNext()) {
20268                                                final double ix = it.aDouble;
20269                                                double ox;
20270                                                ox = (Math.acos(ix));
20271                                                for (int j = 0; j < is; j++) {
20272                                                        oaf64data[it.oIndex + j] = ox;
20273                                                }
20274                                        }
20275                                } else {
20276                                        while (it.hasNext()) {
20277                                                final long ix = it.aLong;
20278                                                double ox;
20279                                                ox = (Math.acos(ix));
20280                                                for (int j = 0; j < is; j++) {
20281                                                        oaf64data[it.oIndex + j] = ox;
20282                                                }
20283                                        }
20284                                }
20285                        } else {
20286                                if (it.isOutputDouble()) {
20287                                        while (it.hasNext()) {
20288                                                for (int j = 0; j < is; j++) {
20289                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20290                                                        double ox;
20291                                                        ox = (Math.acos(ix));
20292                                                        oaf64data[it.oIndex + j] = ox;
20293                                                }
20294                                        }
20295                                } else {
20296                                        while (it.hasNext()) {
20297                                                for (int j = 0; j < is; j++) {
20298                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20299                                                        double ox;
20300                                                        ox = (Math.acos(ix));
20301                                                        oaf64data[it.oIndex + j] = ox;
20302                                                }
20303                                        }
20304                                }
20305                        }
20306                        break;
20307                case Dataset.COMPLEX64:
20308                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
20309                        if (!da.isComplex()) {
20310                                if (it.isOutputDouble()) {
20311                                        final double iy = 0;
20312                                        while (it.hasNext()) {
20313                                                final double ix = it.aDouble;
20314                                                Complex tz;
20315                                                float ox;
20316                                                float oy;
20317                                                tz = new Complex(ix, iy).acos();
20318                                                ox = (float) (tz.getReal());
20319                                                oy = (float) (tz.getImaginary());
20320                                                oc64data[it.oIndex] = ox;
20321                                                oc64data[it.oIndex + 1] = oy;
20322                                        }
20323                                } else {
20324                                        final long iy = 0;
20325                                        while (it.hasNext()) {
20326                                                final long ix = it.aLong;
20327                                                Complex tz;
20328                                                float ox;
20329                                                float oy;
20330                                                tz = new Complex(ix, iy).acos();
20331                                                ox = (float) toLong(tz.getReal());
20332                                                oy = (float) toLong(tz.getImaginary());
20333                                                oc64data[it.oIndex] = ox;
20334                                                oc64data[it.oIndex + 1] = oy;
20335                                        }
20336                                }
20337                        } else {
20338                                while (it.hasNext()) {
20339                                        final double ix = it.aDouble;
20340                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
20341                                        Complex tz;
20342                                        float ox;
20343                                        float oy;
20344                                        tz = new Complex(ix, iy).acos();
20345                                        ox = (float) (tz.getReal());
20346                                        oy = (float) (tz.getImaginary());
20347                                        oc64data[it.oIndex] = ox;
20348                                        oc64data[it.oIndex + 1] = oy;
20349                                }
20350                        }
20351                        break;
20352                case Dataset.COMPLEX128:
20353                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
20354                        if (!da.isComplex()) {
20355                                if (it.isOutputDouble()) {
20356                                        final double iy = 0;
20357                                        while (it.hasNext()) {
20358                                                final double ix = it.aDouble;
20359                                                Complex tz;
20360                                                double ox;
20361                                                double oy;
20362                                                tz = new Complex(ix, iy).acos();
20363                                                ox = (tz.getReal());
20364                                                oy = (tz.getImaginary());
20365                                                oc128data[it.oIndex] = ox;
20366                                                oc128data[it.oIndex + 1] = oy;
20367                                        }
20368                                } else {
20369                                        final long iy = 0;
20370                                        while (it.hasNext()) {
20371                                                final long ix = it.aLong;
20372                                                Complex tz;
20373                                                double ox;
20374                                                double oy;
20375                                                tz = new Complex(ix, iy).acos();
20376                                                ox = (tz.getReal());
20377                                                oy = (tz.getImaginary());
20378                                                oc128data[it.oIndex] = ox;
20379                                                oc128data[it.oIndex + 1] = oy;
20380                                        }
20381                                }
20382                        } else {
20383                                while (it.hasNext()) {
20384                                        final double ix = it.aDouble;
20385                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
20386                                        Complex tz;
20387                                        double ox;
20388                                        double oy;
20389                                        tz = new Complex(ix, iy).acos();
20390                                        ox = (tz.getReal());
20391                                        oy = (tz.getImaginary());
20392                                        oc128data[it.oIndex] = ox;
20393                                        oc128data[it.oIndex + 1] = oy;
20394                                }
20395                        }
20396                        break;
20397                default:
20398                        throw new IllegalArgumentException("arccos supports integer, compound integer, real, compound real, complex datasets only");
20399                }
20400
20401                addFunctionName(result, "arccos");
20402                return result;
20403        }
20404
20405        /**
20406         * arctan - evaluate the inverse tangent function on each element of the dataset
20407         * @param a single operand
20408         * @return dataset
20409         */
20410        public static Dataset arctan(final Object a) {
20411                return arctan(a, null);
20412        }
20413
20414        /**
20415         * arctan - evaluate the inverse tangent function on each element of the dataset
20416         * @param a single operand
20417         * @param o output can be null - in which case, a new dataset is created
20418         * @return dataset
20419         */
20420        public static Dataset arctan(final Object a, final Dataset o) {
20421                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
20422                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
20423                final Dataset result = it.getOutput();
20424                if (!result.isComplex()) {
20425                        if (da.isComplex()) {
20426                                da = da.getRealView();
20427                                it = new SingleInputBroadcastIterator(da, result, true);
20428                        }
20429                }
20430                final int is = result.getElementsPerItem();
20431                final int as = da.getElementsPerItem();
20432                final int dt = result.getDType();
20433
20434                switch(dt) {
20435                case Dataset.INT8:
20436                        final byte[] oi8data = ((ByteDataset) result).getData();
20437                        if (it.isOutputDouble()) {
20438                                while (it.hasNext()) {
20439                                        final double ix = it.aDouble;
20440                                        byte ox;
20441                                        ox = (byte) toLong(Math.atan(ix));
20442                                        oi8data[it.oIndex] = ox;
20443                                }
20444                        } else {
20445                                while (it.hasNext()) {
20446                                        final long ix = it.aLong;
20447                                        byte ox;
20448                                        ox = (byte) toLong(Math.atan(ix));
20449                                        oi8data[it.oIndex] = ox;
20450                                }
20451                        }
20452                        break;
20453                case Dataset.INT16:
20454                        final short[] oi16data = ((ShortDataset) result).getData();
20455                        if (it.isOutputDouble()) {
20456                                while (it.hasNext()) {
20457                                        final double ix = it.aDouble;
20458                                        short ox;
20459                                        ox = (short) toLong(Math.atan(ix));
20460                                        oi16data[it.oIndex] = ox;
20461                                }
20462                        } else {
20463                                while (it.hasNext()) {
20464                                        final long ix = it.aLong;
20465                                        short ox;
20466                                        ox = (short) toLong(Math.atan(ix));
20467                                        oi16data[it.oIndex] = ox;
20468                                }
20469                        }
20470                        break;
20471                case Dataset.INT64:
20472                        final long[] oi64data = ((LongDataset) result).getData();
20473                        if (it.isOutputDouble()) {
20474                                while (it.hasNext()) {
20475                                        final double ix = it.aDouble;
20476                                        long ox;
20477                                        ox = toLong(Math.atan(ix));
20478                                        oi64data[it.oIndex] = ox;
20479                                }
20480                        } else {
20481                                while (it.hasNext()) {
20482                                        final long ix = it.aLong;
20483                                        long ox;
20484                                        ox = toLong(Math.atan(ix));
20485                                        oi64data[it.oIndex] = ox;
20486                                }
20487                        }
20488                        break;
20489                case Dataset.INT32:
20490                        final int[] oi32data = ((IntegerDataset) result).getData();
20491                        if (it.isOutputDouble()) {
20492                                while (it.hasNext()) {
20493                                        final double ix = it.aDouble;
20494                                        int ox;
20495                                        ox = (int) toLong(Math.atan(ix));
20496                                        oi32data[it.oIndex] = ox;
20497                                }
20498                        } else {
20499                                while (it.hasNext()) {
20500                                        final long ix = it.aLong;
20501                                        int ox;
20502                                        ox = (int) toLong(Math.atan(ix));
20503                                        oi32data[it.oIndex] = ox;
20504                                }
20505                        }
20506                        break;
20507                case Dataset.ARRAYINT8:
20508                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
20509                        if (is == 1) {
20510                                if (it.isOutputDouble()) {
20511                                        while (it.hasNext()) {
20512                                                final double ix = it.aDouble;
20513                                                byte ox;
20514                                                ox = (byte) toLong(Math.atan(ix));
20515                                                oai8data[it.oIndex] = ox;
20516                                        }
20517                                } else {
20518                                        while (it.hasNext()) {
20519                                                final long ix = it.aLong;
20520                                                byte ox;
20521                                                ox = (byte) toLong(Math.atan(ix));
20522                                                oai8data[it.oIndex] = ox;
20523                                        }
20524                                }
20525                        } else if (as == 1) {
20526                                if (it.isOutputDouble()) {
20527                                        while (it.hasNext()) {
20528                                                final double ix = it.aDouble;
20529                                                byte ox;
20530                                                ox = (byte) toLong(Math.atan(ix));
20531                                                for (int j = 0; j < is; j++) {
20532                                                        oai8data[it.oIndex + j] = ox;
20533                                                }
20534                                        }
20535                                } else {
20536                                        while (it.hasNext()) {
20537                                                final long ix = it.aLong;
20538                                                byte ox;
20539                                                ox = (byte) toLong(Math.atan(ix));
20540                                                for (int j = 0; j < is; j++) {
20541                                                        oai8data[it.oIndex + j] = ox;
20542                                                }
20543                                        }
20544                                }
20545                        } else {
20546                                if (it.isOutputDouble()) {
20547                                        while (it.hasNext()) {
20548                                                for (int j = 0; j < is; j++) {
20549                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20550                                                        byte ox;
20551                                                        ox = (byte) toLong(Math.atan(ix));
20552                                                        oai8data[it.oIndex + j] = ox;
20553                                                }
20554                                        }
20555                                } else {
20556                                        while (it.hasNext()) {
20557                                                for (int j = 0; j < is; j++) {
20558                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20559                                                        byte ox;
20560                                                        ox = (byte) toLong(Math.atan(ix));
20561                                                        oai8data[it.oIndex + j] = ox;
20562                                                }
20563                                        }
20564                                }
20565                        }
20566                        break;
20567                case Dataset.ARRAYINT16:
20568                        final short[] oai16data = ((CompoundShortDataset) result).getData();
20569                        if (is == 1) {
20570                                if (it.isOutputDouble()) {
20571                                        while (it.hasNext()) {
20572                                                final double ix = it.aDouble;
20573                                                short ox;
20574                                                ox = (short) toLong(Math.atan(ix));
20575                                                oai16data[it.oIndex] = ox;
20576                                        }
20577                                } else {
20578                                        while (it.hasNext()) {
20579                                                final long ix = it.aLong;
20580                                                short ox;
20581                                                ox = (short) toLong(Math.atan(ix));
20582                                                oai16data[it.oIndex] = ox;
20583                                        }
20584                                }
20585                        } else if (as == 1) {
20586                                if (it.isOutputDouble()) {
20587                                        while (it.hasNext()) {
20588                                                final double ix = it.aDouble;
20589                                                short ox;
20590                                                ox = (short) toLong(Math.atan(ix));
20591                                                for (int j = 0; j < is; j++) {
20592                                                        oai16data[it.oIndex + j] = ox;
20593                                                }
20594                                        }
20595                                } else {
20596                                        while (it.hasNext()) {
20597                                                final long ix = it.aLong;
20598                                                short ox;
20599                                                ox = (short) toLong(Math.atan(ix));
20600                                                for (int j = 0; j < is; j++) {
20601                                                        oai16data[it.oIndex + j] = ox;
20602                                                }
20603                                        }
20604                                }
20605                        } else {
20606                                if (it.isOutputDouble()) {
20607                                        while (it.hasNext()) {
20608                                                for (int j = 0; j < is; j++) {
20609                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20610                                                        short ox;
20611                                                        ox = (short) toLong(Math.atan(ix));
20612                                                        oai16data[it.oIndex + j] = ox;
20613                                                }
20614                                        }
20615                                } else {
20616                                        while (it.hasNext()) {
20617                                                for (int j = 0; j < is; j++) {
20618                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20619                                                        short ox;
20620                                                        ox = (short) toLong(Math.atan(ix));
20621                                                        oai16data[it.oIndex + j] = ox;
20622                                                }
20623                                        }
20624                                }
20625                        }
20626                        break;
20627                case Dataset.ARRAYINT64:
20628                        final long[] oai64data = ((CompoundLongDataset) result).getData();
20629                        if (is == 1) {
20630                                if (it.isOutputDouble()) {
20631                                        while (it.hasNext()) {
20632                                                final double ix = it.aDouble;
20633                                                long ox;
20634                                                ox = toLong(Math.atan(ix));
20635                                                oai64data[it.oIndex] = ox;
20636                                        }
20637                                } else {
20638                                        while (it.hasNext()) {
20639                                                final long ix = it.aLong;
20640                                                long ox;
20641                                                ox = toLong(Math.atan(ix));
20642                                                oai64data[it.oIndex] = ox;
20643                                        }
20644                                }
20645                        } else if (as == 1) {
20646                                if (it.isOutputDouble()) {
20647                                        while (it.hasNext()) {
20648                                                final double ix = it.aDouble;
20649                                                long ox;
20650                                                ox = toLong(Math.atan(ix));
20651                                                for (int j = 0; j < is; j++) {
20652                                                        oai64data[it.oIndex + j] = ox;
20653                                                }
20654                                        }
20655                                } else {
20656                                        while (it.hasNext()) {
20657                                                final long ix = it.aLong;
20658                                                long ox;
20659                                                ox = toLong(Math.atan(ix));
20660                                                for (int j = 0; j < is; j++) {
20661                                                        oai64data[it.oIndex + j] = ox;
20662                                                }
20663                                        }
20664                                }
20665                        } else {
20666                                if (it.isOutputDouble()) {
20667                                        while (it.hasNext()) {
20668                                                for (int j = 0; j < is; j++) {
20669                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20670                                                        long ox;
20671                                                        ox = toLong(Math.atan(ix));
20672                                                        oai64data[it.oIndex + j] = ox;
20673                                                }
20674                                        }
20675                                } else {
20676                                        while (it.hasNext()) {
20677                                                for (int j = 0; j < is; j++) {
20678                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20679                                                        long ox;
20680                                                        ox = toLong(Math.atan(ix));
20681                                                        oai64data[it.oIndex + j] = ox;
20682                                                }
20683                                        }
20684                                }
20685                        }
20686                        break;
20687                case Dataset.ARRAYINT32:
20688                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
20689                        if (is == 1) {
20690                                if (it.isOutputDouble()) {
20691                                        while (it.hasNext()) {
20692                                                final double ix = it.aDouble;
20693                                                int ox;
20694                                                ox = (int) toLong(Math.atan(ix));
20695                                                oai32data[it.oIndex] = ox;
20696                                        }
20697                                } else {
20698                                        while (it.hasNext()) {
20699                                                final long ix = it.aLong;
20700                                                int ox;
20701                                                ox = (int) toLong(Math.atan(ix));
20702                                                oai32data[it.oIndex] = ox;
20703                                        }
20704                                }
20705                        } else if (as == 1) {
20706                                if (it.isOutputDouble()) {
20707                                        while (it.hasNext()) {
20708                                                final double ix = it.aDouble;
20709                                                int ox;
20710                                                ox = (int) toLong(Math.atan(ix));
20711                                                for (int j = 0; j < is; j++) {
20712                                                        oai32data[it.oIndex + j] = ox;
20713                                                }
20714                                        }
20715                                } else {
20716                                        while (it.hasNext()) {
20717                                                final long ix = it.aLong;
20718                                                int ox;
20719                                                ox = (int) toLong(Math.atan(ix));
20720                                                for (int j = 0; j < is; j++) {
20721                                                        oai32data[it.oIndex + j] = ox;
20722                                                }
20723                                        }
20724                                }
20725                        } else {
20726                                if (it.isOutputDouble()) {
20727                                        while (it.hasNext()) {
20728                                                for (int j = 0; j < is; j++) {
20729                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20730                                                        int ox;
20731                                                        ox = (int) toLong(Math.atan(ix));
20732                                                        oai32data[it.oIndex + j] = ox;
20733                                                }
20734                                        }
20735                                } else {
20736                                        while (it.hasNext()) {
20737                                                for (int j = 0; j < is; j++) {
20738                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20739                                                        int ox;
20740                                                        ox = (int) toLong(Math.atan(ix));
20741                                                        oai32data[it.oIndex + j] = ox;
20742                                                }
20743                                        }
20744                                }
20745                        }
20746                        break;
20747                case Dataset.FLOAT32:
20748                        final float[] of32data = ((FloatDataset) result).getData();
20749                        if (it.isOutputDouble()) {
20750                                while (it.hasNext()) {
20751                                        final double ix = it.aDouble;
20752                                        float ox;
20753                                        ox = (float) (Math.atan(ix));
20754                                        of32data[it.oIndex] = ox;
20755                                }
20756                        } else {
20757                                while (it.hasNext()) {
20758                                        final long ix = it.aLong;
20759                                        float ox;
20760                                        ox = (float) (Math.atan(ix));
20761                                        of32data[it.oIndex] = ox;
20762                                }
20763                        }
20764                        break;
20765                case Dataset.FLOAT64:
20766                        final double[] of64data = ((DoubleDataset) result).getData();
20767                        if (it.isOutputDouble()) {
20768                                while (it.hasNext()) {
20769                                        final double ix = it.aDouble;
20770                                        double ox;
20771                                        ox = (Math.atan(ix));
20772                                        of64data[it.oIndex] = ox;
20773                                }
20774                        } else {
20775                                while (it.hasNext()) {
20776                                        final long ix = it.aLong;
20777                                        double ox;
20778                                        ox = (Math.atan(ix));
20779                                        of64data[it.oIndex] = ox;
20780                                }
20781                        }
20782                        break;
20783                case Dataset.ARRAYFLOAT32:
20784                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
20785                        if (is == 1) {
20786                                if (it.isOutputDouble()) {
20787                                        while (it.hasNext()) {
20788                                                final double ix = it.aDouble;
20789                                                float ox;
20790                                                ox = (float) (Math.atan(ix));
20791                                                oaf32data[it.oIndex] = ox;
20792                                        }
20793                                } else {
20794                                        while (it.hasNext()) {
20795                                                final long ix = it.aLong;
20796                                                float ox;
20797                                                ox = (float) (Math.atan(ix));
20798                                                oaf32data[it.oIndex] = ox;
20799                                        }
20800                                }
20801                        } else if (as == 1) {
20802                                if (it.isOutputDouble()) {
20803                                        while (it.hasNext()) {
20804                                                final double ix = it.aDouble;
20805                                                float ox;
20806                                                ox = (float) (Math.atan(ix));
20807                                                for (int j = 0; j < is; j++) {
20808                                                        oaf32data[it.oIndex + j] = ox;
20809                                                }
20810                                        }
20811                                } else {
20812                                        while (it.hasNext()) {
20813                                                final long ix = it.aLong;
20814                                                float ox;
20815                                                ox = (float) (Math.atan(ix));
20816                                                for (int j = 0; j < is; j++) {
20817                                                        oaf32data[it.oIndex + j] = ox;
20818                                                }
20819                                        }
20820                                }
20821                        } else {
20822                                if (it.isOutputDouble()) {
20823                                        while (it.hasNext()) {
20824                                                for (int j = 0; j < is; j++) {
20825                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20826                                                        float ox;
20827                                                        ox = (float) (Math.atan(ix));
20828                                                        oaf32data[it.oIndex + j] = ox;
20829                                                }
20830                                        }
20831                                } else {
20832                                        while (it.hasNext()) {
20833                                                for (int j = 0; j < is; j++) {
20834                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20835                                                        float ox;
20836                                                        ox = (float) (Math.atan(ix));
20837                                                        oaf32data[it.oIndex + j] = ox;
20838                                                }
20839                                        }
20840                                }
20841                        }
20842                        break;
20843                case Dataset.ARRAYFLOAT64:
20844                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
20845                        if (is == 1) {
20846                                if (it.isOutputDouble()) {
20847                                        while (it.hasNext()) {
20848                                                final double ix = it.aDouble;
20849                                                double ox;
20850                                                ox = (Math.atan(ix));
20851                                                oaf64data[it.oIndex] = ox;
20852                                        }
20853                                } else {
20854                                        while (it.hasNext()) {
20855                                                final long ix = it.aLong;
20856                                                double ox;
20857                                                ox = (Math.atan(ix));
20858                                                oaf64data[it.oIndex] = ox;
20859                                        }
20860                                }
20861                        } else if (as == 1) {
20862                                if (it.isOutputDouble()) {
20863                                        while (it.hasNext()) {
20864                                                final double ix = it.aDouble;
20865                                                double ox;
20866                                                ox = (Math.atan(ix));
20867                                                for (int j = 0; j < is; j++) {
20868                                                        oaf64data[it.oIndex + j] = ox;
20869                                                }
20870                                        }
20871                                } else {
20872                                        while (it.hasNext()) {
20873                                                final long ix = it.aLong;
20874                                                double ox;
20875                                                ox = (Math.atan(ix));
20876                                                for (int j = 0; j < is; j++) {
20877                                                        oaf64data[it.oIndex + j] = ox;
20878                                                }
20879                                        }
20880                                }
20881                        } else {
20882                                if (it.isOutputDouble()) {
20883                                        while (it.hasNext()) {
20884                                                for (int j = 0; j < is; j++) {
20885                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
20886                                                        double ox;
20887                                                        ox = (Math.atan(ix));
20888                                                        oaf64data[it.oIndex + j] = ox;
20889                                                }
20890                                        }
20891                                } else {
20892                                        while (it.hasNext()) {
20893                                                for (int j = 0; j < is; j++) {
20894                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
20895                                                        double ox;
20896                                                        ox = (Math.atan(ix));
20897                                                        oaf64data[it.oIndex + j] = ox;
20898                                                }
20899                                        }
20900                                }
20901                        }
20902                        break;
20903                case Dataset.COMPLEX64:
20904                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
20905                        if (!da.isComplex()) {
20906                                if (it.isOutputDouble()) {
20907                                        final double iy = 0;
20908                                        while (it.hasNext()) {
20909                                                final double ix = it.aDouble;
20910                                                Complex tz;
20911                                                float ox;
20912                                                float oy;
20913                                                tz = new Complex(ix, iy).atan();
20914                                                ox = (float) (tz.getReal());
20915                                                oy = (float) (tz.getImaginary());
20916                                                oc64data[it.oIndex] = ox;
20917                                                oc64data[it.oIndex + 1] = oy;
20918                                        }
20919                                } else {
20920                                        final long iy = 0;
20921                                        while (it.hasNext()) {
20922                                                final long ix = it.aLong;
20923                                                Complex tz;
20924                                                float ox;
20925                                                float oy;
20926                                                tz = new Complex(ix, iy).atan();
20927                                                ox = (float) toLong(tz.getReal());
20928                                                oy = (float) toLong(tz.getImaginary());
20929                                                oc64data[it.oIndex] = ox;
20930                                                oc64data[it.oIndex + 1] = oy;
20931                                        }
20932                                }
20933                        } else {
20934                                while (it.hasNext()) {
20935                                        final double ix = it.aDouble;
20936                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
20937                                        Complex tz;
20938                                        float ox;
20939                                        float oy;
20940                                        tz = new Complex(ix, iy).atan();
20941                                        ox = (float) (tz.getReal());
20942                                        oy = (float) (tz.getImaginary());
20943                                        oc64data[it.oIndex] = ox;
20944                                        oc64data[it.oIndex + 1] = oy;
20945                                }
20946                        }
20947                        break;
20948                case Dataset.COMPLEX128:
20949                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
20950                        if (!da.isComplex()) {
20951                                if (it.isOutputDouble()) {
20952                                        final double iy = 0;
20953                                        while (it.hasNext()) {
20954                                                final double ix = it.aDouble;
20955                                                Complex tz;
20956                                                double ox;
20957                                                double oy;
20958                                                tz = new Complex(ix, iy).atan();
20959                                                ox = (tz.getReal());
20960                                                oy = (tz.getImaginary());
20961                                                oc128data[it.oIndex] = ox;
20962                                                oc128data[it.oIndex + 1] = oy;
20963                                        }
20964                                } else {
20965                                        final long iy = 0;
20966                                        while (it.hasNext()) {
20967                                                final long ix = it.aLong;
20968                                                Complex tz;
20969                                                double ox;
20970                                                double oy;
20971                                                tz = new Complex(ix, iy).atan();
20972                                                ox = (tz.getReal());
20973                                                oy = (tz.getImaginary());
20974                                                oc128data[it.oIndex] = ox;
20975                                                oc128data[it.oIndex + 1] = oy;
20976                                        }
20977                                }
20978                        } else {
20979                                while (it.hasNext()) {
20980                                        final double ix = it.aDouble;
20981                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
20982                                        Complex tz;
20983                                        double ox;
20984                                        double oy;
20985                                        tz = new Complex(ix, iy).atan();
20986                                        ox = (tz.getReal());
20987                                        oy = (tz.getImaginary());
20988                                        oc128data[it.oIndex] = ox;
20989                                        oc128data[it.oIndex + 1] = oy;
20990                                }
20991                        }
20992                        break;
20993                default:
20994                        throw new IllegalArgumentException("arctan supports integer, compound integer, real, compound real, complex datasets only");
20995                }
20996
20997                addFunctionName(result, "arctan");
20998                return result;
20999        }
21000
21001        /**
21002         * sinh - evaluate the hyperbolic sine function on each element of the dataset
21003         * @param a single operand
21004         * @return dataset
21005         */
21006        public static Dataset sinh(final Object a) {
21007                return sinh(a, null);
21008        }
21009
21010        /**
21011         * sinh - evaluate the hyperbolic sine function on each element of the dataset
21012         * @param a single operand
21013         * @param o output can be null - in which case, a new dataset is created
21014         * @return dataset
21015         */
21016        public static Dataset sinh(final Object a, final Dataset o) {
21017                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
21018                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
21019                final Dataset result = it.getOutput();
21020                if (!result.isComplex()) {
21021                        if (da.isComplex()) {
21022                                da = da.getRealView();
21023                                it = new SingleInputBroadcastIterator(da, result, true);
21024                        }
21025                }
21026                final int is = result.getElementsPerItem();
21027                final int as = da.getElementsPerItem();
21028                final int dt = result.getDType();
21029
21030                switch(dt) {
21031                case Dataset.INT8:
21032                        final byte[] oi8data = ((ByteDataset) result).getData();
21033                        if (it.isOutputDouble()) {
21034                                while (it.hasNext()) {
21035                                        final double ix = it.aDouble;
21036                                        byte ox;
21037                                        ox = (byte) toLong(Math.sinh(ix));
21038                                        oi8data[it.oIndex] = ox;
21039                                }
21040                        } else {
21041                                while (it.hasNext()) {
21042                                        final long ix = it.aLong;
21043                                        byte ox;
21044                                        ox = (byte) toLong(Math.sinh(ix));
21045                                        oi8data[it.oIndex] = ox;
21046                                }
21047                        }
21048                        break;
21049                case Dataset.INT16:
21050                        final short[] oi16data = ((ShortDataset) result).getData();
21051                        if (it.isOutputDouble()) {
21052                                while (it.hasNext()) {
21053                                        final double ix = it.aDouble;
21054                                        short ox;
21055                                        ox = (short) toLong(Math.sinh(ix));
21056                                        oi16data[it.oIndex] = ox;
21057                                }
21058                        } else {
21059                                while (it.hasNext()) {
21060                                        final long ix = it.aLong;
21061                                        short ox;
21062                                        ox = (short) toLong(Math.sinh(ix));
21063                                        oi16data[it.oIndex] = ox;
21064                                }
21065                        }
21066                        break;
21067                case Dataset.INT64:
21068                        final long[] oi64data = ((LongDataset) result).getData();
21069                        if (it.isOutputDouble()) {
21070                                while (it.hasNext()) {
21071                                        final double ix = it.aDouble;
21072                                        long ox;
21073                                        ox = toLong(Math.sinh(ix));
21074                                        oi64data[it.oIndex] = ox;
21075                                }
21076                        } else {
21077                                while (it.hasNext()) {
21078                                        final long ix = it.aLong;
21079                                        long ox;
21080                                        ox = toLong(Math.sinh(ix));
21081                                        oi64data[it.oIndex] = ox;
21082                                }
21083                        }
21084                        break;
21085                case Dataset.INT32:
21086                        final int[] oi32data = ((IntegerDataset) result).getData();
21087                        if (it.isOutputDouble()) {
21088                                while (it.hasNext()) {
21089                                        final double ix = it.aDouble;
21090                                        int ox;
21091                                        ox = (int) toLong(Math.sinh(ix));
21092                                        oi32data[it.oIndex] = ox;
21093                                }
21094                        } else {
21095                                while (it.hasNext()) {
21096                                        final long ix = it.aLong;
21097                                        int ox;
21098                                        ox = (int) toLong(Math.sinh(ix));
21099                                        oi32data[it.oIndex] = ox;
21100                                }
21101                        }
21102                        break;
21103                case Dataset.ARRAYINT8:
21104                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
21105                        if (is == 1) {
21106                                if (it.isOutputDouble()) {
21107                                        while (it.hasNext()) {
21108                                                final double ix = it.aDouble;
21109                                                byte ox;
21110                                                ox = (byte) toLong(Math.sinh(ix));
21111                                                oai8data[it.oIndex] = ox;
21112                                        }
21113                                } else {
21114                                        while (it.hasNext()) {
21115                                                final long ix = it.aLong;
21116                                                byte ox;
21117                                                ox = (byte) toLong(Math.sinh(ix));
21118                                                oai8data[it.oIndex] = ox;
21119                                        }
21120                                }
21121                        } else if (as == 1) {
21122                                if (it.isOutputDouble()) {
21123                                        while (it.hasNext()) {
21124                                                final double ix = it.aDouble;
21125                                                byte ox;
21126                                                ox = (byte) toLong(Math.sinh(ix));
21127                                                for (int j = 0; j < is; j++) {
21128                                                        oai8data[it.oIndex + j] = ox;
21129                                                }
21130                                        }
21131                                } else {
21132                                        while (it.hasNext()) {
21133                                                final long ix = it.aLong;
21134                                                byte ox;
21135                                                ox = (byte) toLong(Math.sinh(ix));
21136                                                for (int j = 0; j < is; j++) {
21137                                                        oai8data[it.oIndex + j] = ox;
21138                                                }
21139                                        }
21140                                }
21141                        } else {
21142                                if (it.isOutputDouble()) {
21143                                        while (it.hasNext()) {
21144                                                for (int j = 0; j < is; j++) {
21145                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21146                                                        byte ox;
21147                                                        ox = (byte) toLong(Math.sinh(ix));
21148                                                        oai8data[it.oIndex + j] = ox;
21149                                                }
21150                                        }
21151                                } else {
21152                                        while (it.hasNext()) {
21153                                                for (int j = 0; j < is; j++) {
21154                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21155                                                        byte ox;
21156                                                        ox = (byte) toLong(Math.sinh(ix));
21157                                                        oai8data[it.oIndex + j] = ox;
21158                                                }
21159                                        }
21160                                }
21161                        }
21162                        break;
21163                case Dataset.ARRAYINT16:
21164                        final short[] oai16data = ((CompoundShortDataset) result).getData();
21165                        if (is == 1) {
21166                                if (it.isOutputDouble()) {
21167                                        while (it.hasNext()) {
21168                                                final double ix = it.aDouble;
21169                                                short ox;
21170                                                ox = (short) toLong(Math.sinh(ix));
21171                                                oai16data[it.oIndex] = ox;
21172                                        }
21173                                } else {
21174                                        while (it.hasNext()) {
21175                                                final long ix = it.aLong;
21176                                                short ox;
21177                                                ox = (short) toLong(Math.sinh(ix));
21178                                                oai16data[it.oIndex] = ox;
21179                                        }
21180                                }
21181                        } else if (as == 1) {
21182                                if (it.isOutputDouble()) {
21183                                        while (it.hasNext()) {
21184                                                final double ix = it.aDouble;
21185                                                short ox;
21186                                                ox = (short) toLong(Math.sinh(ix));
21187                                                for (int j = 0; j < is; j++) {
21188                                                        oai16data[it.oIndex + j] = ox;
21189                                                }
21190                                        }
21191                                } else {
21192                                        while (it.hasNext()) {
21193                                                final long ix = it.aLong;
21194                                                short ox;
21195                                                ox = (short) toLong(Math.sinh(ix));
21196                                                for (int j = 0; j < is; j++) {
21197                                                        oai16data[it.oIndex + j] = ox;
21198                                                }
21199                                        }
21200                                }
21201                        } else {
21202                                if (it.isOutputDouble()) {
21203                                        while (it.hasNext()) {
21204                                                for (int j = 0; j < is; j++) {
21205                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21206                                                        short ox;
21207                                                        ox = (short) toLong(Math.sinh(ix));
21208                                                        oai16data[it.oIndex + j] = ox;
21209                                                }
21210                                        }
21211                                } else {
21212                                        while (it.hasNext()) {
21213                                                for (int j = 0; j < is; j++) {
21214                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21215                                                        short ox;
21216                                                        ox = (short) toLong(Math.sinh(ix));
21217                                                        oai16data[it.oIndex + j] = ox;
21218                                                }
21219                                        }
21220                                }
21221                        }
21222                        break;
21223                case Dataset.ARRAYINT64:
21224                        final long[] oai64data = ((CompoundLongDataset) result).getData();
21225                        if (is == 1) {
21226                                if (it.isOutputDouble()) {
21227                                        while (it.hasNext()) {
21228                                                final double ix = it.aDouble;
21229                                                long ox;
21230                                                ox = toLong(Math.sinh(ix));
21231                                                oai64data[it.oIndex] = ox;
21232                                        }
21233                                } else {
21234                                        while (it.hasNext()) {
21235                                                final long ix = it.aLong;
21236                                                long ox;
21237                                                ox = toLong(Math.sinh(ix));
21238                                                oai64data[it.oIndex] = ox;
21239                                        }
21240                                }
21241                        } else if (as == 1) {
21242                                if (it.isOutputDouble()) {
21243                                        while (it.hasNext()) {
21244                                                final double ix = it.aDouble;
21245                                                long ox;
21246                                                ox = toLong(Math.sinh(ix));
21247                                                for (int j = 0; j < is; j++) {
21248                                                        oai64data[it.oIndex + j] = ox;
21249                                                }
21250                                        }
21251                                } else {
21252                                        while (it.hasNext()) {
21253                                                final long ix = it.aLong;
21254                                                long ox;
21255                                                ox = toLong(Math.sinh(ix));
21256                                                for (int j = 0; j < is; j++) {
21257                                                        oai64data[it.oIndex + j] = ox;
21258                                                }
21259                                        }
21260                                }
21261                        } else {
21262                                if (it.isOutputDouble()) {
21263                                        while (it.hasNext()) {
21264                                                for (int j = 0; j < is; j++) {
21265                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21266                                                        long ox;
21267                                                        ox = toLong(Math.sinh(ix));
21268                                                        oai64data[it.oIndex + j] = ox;
21269                                                }
21270                                        }
21271                                } else {
21272                                        while (it.hasNext()) {
21273                                                for (int j = 0; j < is; j++) {
21274                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21275                                                        long ox;
21276                                                        ox = toLong(Math.sinh(ix));
21277                                                        oai64data[it.oIndex + j] = ox;
21278                                                }
21279                                        }
21280                                }
21281                        }
21282                        break;
21283                case Dataset.ARRAYINT32:
21284                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
21285                        if (is == 1) {
21286                                if (it.isOutputDouble()) {
21287                                        while (it.hasNext()) {
21288                                                final double ix = it.aDouble;
21289                                                int ox;
21290                                                ox = (int) toLong(Math.sinh(ix));
21291                                                oai32data[it.oIndex] = ox;
21292                                        }
21293                                } else {
21294                                        while (it.hasNext()) {
21295                                                final long ix = it.aLong;
21296                                                int ox;
21297                                                ox = (int) toLong(Math.sinh(ix));
21298                                                oai32data[it.oIndex] = ox;
21299                                        }
21300                                }
21301                        } else if (as == 1) {
21302                                if (it.isOutputDouble()) {
21303                                        while (it.hasNext()) {
21304                                                final double ix = it.aDouble;
21305                                                int ox;
21306                                                ox = (int) toLong(Math.sinh(ix));
21307                                                for (int j = 0; j < is; j++) {
21308                                                        oai32data[it.oIndex + j] = ox;
21309                                                }
21310                                        }
21311                                } else {
21312                                        while (it.hasNext()) {
21313                                                final long ix = it.aLong;
21314                                                int ox;
21315                                                ox = (int) toLong(Math.sinh(ix));
21316                                                for (int j = 0; j < is; j++) {
21317                                                        oai32data[it.oIndex + j] = ox;
21318                                                }
21319                                        }
21320                                }
21321                        } else {
21322                                if (it.isOutputDouble()) {
21323                                        while (it.hasNext()) {
21324                                                for (int j = 0; j < is; j++) {
21325                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21326                                                        int ox;
21327                                                        ox = (int) toLong(Math.sinh(ix));
21328                                                        oai32data[it.oIndex + j] = ox;
21329                                                }
21330                                        }
21331                                } else {
21332                                        while (it.hasNext()) {
21333                                                for (int j = 0; j < is; j++) {
21334                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21335                                                        int ox;
21336                                                        ox = (int) toLong(Math.sinh(ix));
21337                                                        oai32data[it.oIndex + j] = ox;
21338                                                }
21339                                        }
21340                                }
21341                        }
21342                        break;
21343                case Dataset.FLOAT32:
21344                        final float[] of32data = ((FloatDataset) result).getData();
21345                        if (it.isOutputDouble()) {
21346                                while (it.hasNext()) {
21347                                        final double ix = it.aDouble;
21348                                        float ox;
21349                                        ox = (float) (Math.sinh(ix));
21350                                        of32data[it.oIndex] = ox;
21351                                }
21352                        } else {
21353                                while (it.hasNext()) {
21354                                        final long ix = it.aLong;
21355                                        float ox;
21356                                        ox = (float) (Math.sinh(ix));
21357                                        of32data[it.oIndex] = ox;
21358                                }
21359                        }
21360                        break;
21361                case Dataset.FLOAT64:
21362                        final double[] of64data = ((DoubleDataset) result).getData();
21363                        if (it.isOutputDouble()) {
21364                                while (it.hasNext()) {
21365                                        final double ix = it.aDouble;
21366                                        double ox;
21367                                        ox = (Math.sinh(ix));
21368                                        of64data[it.oIndex] = ox;
21369                                }
21370                        } else {
21371                                while (it.hasNext()) {
21372                                        final long ix = it.aLong;
21373                                        double ox;
21374                                        ox = (Math.sinh(ix));
21375                                        of64data[it.oIndex] = ox;
21376                                }
21377                        }
21378                        break;
21379                case Dataset.ARRAYFLOAT32:
21380                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
21381                        if (is == 1) {
21382                                if (it.isOutputDouble()) {
21383                                        while (it.hasNext()) {
21384                                                final double ix = it.aDouble;
21385                                                float ox;
21386                                                ox = (float) (Math.sinh(ix));
21387                                                oaf32data[it.oIndex] = ox;
21388                                        }
21389                                } else {
21390                                        while (it.hasNext()) {
21391                                                final long ix = it.aLong;
21392                                                float ox;
21393                                                ox = (float) (Math.sinh(ix));
21394                                                oaf32data[it.oIndex] = ox;
21395                                        }
21396                                }
21397                        } else if (as == 1) {
21398                                if (it.isOutputDouble()) {
21399                                        while (it.hasNext()) {
21400                                                final double ix = it.aDouble;
21401                                                float ox;
21402                                                ox = (float) (Math.sinh(ix));
21403                                                for (int j = 0; j < is; j++) {
21404                                                        oaf32data[it.oIndex + j] = ox;
21405                                                }
21406                                        }
21407                                } else {
21408                                        while (it.hasNext()) {
21409                                                final long ix = it.aLong;
21410                                                float ox;
21411                                                ox = (float) (Math.sinh(ix));
21412                                                for (int j = 0; j < is; j++) {
21413                                                        oaf32data[it.oIndex + j] = ox;
21414                                                }
21415                                        }
21416                                }
21417                        } else {
21418                                if (it.isOutputDouble()) {
21419                                        while (it.hasNext()) {
21420                                                for (int j = 0; j < is; j++) {
21421                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21422                                                        float ox;
21423                                                        ox = (float) (Math.sinh(ix));
21424                                                        oaf32data[it.oIndex + j] = ox;
21425                                                }
21426                                        }
21427                                } else {
21428                                        while (it.hasNext()) {
21429                                                for (int j = 0; j < is; j++) {
21430                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21431                                                        float ox;
21432                                                        ox = (float) (Math.sinh(ix));
21433                                                        oaf32data[it.oIndex + j] = ox;
21434                                                }
21435                                        }
21436                                }
21437                        }
21438                        break;
21439                case Dataset.ARRAYFLOAT64:
21440                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
21441                        if (is == 1) {
21442                                if (it.isOutputDouble()) {
21443                                        while (it.hasNext()) {
21444                                                final double ix = it.aDouble;
21445                                                double ox;
21446                                                ox = (Math.sinh(ix));
21447                                                oaf64data[it.oIndex] = ox;
21448                                        }
21449                                } else {
21450                                        while (it.hasNext()) {
21451                                                final long ix = it.aLong;
21452                                                double ox;
21453                                                ox = (Math.sinh(ix));
21454                                                oaf64data[it.oIndex] = ox;
21455                                        }
21456                                }
21457                        } else if (as == 1) {
21458                                if (it.isOutputDouble()) {
21459                                        while (it.hasNext()) {
21460                                                final double ix = it.aDouble;
21461                                                double ox;
21462                                                ox = (Math.sinh(ix));
21463                                                for (int j = 0; j < is; j++) {
21464                                                        oaf64data[it.oIndex + j] = ox;
21465                                                }
21466                                        }
21467                                } else {
21468                                        while (it.hasNext()) {
21469                                                final long ix = it.aLong;
21470                                                double ox;
21471                                                ox = (Math.sinh(ix));
21472                                                for (int j = 0; j < is; j++) {
21473                                                        oaf64data[it.oIndex + j] = ox;
21474                                                }
21475                                        }
21476                                }
21477                        } else {
21478                                if (it.isOutputDouble()) {
21479                                        while (it.hasNext()) {
21480                                                for (int j = 0; j < is; j++) {
21481                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21482                                                        double ox;
21483                                                        ox = (Math.sinh(ix));
21484                                                        oaf64data[it.oIndex + j] = ox;
21485                                                }
21486                                        }
21487                                } else {
21488                                        while (it.hasNext()) {
21489                                                for (int j = 0; j < is; j++) {
21490                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21491                                                        double ox;
21492                                                        ox = (Math.sinh(ix));
21493                                                        oaf64data[it.oIndex + j] = ox;
21494                                                }
21495                                        }
21496                                }
21497                        }
21498                        break;
21499                case Dataset.COMPLEX64:
21500                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
21501                        if (!da.isComplex()) {
21502                                if (it.isOutputDouble()) {
21503                                        final double iy = 0;
21504                                        while (it.hasNext()) {
21505                                                final double ix = it.aDouble;
21506                                                float ox;
21507                                                float oy;
21508                                                ox = (float) (Math.sinh(ix)*Math.cos(iy));
21509                                                oy = (float) (Math.cosh(ix)*Math.sin(iy));
21510                                                oc64data[it.oIndex] = ox;
21511                                                oc64data[it.oIndex + 1] = oy;
21512                                        }
21513                                } else {
21514                                        final long iy = 0;
21515                                        while (it.hasNext()) {
21516                                                final long ix = it.aLong;
21517                                                float ox;
21518                                                float oy;
21519                                                ox = (float) toLong(Math.sinh(ix)*Math.cos(iy));
21520                                                oy = (float) toLong(Math.cosh(ix)*Math.sin(iy));
21521                                                oc64data[it.oIndex] = ox;
21522                                                oc64data[it.oIndex + 1] = oy;
21523                                        }
21524                                }
21525                        } else {
21526                                while (it.hasNext()) {
21527                                        final double ix = it.aDouble;
21528                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
21529                                        float ox;
21530                                        float oy;
21531                                        ox = (float) (Math.sinh(ix)*Math.cos(iy));
21532                                        oy = (float) (Math.cosh(ix)*Math.sin(iy));
21533                                        oc64data[it.oIndex] = ox;
21534                                        oc64data[it.oIndex + 1] = oy;
21535                                }
21536                        }
21537                        break;
21538                case Dataset.COMPLEX128:
21539                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
21540                        if (!da.isComplex()) {
21541                                if (it.isOutputDouble()) {
21542                                        final double iy = 0;
21543                                        while (it.hasNext()) {
21544                                                final double ix = it.aDouble;
21545                                                double ox;
21546                                                double oy;
21547                                                ox = (Math.sinh(ix)*Math.cos(iy));
21548                                                oy = (Math.cosh(ix)*Math.sin(iy));
21549                                                oc128data[it.oIndex] = ox;
21550                                                oc128data[it.oIndex + 1] = oy;
21551                                        }
21552                                } else {
21553                                        final long iy = 0;
21554                                        while (it.hasNext()) {
21555                                                final long ix = it.aLong;
21556                                                double ox;
21557                                                double oy;
21558                                                ox = (double) (Math.sinh(ix)*Math.cos(iy));
21559                                                oy = (double) (Math.cosh(ix)*Math.sin(iy));
21560                                                oc128data[it.oIndex] = ox;
21561                                                oc128data[it.oIndex + 1] = oy;
21562                                        }
21563                                }
21564                        } else {
21565                                while (it.hasNext()) {
21566                                        final double ix = it.aDouble;
21567                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
21568                                        double ox;
21569                                        double oy;
21570                                        ox = (Math.sinh(ix)*Math.cos(iy));
21571                                        oy = (Math.cosh(ix)*Math.sin(iy));
21572                                        oc128data[it.oIndex] = ox;
21573                                        oc128data[it.oIndex + 1] = oy;
21574                                }
21575                        }
21576                        break;
21577                default:
21578                        throw new IllegalArgumentException("sinh supports integer, compound integer, real, compound real, complex datasets only");
21579                }
21580
21581                addFunctionName(result, "sinh");
21582                return result;
21583        }
21584
21585        /**
21586         * cosh - evaluate the hyperbolic cosine function on each element of the dataset
21587         * @param a single operand
21588         * @return dataset
21589         */
21590        public static Dataset cosh(final Object a) {
21591                return cosh(a, null);
21592        }
21593
21594        /**
21595         * cosh - evaluate the hyperbolic cosine function on each element of the dataset
21596         * @param a single operand
21597         * @param o output can be null - in which case, a new dataset is created
21598         * @return dataset
21599         */
21600        public static Dataset cosh(final Object a, final Dataset o) {
21601                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
21602                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
21603                final Dataset result = it.getOutput();
21604                if (!result.isComplex()) {
21605                        if (da.isComplex()) {
21606                                da = da.getRealView();
21607                                it = new SingleInputBroadcastIterator(da, result, true);
21608                        }
21609                }
21610                final int is = result.getElementsPerItem();
21611                final int as = da.getElementsPerItem();
21612                final int dt = result.getDType();
21613
21614                switch(dt) {
21615                case Dataset.INT8:
21616                        final byte[] oi8data = ((ByteDataset) result).getData();
21617                        if (it.isOutputDouble()) {
21618                                while (it.hasNext()) {
21619                                        final double ix = it.aDouble;
21620                                        byte ox;
21621                                        ox = (byte) toLong(Math.cosh(ix));
21622                                        oi8data[it.oIndex] = ox;
21623                                }
21624                        } else {
21625                                while (it.hasNext()) {
21626                                        final long ix = it.aLong;
21627                                        byte ox;
21628                                        ox = (byte) toLong(Math.cosh(ix));
21629                                        oi8data[it.oIndex] = ox;
21630                                }
21631                        }
21632                        break;
21633                case Dataset.INT16:
21634                        final short[] oi16data = ((ShortDataset) result).getData();
21635                        if (it.isOutputDouble()) {
21636                                while (it.hasNext()) {
21637                                        final double ix = it.aDouble;
21638                                        short ox;
21639                                        ox = (short) toLong(Math.cosh(ix));
21640                                        oi16data[it.oIndex] = ox;
21641                                }
21642                        } else {
21643                                while (it.hasNext()) {
21644                                        final long ix = it.aLong;
21645                                        short ox;
21646                                        ox = (short) toLong(Math.cosh(ix));
21647                                        oi16data[it.oIndex] = ox;
21648                                }
21649                        }
21650                        break;
21651                case Dataset.INT64:
21652                        final long[] oi64data = ((LongDataset) result).getData();
21653                        if (it.isOutputDouble()) {
21654                                while (it.hasNext()) {
21655                                        final double ix = it.aDouble;
21656                                        long ox;
21657                                        ox = toLong(Math.cosh(ix));
21658                                        oi64data[it.oIndex] = ox;
21659                                }
21660                        } else {
21661                                while (it.hasNext()) {
21662                                        final long ix = it.aLong;
21663                                        long ox;
21664                                        ox = toLong(Math.cosh(ix));
21665                                        oi64data[it.oIndex] = ox;
21666                                }
21667                        }
21668                        break;
21669                case Dataset.INT32:
21670                        final int[] oi32data = ((IntegerDataset) result).getData();
21671                        if (it.isOutputDouble()) {
21672                                while (it.hasNext()) {
21673                                        final double ix = it.aDouble;
21674                                        int ox;
21675                                        ox = (int) toLong(Math.cosh(ix));
21676                                        oi32data[it.oIndex] = ox;
21677                                }
21678                        } else {
21679                                while (it.hasNext()) {
21680                                        final long ix = it.aLong;
21681                                        int ox;
21682                                        ox = (int) toLong(Math.cosh(ix));
21683                                        oi32data[it.oIndex] = ox;
21684                                }
21685                        }
21686                        break;
21687                case Dataset.ARRAYINT8:
21688                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
21689                        if (is == 1) {
21690                                if (it.isOutputDouble()) {
21691                                        while (it.hasNext()) {
21692                                                final double ix = it.aDouble;
21693                                                byte ox;
21694                                                ox = (byte) toLong(Math.cosh(ix));
21695                                                oai8data[it.oIndex] = ox;
21696                                        }
21697                                } else {
21698                                        while (it.hasNext()) {
21699                                                final long ix = it.aLong;
21700                                                byte ox;
21701                                                ox = (byte) toLong(Math.cosh(ix));
21702                                                oai8data[it.oIndex] = ox;
21703                                        }
21704                                }
21705                        } else if (as == 1) {
21706                                if (it.isOutputDouble()) {
21707                                        while (it.hasNext()) {
21708                                                final double ix = it.aDouble;
21709                                                byte ox;
21710                                                ox = (byte) toLong(Math.cosh(ix));
21711                                                for (int j = 0; j < is; j++) {
21712                                                        oai8data[it.oIndex + j] = ox;
21713                                                }
21714                                        }
21715                                } else {
21716                                        while (it.hasNext()) {
21717                                                final long ix = it.aLong;
21718                                                byte ox;
21719                                                ox = (byte) toLong(Math.cosh(ix));
21720                                                for (int j = 0; j < is; j++) {
21721                                                        oai8data[it.oIndex + j] = ox;
21722                                                }
21723                                        }
21724                                }
21725                        } else {
21726                                if (it.isOutputDouble()) {
21727                                        while (it.hasNext()) {
21728                                                for (int j = 0; j < is; j++) {
21729                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21730                                                        byte ox;
21731                                                        ox = (byte) toLong(Math.cosh(ix));
21732                                                        oai8data[it.oIndex + j] = ox;
21733                                                }
21734                                        }
21735                                } else {
21736                                        while (it.hasNext()) {
21737                                                for (int j = 0; j < is; j++) {
21738                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21739                                                        byte ox;
21740                                                        ox = (byte) toLong(Math.cosh(ix));
21741                                                        oai8data[it.oIndex + j] = ox;
21742                                                }
21743                                        }
21744                                }
21745                        }
21746                        break;
21747                case Dataset.ARRAYINT16:
21748                        final short[] oai16data = ((CompoundShortDataset) result).getData();
21749                        if (is == 1) {
21750                                if (it.isOutputDouble()) {
21751                                        while (it.hasNext()) {
21752                                                final double ix = it.aDouble;
21753                                                short ox;
21754                                                ox = (short) toLong(Math.cosh(ix));
21755                                                oai16data[it.oIndex] = ox;
21756                                        }
21757                                } else {
21758                                        while (it.hasNext()) {
21759                                                final long ix = it.aLong;
21760                                                short ox;
21761                                                ox = (short) toLong(Math.cosh(ix));
21762                                                oai16data[it.oIndex] = ox;
21763                                        }
21764                                }
21765                        } else if (as == 1) {
21766                                if (it.isOutputDouble()) {
21767                                        while (it.hasNext()) {
21768                                                final double ix = it.aDouble;
21769                                                short ox;
21770                                                ox = (short) toLong(Math.cosh(ix));
21771                                                for (int j = 0; j < is; j++) {
21772                                                        oai16data[it.oIndex + j] = ox;
21773                                                }
21774                                        }
21775                                } else {
21776                                        while (it.hasNext()) {
21777                                                final long ix = it.aLong;
21778                                                short ox;
21779                                                ox = (short) toLong(Math.cosh(ix));
21780                                                for (int j = 0; j < is; j++) {
21781                                                        oai16data[it.oIndex + j] = ox;
21782                                                }
21783                                        }
21784                                }
21785                        } else {
21786                                if (it.isOutputDouble()) {
21787                                        while (it.hasNext()) {
21788                                                for (int j = 0; j < is; j++) {
21789                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21790                                                        short ox;
21791                                                        ox = (short) toLong(Math.cosh(ix));
21792                                                        oai16data[it.oIndex + j] = ox;
21793                                                }
21794                                        }
21795                                } else {
21796                                        while (it.hasNext()) {
21797                                                for (int j = 0; j < is; j++) {
21798                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21799                                                        short ox;
21800                                                        ox = (short) toLong(Math.cosh(ix));
21801                                                        oai16data[it.oIndex + j] = ox;
21802                                                }
21803                                        }
21804                                }
21805                        }
21806                        break;
21807                case Dataset.ARRAYINT64:
21808                        final long[] oai64data = ((CompoundLongDataset) result).getData();
21809                        if (is == 1) {
21810                                if (it.isOutputDouble()) {
21811                                        while (it.hasNext()) {
21812                                                final double ix = it.aDouble;
21813                                                long ox;
21814                                                ox = toLong(Math.cosh(ix));
21815                                                oai64data[it.oIndex] = ox;
21816                                        }
21817                                } else {
21818                                        while (it.hasNext()) {
21819                                                final long ix = it.aLong;
21820                                                long ox;
21821                                                ox = toLong(Math.cosh(ix));
21822                                                oai64data[it.oIndex] = ox;
21823                                        }
21824                                }
21825                        } else if (as == 1) {
21826                                if (it.isOutputDouble()) {
21827                                        while (it.hasNext()) {
21828                                                final double ix = it.aDouble;
21829                                                long ox;
21830                                                ox = toLong(Math.cosh(ix));
21831                                                for (int j = 0; j < is; j++) {
21832                                                        oai64data[it.oIndex + j] = ox;
21833                                                }
21834                                        }
21835                                } else {
21836                                        while (it.hasNext()) {
21837                                                final long ix = it.aLong;
21838                                                long ox;
21839                                                ox = toLong(Math.cosh(ix));
21840                                                for (int j = 0; j < is; j++) {
21841                                                        oai64data[it.oIndex + j] = ox;
21842                                                }
21843                                        }
21844                                }
21845                        } else {
21846                                if (it.isOutputDouble()) {
21847                                        while (it.hasNext()) {
21848                                                for (int j = 0; j < is; j++) {
21849                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21850                                                        long ox;
21851                                                        ox = toLong(Math.cosh(ix));
21852                                                        oai64data[it.oIndex + j] = ox;
21853                                                }
21854                                        }
21855                                } else {
21856                                        while (it.hasNext()) {
21857                                                for (int j = 0; j < is; j++) {
21858                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21859                                                        long ox;
21860                                                        ox = toLong(Math.cosh(ix));
21861                                                        oai64data[it.oIndex + j] = ox;
21862                                                }
21863                                        }
21864                                }
21865                        }
21866                        break;
21867                case Dataset.ARRAYINT32:
21868                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
21869                        if (is == 1) {
21870                                if (it.isOutputDouble()) {
21871                                        while (it.hasNext()) {
21872                                                final double ix = it.aDouble;
21873                                                int ox;
21874                                                ox = (int) toLong(Math.cosh(ix));
21875                                                oai32data[it.oIndex] = ox;
21876                                        }
21877                                } else {
21878                                        while (it.hasNext()) {
21879                                                final long ix = it.aLong;
21880                                                int ox;
21881                                                ox = (int) toLong(Math.cosh(ix));
21882                                                oai32data[it.oIndex] = ox;
21883                                        }
21884                                }
21885                        } else if (as == 1) {
21886                                if (it.isOutputDouble()) {
21887                                        while (it.hasNext()) {
21888                                                final double ix = it.aDouble;
21889                                                int ox;
21890                                                ox = (int) toLong(Math.cosh(ix));
21891                                                for (int j = 0; j < is; j++) {
21892                                                        oai32data[it.oIndex + j] = ox;
21893                                                }
21894                                        }
21895                                } else {
21896                                        while (it.hasNext()) {
21897                                                final long ix = it.aLong;
21898                                                int ox;
21899                                                ox = (int) toLong(Math.cosh(ix));
21900                                                for (int j = 0; j < is; j++) {
21901                                                        oai32data[it.oIndex + j] = ox;
21902                                                }
21903                                        }
21904                                }
21905                        } else {
21906                                if (it.isOutputDouble()) {
21907                                        while (it.hasNext()) {
21908                                                for (int j = 0; j < is; j++) {
21909                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
21910                                                        int ox;
21911                                                        ox = (int) toLong(Math.cosh(ix));
21912                                                        oai32data[it.oIndex + j] = ox;
21913                                                }
21914                                        }
21915                                } else {
21916                                        while (it.hasNext()) {
21917                                                for (int j = 0; j < is; j++) {
21918                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
21919                                                        int ox;
21920                                                        ox = (int) toLong(Math.cosh(ix));
21921                                                        oai32data[it.oIndex + j] = ox;
21922                                                }
21923                                        }
21924                                }
21925                        }
21926                        break;
21927                case Dataset.FLOAT32:
21928                        final float[] of32data = ((FloatDataset) result).getData();
21929                        if (it.isOutputDouble()) {
21930                                while (it.hasNext()) {
21931                                        final double ix = it.aDouble;
21932                                        float ox;
21933                                        ox = (float) (Math.cosh(ix));
21934                                        of32data[it.oIndex] = ox;
21935                                }
21936                        } else {
21937                                while (it.hasNext()) {
21938                                        final long ix = it.aLong;
21939                                        float ox;
21940                                        ox = (float) (Math.cosh(ix));
21941                                        of32data[it.oIndex] = ox;
21942                                }
21943                        }
21944                        break;
21945                case Dataset.FLOAT64:
21946                        final double[] of64data = ((DoubleDataset) result).getData();
21947                        if (it.isOutputDouble()) {
21948                                while (it.hasNext()) {
21949                                        final double ix = it.aDouble;
21950                                        double ox;
21951                                        ox = (Math.cosh(ix));
21952                                        of64data[it.oIndex] = ox;
21953                                }
21954                        } else {
21955                                while (it.hasNext()) {
21956                                        final long ix = it.aLong;
21957                                        double ox;
21958                                        ox = (Math.cosh(ix));
21959                                        of64data[it.oIndex] = ox;
21960                                }
21961                        }
21962                        break;
21963                case Dataset.ARRAYFLOAT32:
21964                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
21965                        if (is == 1) {
21966                                if (it.isOutputDouble()) {
21967                                        while (it.hasNext()) {
21968                                                final double ix = it.aDouble;
21969                                                float ox;
21970                                                ox = (float) (Math.cosh(ix));
21971                                                oaf32data[it.oIndex] = ox;
21972                                        }
21973                                } else {
21974                                        while (it.hasNext()) {
21975                                                final long ix = it.aLong;
21976                                                float ox;
21977                                                ox = (float) (Math.cosh(ix));
21978                                                oaf32data[it.oIndex] = ox;
21979                                        }
21980                                }
21981                        } else if (as == 1) {
21982                                if (it.isOutputDouble()) {
21983                                        while (it.hasNext()) {
21984                                                final double ix = it.aDouble;
21985                                                float ox;
21986                                                ox = (float) (Math.cosh(ix));
21987                                                for (int j = 0; j < is; j++) {
21988                                                        oaf32data[it.oIndex + j] = ox;
21989                                                }
21990                                        }
21991                                } else {
21992                                        while (it.hasNext()) {
21993                                                final long ix = it.aLong;
21994                                                float ox;
21995                                                ox = (float) (Math.cosh(ix));
21996                                                for (int j = 0; j < is; j++) {
21997                                                        oaf32data[it.oIndex + j] = ox;
21998                                                }
21999                                        }
22000                                }
22001                        } else {
22002                                if (it.isOutputDouble()) {
22003                                        while (it.hasNext()) {
22004                                                for (int j = 0; j < is; j++) {
22005                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22006                                                        float ox;
22007                                                        ox = (float) (Math.cosh(ix));
22008                                                        oaf32data[it.oIndex + j] = ox;
22009                                                }
22010                                        }
22011                                } else {
22012                                        while (it.hasNext()) {
22013                                                for (int j = 0; j < is; j++) {
22014                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22015                                                        float ox;
22016                                                        ox = (float) (Math.cosh(ix));
22017                                                        oaf32data[it.oIndex + j] = ox;
22018                                                }
22019                                        }
22020                                }
22021                        }
22022                        break;
22023                case Dataset.ARRAYFLOAT64:
22024                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
22025                        if (is == 1) {
22026                                if (it.isOutputDouble()) {
22027                                        while (it.hasNext()) {
22028                                                final double ix = it.aDouble;
22029                                                double ox;
22030                                                ox = (Math.cosh(ix));
22031                                                oaf64data[it.oIndex] = ox;
22032                                        }
22033                                } else {
22034                                        while (it.hasNext()) {
22035                                                final long ix = it.aLong;
22036                                                double ox;
22037                                                ox = (Math.cosh(ix));
22038                                                oaf64data[it.oIndex] = ox;
22039                                        }
22040                                }
22041                        } else if (as == 1) {
22042                                if (it.isOutputDouble()) {
22043                                        while (it.hasNext()) {
22044                                                final double ix = it.aDouble;
22045                                                double ox;
22046                                                ox = (Math.cosh(ix));
22047                                                for (int j = 0; j < is; j++) {
22048                                                        oaf64data[it.oIndex + j] = ox;
22049                                                }
22050                                        }
22051                                } else {
22052                                        while (it.hasNext()) {
22053                                                final long ix = it.aLong;
22054                                                double ox;
22055                                                ox = (Math.cosh(ix));
22056                                                for (int j = 0; j < is; j++) {
22057                                                        oaf64data[it.oIndex + j] = ox;
22058                                                }
22059                                        }
22060                                }
22061                        } else {
22062                                if (it.isOutputDouble()) {
22063                                        while (it.hasNext()) {
22064                                                for (int j = 0; j < is; j++) {
22065                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22066                                                        double ox;
22067                                                        ox = (Math.cosh(ix));
22068                                                        oaf64data[it.oIndex + j] = ox;
22069                                                }
22070                                        }
22071                                } else {
22072                                        while (it.hasNext()) {
22073                                                for (int j = 0; j < is; j++) {
22074                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22075                                                        double ox;
22076                                                        ox = (Math.cosh(ix));
22077                                                        oaf64data[it.oIndex + j] = ox;
22078                                                }
22079                                        }
22080                                }
22081                        }
22082                        break;
22083                case Dataset.COMPLEX64:
22084                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
22085                        if (!da.isComplex()) {
22086                                if (it.isOutputDouble()) {
22087                                        final double iy = 0;
22088                                        while (it.hasNext()) {
22089                                                final double ix = it.aDouble;
22090                                                float ox;
22091                                                float oy;
22092                                                ox = (float) (Math.cosh(ix)*Math.cos(iy));
22093                                                oy = (float) (Math.sinh(ix)*Math.sin(iy));
22094                                                oc64data[it.oIndex] = ox;
22095                                                oc64data[it.oIndex + 1] = oy;
22096                                        }
22097                                } else {
22098                                        final long iy = 0;
22099                                        while (it.hasNext()) {
22100                                                final long ix = it.aLong;
22101                                                float ox;
22102                                                float oy;
22103                                                ox = (float) toLong(Math.cosh(ix)*Math.cos(iy));
22104                                                oy = (float) toLong(Math.sinh(ix)*Math.sin(iy));
22105                                                oc64data[it.oIndex] = ox;
22106                                                oc64data[it.oIndex + 1] = oy;
22107                                        }
22108                                }
22109                        } else {
22110                                while (it.hasNext()) {
22111                                        final double ix = it.aDouble;
22112                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
22113                                        float ox;
22114                                        float oy;
22115                                        ox = (float) (Math.cosh(ix)*Math.cos(iy));
22116                                        oy = (float) (Math.sinh(ix)*Math.sin(iy));
22117                                        oc64data[it.oIndex] = ox;
22118                                        oc64data[it.oIndex + 1] = oy;
22119                                }
22120                        }
22121                        break;
22122                case Dataset.COMPLEX128:
22123                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
22124                        if (!da.isComplex()) {
22125                                if (it.isOutputDouble()) {
22126                                        final double iy = 0;
22127                                        while (it.hasNext()) {
22128                                                final double ix = it.aDouble;
22129                                                double ox;
22130                                                double oy;
22131                                                ox = (Math.cosh(ix)*Math.cos(iy));
22132                                                oy = (Math.sinh(ix)*Math.sin(iy));
22133                                                oc128data[it.oIndex] = ox;
22134                                                oc128data[it.oIndex + 1] = oy;
22135                                        }
22136                                } else {
22137                                        final long iy = 0;
22138                                        while (it.hasNext()) {
22139                                                final long ix = it.aLong;
22140                                                double ox;
22141                                                double oy;
22142                                                ox = (double) (Math.cosh(ix)*Math.cos(iy));
22143                                                oy = (double) (Math.sinh(ix)*Math.sin(iy));
22144                                                oc128data[it.oIndex] = ox;
22145                                                oc128data[it.oIndex + 1] = oy;
22146                                        }
22147                                }
22148                        } else {
22149                                while (it.hasNext()) {
22150                                        final double ix = it.aDouble;
22151                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
22152                                        double ox;
22153                                        double oy;
22154                                        ox = (Math.cosh(ix)*Math.cos(iy));
22155                                        oy = (Math.sinh(ix)*Math.sin(iy));
22156                                        oc128data[it.oIndex] = ox;
22157                                        oc128data[it.oIndex + 1] = oy;
22158                                }
22159                        }
22160                        break;
22161                default:
22162                        throw new IllegalArgumentException("cosh supports integer, compound integer, real, compound real, complex datasets only");
22163                }
22164
22165                addFunctionName(result, "cosh");
22166                return result;
22167        }
22168
22169        /**
22170         * tanh - evaluate the tangent hyperbolic function on each element of the dataset
22171         * @param a single operand
22172         * @return dataset
22173         */
22174        public static Dataset tanh(final Object a) {
22175                return tanh(a, null);
22176        }
22177
22178        /**
22179         * tanh - evaluate the tangent hyperbolic function on each element of the dataset
22180         * @param a single operand
22181         * @param o output can be null - in which case, a new dataset is created
22182         * @return dataset
22183         */
22184        public static Dataset tanh(final Object a, final Dataset o) {
22185                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
22186                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
22187                final Dataset result = it.getOutput();
22188                if (!result.isComplex()) {
22189                        if (da.isComplex()) {
22190                                da = da.getRealView();
22191                                it = new SingleInputBroadcastIterator(da, result, true);
22192                        }
22193                }
22194                final int is = result.getElementsPerItem();
22195                final int as = da.getElementsPerItem();
22196                final int dt = result.getDType();
22197
22198                switch(dt) {
22199                case Dataset.INT8:
22200                        final byte[] oi8data = ((ByteDataset) result).getData();
22201                        if (it.isOutputDouble()) {
22202                                while (it.hasNext()) {
22203                                        final double ix = it.aDouble;
22204                                        byte ox;
22205                                        ox = (byte) toLong(Math.tanh(ix));
22206                                        oi8data[it.oIndex] = ox;
22207                                }
22208                        } else {
22209                                while (it.hasNext()) {
22210                                        final long ix = it.aLong;
22211                                        byte ox;
22212                                        ox = (byte) toLong(Math.tanh(ix));
22213                                        oi8data[it.oIndex] = ox;
22214                                }
22215                        }
22216                        break;
22217                case Dataset.INT16:
22218                        final short[] oi16data = ((ShortDataset) result).getData();
22219                        if (it.isOutputDouble()) {
22220                                while (it.hasNext()) {
22221                                        final double ix = it.aDouble;
22222                                        short ox;
22223                                        ox = (short) toLong(Math.tanh(ix));
22224                                        oi16data[it.oIndex] = ox;
22225                                }
22226                        } else {
22227                                while (it.hasNext()) {
22228                                        final long ix = it.aLong;
22229                                        short ox;
22230                                        ox = (short) toLong(Math.tanh(ix));
22231                                        oi16data[it.oIndex] = ox;
22232                                }
22233                        }
22234                        break;
22235                case Dataset.INT64:
22236                        final long[] oi64data = ((LongDataset) result).getData();
22237                        if (it.isOutputDouble()) {
22238                                while (it.hasNext()) {
22239                                        final double ix = it.aDouble;
22240                                        long ox;
22241                                        ox = toLong(Math.tanh(ix));
22242                                        oi64data[it.oIndex] = ox;
22243                                }
22244                        } else {
22245                                while (it.hasNext()) {
22246                                        final long ix = it.aLong;
22247                                        long ox;
22248                                        ox = toLong(Math.tanh(ix));
22249                                        oi64data[it.oIndex] = ox;
22250                                }
22251                        }
22252                        break;
22253                case Dataset.INT32:
22254                        final int[] oi32data = ((IntegerDataset) result).getData();
22255                        if (it.isOutputDouble()) {
22256                                while (it.hasNext()) {
22257                                        final double ix = it.aDouble;
22258                                        int ox;
22259                                        ox = (int) toLong(Math.tanh(ix));
22260                                        oi32data[it.oIndex] = ox;
22261                                }
22262                        } else {
22263                                while (it.hasNext()) {
22264                                        final long ix = it.aLong;
22265                                        int ox;
22266                                        ox = (int) toLong(Math.tanh(ix));
22267                                        oi32data[it.oIndex] = ox;
22268                                }
22269                        }
22270                        break;
22271                case Dataset.ARRAYINT8:
22272                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
22273                        if (is == 1) {
22274                                if (it.isOutputDouble()) {
22275                                        while (it.hasNext()) {
22276                                                final double ix = it.aDouble;
22277                                                byte ox;
22278                                                ox = (byte) toLong(Math.tanh(ix));
22279                                                oai8data[it.oIndex] = ox;
22280                                        }
22281                                } else {
22282                                        while (it.hasNext()) {
22283                                                final long ix = it.aLong;
22284                                                byte ox;
22285                                                ox = (byte) toLong(Math.tanh(ix));
22286                                                oai8data[it.oIndex] = ox;
22287                                        }
22288                                }
22289                        } else if (as == 1) {
22290                                if (it.isOutputDouble()) {
22291                                        while (it.hasNext()) {
22292                                                final double ix = it.aDouble;
22293                                                byte ox;
22294                                                ox = (byte) toLong(Math.tanh(ix));
22295                                                for (int j = 0; j < is; j++) {
22296                                                        oai8data[it.oIndex + j] = ox;
22297                                                }
22298                                        }
22299                                } else {
22300                                        while (it.hasNext()) {
22301                                                final long ix = it.aLong;
22302                                                byte ox;
22303                                                ox = (byte) toLong(Math.tanh(ix));
22304                                                for (int j = 0; j < is; j++) {
22305                                                        oai8data[it.oIndex + j] = ox;
22306                                                }
22307                                        }
22308                                }
22309                        } else {
22310                                if (it.isOutputDouble()) {
22311                                        while (it.hasNext()) {
22312                                                for (int j = 0; j < is; j++) {
22313                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22314                                                        byte ox;
22315                                                        ox = (byte) toLong(Math.tanh(ix));
22316                                                        oai8data[it.oIndex + j] = ox;
22317                                                }
22318                                        }
22319                                } else {
22320                                        while (it.hasNext()) {
22321                                                for (int j = 0; j < is; j++) {
22322                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22323                                                        byte ox;
22324                                                        ox = (byte) toLong(Math.tanh(ix));
22325                                                        oai8data[it.oIndex + j] = ox;
22326                                                }
22327                                        }
22328                                }
22329                        }
22330                        break;
22331                case Dataset.ARRAYINT16:
22332                        final short[] oai16data = ((CompoundShortDataset) result).getData();
22333                        if (is == 1) {
22334                                if (it.isOutputDouble()) {
22335                                        while (it.hasNext()) {
22336                                                final double ix = it.aDouble;
22337                                                short ox;
22338                                                ox = (short) toLong(Math.tanh(ix));
22339                                                oai16data[it.oIndex] = ox;
22340                                        }
22341                                } else {
22342                                        while (it.hasNext()) {
22343                                                final long ix = it.aLong;
22344                                                short ox;
22345                                                ox = (short) toLong(Math.tanh(ix));
22346                                                oai16data[it.oIndex] = ox;
22347                                        }
22348                                }
22349                        } else if (as == 1) {
22350                                if (it.isOutputDouble()) {
22351                                        while (it.hasNext()) {
22352                                                final double ix = it.aDouble;
22353                                                short ox;
22354                                                ox = (short) toLong(Math.tanh(ix));
22355                                                for (int j = 0; j < is; j++) {
22356                                                        oai16data[it.oIndex + j] = ox;
22357                                                }
22358                                        }
22359                                } else {
22360                                        while (it.hasNext()) {
22361                                                final long ix = it.aLong;
22362                                                short ox;
22363                                                ox = (short) toLong(Math.tanh(ix));
22364                                                for (int j = 0; j < is; j++) {
22365                                                        oai16data[it.oIndex + j] = ox;
22366                                                }
22367                                        }
22368                                }
22369                        } else {
22370                                if (it.isOutputDouble()) {
22371                                        while (it.hasNext()) {
22372                                                for (int j = 0; j < is; j++) {
22373                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22374                                                        short ox;
22375                                                        ox = (short) toLong(Math.tanh(ix));
22376                                                        oai16data[it.oIndex + j] = ox;
22377                                                }
22378                                        }
22379                                } else {
22380                                        while (it.hasNext()) {
22381                                                for (int j = 0; j < is; j++) {
22382                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22383                                                        short ox;
22384                                                        ox = (short) toLong(Math.tanh(ix));
22385                                                        oai16data[it.oIndex + j] = ox;
22386                                                }
22387                                        }
22388                                }
22389                        }
22390                        break;
22391                case Dataset.ARRAYINT64:
22392                        final long[] oai64data = ((CompoundLongDataset) result).getData();
22393                        if (is == 1) {
22394                                if (it.isOutputDouble()) {
22395                                        while (it.hasNext()) {
22396                                                final double ix = it.aDouble;
22397                                                long ox;
22398                                                ox = toLong(Math.tanh(ix));
22399                                                oai64data[it.oIndex] = ox;
22400                                        }
22401                                } else {
22402                                        while (it.hasNext()) {
22403                                                final long ix = it.aLong;
22404                                                long ox;
22405                                                ox = toLong(Math.tanh(ix));
22406                                                oai64data[it.oIndex] = ox;
22407                                        }
22408                                }
22409                        } else if (as == 1) {
22410                                if (it.isOutputDouble()) {
22411                                        while (it.hasNext()) {
22412                                                final double ix = it.aDouble;
22413                                                long ox;
22414                                                ox = toLong(Math.tanh(ix));
22415                                                for (int j = 0; j < is; j++) {
22416                                                        oai64data[it.oIndex + j] = ox;
22417                                                }
22418                                        }
22419                                } else {
22420                                        while (it.hasNext()) {
22421                                                final long ix = it.aLong;
22422                                                long ox;
22423                                                ox = toLong(Math.tanh(ix));
22424                                                for (int j = 0; j < is; j++) {
22425                                                        oai64data[it.oIndex + j] = ox;
22426                                                }
22427                                        }
22428                                }
22429                        } else {
22430                                if (it.isOutputDouble()) {
22431                                        while (it.hasNext()) {
22432                                                for (int j = 0; j < is; j++) {
22433                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22434                                                        long ox;
22435                                                        ox = toLong(Math.tanh(ix));
22436                                                        oai64data[it.oIndex + j] = ox;
22437                                                }
22438                                        }
22439                                } else {
22440                                        while (it.hasNext()) {
22441                                                for (int j = 0; j < is; j++) {
22442                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22443                                                        long ox;
22444                                                        ox = toLong(Math.tanh(ix));
22445                                                        oai64data[it.oIndex + j] = ox;
22446                                                }
22447                                        }
22448                                }
22449                        }
22450                        break;
22451                case Dataset.ARRAYINT32:
22452                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
22453                        if (is == 1) {
22454                                if (it.isOutputDouble()) {
22455                                        while (it.hasNext()) {
22456                                                final double ix = it.aDouble;
22457                                                int ox;
22458                                                ox = (int) toLong(Math.tanh(ix));
22459                                                oai32data[it.oIndex] = ox;
22460                                        }
22461                                } else {
22462                                        while (it.hasNext()) {
22463                                                final long ix = it.aLong;
22464                                                int ox;
22465                                                ox = (int) toLong(Math.tanh(ix));
22466                                                oai32data[it.oIndex] = ox;
22467                                        }
22468                                }
22469                        } else if (as == 1) {
22470                                if (it.isOutputDouble()) {
22471                                        while (it.hasNext()) {
22472                                                final double ix = it.aDouble;
22473                                                int ox;
22474                                                ox = (int) toLong(Math.tanh(ix));
22475                                                for (int j = 0; j < is; j++) {
22476                                                        oai32data[it.oIndex + j] = ox;
22477                                                }
22478                                        }
22479                                } else {
22480                                        while (it.hasNext()) {
22481                                                final long ix = it.aLong;
22482                                                int ox;
22483                                                ox = (int) toLong(Math.tanh(ix));
22484                                                for (int j = 0; j < is; j++) {
22485                                                        oai32data[it.oIndex + j] = ox;
22486                                                }
22487                                        }
22488                                }
22489                        } else {
22490                                if (it.isOutputDouble()) {
22491                                        while (it.hasNext()) {
22492                                                for (int j = 0; j < is; j++) {
22493                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22494                                                        int ox;
22495                                                        ox = (int) toLong(Math.tanh(ix));
22496                                                        oai32data[it.oIndex + j] = ox;
22497                                                }
22498                                        }
22499                                } else {
22500                                        while (it.hasNext()) {
22501                                                for (int j = 0; j < is; j++) {
22502                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22503                                                        int ox;
22504                                                        ox = (int) toLong(Math.tanh(ix));
22505                                                        oai32data[it.oIndex + j] = ox;
22506                                                }
22507                                        }
22508                                }
22509                        }
22510                        break;
22511                case Dataset.FLOAT32:
22512                        final float[] of32data = ((FloatDataset) result).getData();
22513                        if (it.isOutputDouble()) {
22514                                while (it.hasNext()) {
22515                                        final double ix = it.aDouble;
22516                                        float ox;
22517                                        ox = (float) (Math.tanh(ix));
22518                                        of32data[it.oIndex] = ox;
22519                                }
22520                        } else {
22521                                while (it.hasNext()) {
22522                                        final long ix = it.aLong;
22523                                        float ox;
22524                                        ox = (float) (Math.tanh(ix));
22525                                        of32data[it.oIndex] = ox;
22526                                }
22527                        }
22528                        break;
22529                case Dataset.FLOAT64:
22530                        final double[] of64data = ((DoubleDataset) result).getData();
22531                        if (it.isOutputDouble()) {
22532                                while (it.hasNext()) {
22533                                        final double ix = it.aDouble;
22534                                        double ox;
22535                                        ox = (Math.tanh(ix));
22536                                        of64data[it.oIndex] = ox;
22537                                }
22538                        } else {
22539                                while (it.hasNext()) {
22540                                        final long ix = it.aLong;
22541                                        double ox;
22542                                        ox = (Math.tanh(ix));
22543                                        of64data[it.oIndex] = ox;
22544                                }
22545                        }
22546                        break;
22547                case Dataset.ARRAYFLOAT32:
22548                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
22549                        if (is == 1) {
22550                                if (it.isOutputDouble()) {
22551                                        while (it.hasNext()) {
22552                                                final double ix = it.aDouble;
22553                                                float ox;
22554                                                ox = (float) (Math.tanh(ix));
22555                                                oaf32data[it.oIndex] = ox;
22556                                        }
22557                                } else {
22558                                        while (it.hasNext()) {
22559                                                final long ix = it.aLong;
22560                                                float ox;
22561                                                ox = (float) (Math.tanh(ix));
22562                                                oaf32data[it.oIndex] = ox;
22563                                        }
22564                                }
22565                        } else if (as == 1) {
22566                                if (it.isOutputDouble()) {
22567                                        while (it.hasNext()) {
22568                                                final double ix = it.aDouble;
22569                                                float ox;
22570                                                ox = (float) (Math.tanh(ix));
22571                                                for (int j = 0; j < is; j++) {
22572                                                        oaf32data[it.oIndex + j] = ox;
22573                                                }
22574                                        }
22575                                } else {
22576                                        while (it.hasNext()) {
22577                                                final long ix = it.aLong;
22578                                                float ox;
22579                                                ox = (float) (Math.tanh(ix));
22580                                                for (int j = 0; j < is; j++) {
22581                                                        oaf32data[it.oIndex + j] = ox;
22582                                                }
22583                                        }
22584                                }
22585                        } else {
22586                                if (it.isOutputDouble()) {
22587                                        while (it.hasNext()) {
22588                                                for (int j = 0; j < is; j++) {
22589                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22590                                                        float ox;
22591                                                        ox = (float) (Math.tanh(ix));
22592                                                        oaf32data[it.oIndex + j] = ox;
22593                                                }
22594                                        }
22595                                } else {
22596                                        while (it.hasNext()) {
22597                                                for (int j = 0; j < is; j++) {
22598                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22599                                                        float ox;
22600                                                        ox = (float) (Math.tanh(ix));
22601                                                        oaf32data[it.oIndex + j] = ox;
22602                                                }
22603                                        }
22604                                }
22605                        }
22606                        break;
22607                case Dataset.ARRAYFLOAT64:
22608                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
22609                        if (is == 1) {
22610                                if (it.isOutputDouble()) {
22611                                        while (it.hasNext()) {
22612                                                final double ix = it.aDouble;
22613                                                double ox;
22614                                                ox = (Math.tanh(ix));
22615                                                oaf64data[it.oIndex] = ox;
22616                                        }
22617                                } else {
22618                                        while (it.hasNext()) {
22619                                                final long ix = it.aLong;
22620                                                double ox;
22621                                                ox = (Math.tanh(ix));
22622                                                oaf64data[it.oIndex] = ox;
22623                                        }
22624                                }
22625                        } else if (as == 1) {
22626                                if (it.isOutputDouble()) {
22627                                        while (it.hasNext()) {
22628                                                final double ix = it.aDouble;
22629                                                double ox;
22630                                                ox = (Math.tanh(ix));
22631                                                for (int j = 0; j < is; j++) {
22632                                                        oaf64data[it.oIndex + j] = ox;
22633                                                }
22634                                        }
22635                                } else {
22636                                        while (it.hasNext()) {
22637                                                final long ix = it.aLong;
22638                                                double ox;
22639                                                ox = (Math.tanh(ix));
22640                                                for (int j = 0; j < is; j++) {
22641                                                        oaf64data[it.oIndex + j] = ox;
22642                                                }
22643                                        }
22644                                }
22645                        } else {
22646                                if (it.isOutputDouble()) {
22647                                        while (it.hasNext()) {
22648                                                for (int j = 0; j < is; j++) {
22649                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22650                                                        double ox;
22651                                                        ox = (Math.tanh(ix));
22652                                                        oaf64data[it.oIndex + j] = ox;
22653                                                }
22654                                        }
22655                                } else {
22656                                        while (it.hasNext()) {
22657                                                for (int j = 0; j < is; j++) {
22658                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22659                                                        double ox;
22660                                                        ox = (Math.tanh(ix));
22661                                                        oaf64data[it.oIndex + j] = ox;
22662                                                }
22663                                        }
22664                                }
22665                        }
22666                        break;
22667                case Dataset.COMPLEX64:
22668                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
22669                        if (!da.isComplex()) {
22670                                if (it.isOutputDouble()) {
22671                                        final double iy = 0;
22672                                        while (it.hasNext()) {
22673                                                final double ix = it.aDouble;
22674                                                float tx;
22675                                                float ty;
22676                                                float tf;
22677                                                float ox;
22678                                                float oy;
22679                                                tx = (float) (2.*ix);
22680                                                ty = (float) (2.*iy);
22681                                                tf = (float) (1./(Math.cos(tx)+Math.cosh(ty)));
22682                                                ox = (float) (tf*Math.sinh(tx));
22683                                                oy = (float) (tf*Math.sin(ty));
22684                                                oc64data[it.oIndex] = ox;
22685                                                oc64data[it.oIndex + 1] = oy;
22686                                        }
22687                                } else {
22688                                        final long iy = 0;
22689                                        while (it.hasNext()) {
22690                                                final long ix = it.aLong;
22691                                                float tx;
22692                                                float ty;
22693                                                float tf;
22694                                                float ox;
22695                                                float oy;
22696                                                tx = (float) toLong(2.*ix);
22697                                                ty = (float) toLong(2.*iy);
22698                                                tf = (float) toLong(1./(Math.cos(tx)+Math.cosh(ty)));
22699                                                ox = (float) toLong(tf*Math.sinh(tx));
22700                                                oy = (float) toLong(tf*Math.sin(ty));
22701                                                oc64data[it.oIndex] = ox;
22702                                                oc64data[it.oIndex + 1] = oy;
22703                                        }
22704                                }
22705                        } else {
22706                                while (it.hasNext()) {
22707                                        final double ix = it.aDouble;
22708                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
22709                                        float tx;
22710                                        float ty;
22711                                        float tf;
22712                                        float ox;
22713                                        float oy;
22714                                        tx = (float) (2.*ix);
22715                                        ty = (float) (2.*iy);
22716                                        tf = (float) (1./(Math.cos(tx)+Math.cosh(ty)));
22717                                        ox = (float) (tf*Math.sinh(tx));
22718                                        oy = (float) (tf*Math.sin(ty));
22719                                        oc64data[it.oIndex] = ox;
22720                                        oc64data[it.oIndex + 1] = oy;
22721                                }
22722                        }
22723                        break;
22724                case Dataset.COMPLEX128:
22725                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
22726                        if (!da.isComplex()) {
22727                                if (it.isOutputDouble()) {
22728                                        final double iy = 0;
22729                                        while (it.hasNext()) {
22730                                                final double ix = it.aDouble;
22731                                                double tx;
22732                                                double ty;
22733                                                double tf;
22734                                                double ox;
22735                                                double oy;
22736                                                tx = (2.*ix);
22737                                                ty = (2.*iy);
22738                                                tf = (1./(Math.cos(tx)+Math.cosh(ty)));
22739                                                ox = (tf*Math.sinh(tx));
22740                                                oy = (tf*Math.sin(ty));
22741                                                oc128data[it.oIndex] = ox;
22742                                                oc128data[it.oIndex + 1] = oy;
22743                                        }
22744                                } else {
22745                                        final long iy = 0;
22746                                        while (it.hasNext()) {
22747                                                final long ix = it.aLong;
22748                                                double tx;
22749                                                double ty;
22750                                                double tf;
22751                                                double ox;
22752                                                double oy;
22753                                                tx = (2.*ix);
22754                                                ty = (2.*iy);
22755                                                tf = (double) (1./(Math.cos(tx)+Math.cosh(ty)));
22756                                                ox = (double) (tf*Math.sinh(tx));
22757                                                oy = (double) (tf*Math.sin(ty));
22758                                                oc128data[it.oIndex] = ox;
22759                                                oc128data[it.oIndex + 1] = oy;
22760                                        }
22761                                }
22762                        } else {
22763                                while (it.hasNext()) {
22764                                        final double ix = it.aDouble;
22765                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
22766                                        double tx;
22767                                        double ty;
22768                                        double tf;
22769                                        double ox;
22770                                        double oy;
22771                                        tx = (2.*ix);
22772                                        ty = (2.*iy);
22773                                        tf = (1./(Math.cos(tx)+Math.cosh(ty)));
22774                                        ox = (tf*Math.sinh(tx));
22775                                        oy = (tf*Math.sin(ty));
22776                                        oc128data[it.oIndex] = ox;
22777                                        oc128data[it.oIndex + 1] = oy;
22778                                }
22779                        }
22780                        break;
22781                default:
22782                        throw new IllegalArgumentException("tanh supports integer, compound integer, real, compound real, complex datasets only");
22783                }
22784
22785                addFunctionName(result, "tanh");
22786                return result;
22787        }
22788
22789        /**
22790         * arcsinh - evaluate the inverse hyperbolic sine function on each element of the dataset
22791         * @param a single operand
22792         * @return dataset
22793         */
22794        public static Dataset arcsinh(final Object a) {
22795                return arcsinh(a, null);
22796        }
22797
22798        /**
22799         * arcsinh - evaluate the inverse hyperbolic sine function on each element of the dataset
22800         * @param a single operand
22801         * @param o output can be null - in which case, a new dataset is created
22802         * @return dataset
22803         */
22804        public static Dataset arcsinh(final Object a, final Dataset o) {
22805                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
22806                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
22807                final Dataset result = it.getOutput();
22808                if (!result.isComplex()) {
22809                        if (da.isComplex()) {
22810                                da = da.getRealView();
22811                                it = new SingleInputBroadcastIterator(da, result, true);
22812                        }
22813                }
22814                final int is = result.getElementsPerItem();
22815                final int as = da.getElementsPerItem();
22816                final int dt = result.getDType();
22817
22818                switch(dt) {
22819                case Dataset.INT8:
22820                        final byte[] oi8data = ((ByteDataset) result).getData();
22821                        if (it.isOutputDouble()) {
22822                                while (it.hasNext()) {
22823                                        final double ix = it.aDouble;
22824                                        byte ox;
22825                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22826                                        oi8data[it.oIndex] = ox;
22827                                }
22828                        } else {
22829                                while (it.hasNext()) {
22830                                        final long ix = it.aLong;
22831                                        byte ox;
22832                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22833                                        oi8data[it.oIndex] = ox;
22834                                }
22835                        }
22836                        break;
22837                case Dataset.INT16:
22838                        final short[] oi16data = ((ShortDataset) result).getData();
22839                        if (it.isOutputDouble()) {
22840                                while (it.hasNext()) {
22841                                        final double ix = it.aDouble;
22842                                        short ox;
22843                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22844                                        oi16data[it.oIndex] = ox;
22845                                }
22846                        } else {
22847                                while (it.hasNext()) {
22848                                        final long ix = it.aLong;
22849                                        short ox;
22850                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22851                                        oi16data[it.oIndex] = ox;
22852                                }
22853                        }
22854                        break;
22855                case Dataset.INT64:
22856                        final long[] oi64data = ((LongDataset) result).getData();
22857                        if (it.isOutputDouble()) {
22858                                while (it.hasNext()) {
22859                                        final double ix = it.aDouble;
22860                                        long ox;
22861                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22862                                        oi64data[it.oIndex] = ox;
22863                                }
22864                        } else {
22865                                while (it.hasNext()) {
22866                                        final long ix = it.aLong;
22867                                        long ox;
22868                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22869                                        oi64data[it.oIndex] = ox;
22870                                }
22871                        }
22872                        break;
22873                case Dataset.INT32:
22874                        final int[] oi32data = ((IntegerDataset) result).getData();
22875                        if (it.isOutputDouble()) {
22876                                while (it.hasNext()) {
22877                                        final double ix = it.aDouble;
22878                                        int ox;
22879                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22880                                        oi32data[it.oIndex] = ox;
22881                                }
22882                        } else {
22883                                while (it.hasNext()) {
22884                                        final long ix = it.aLong;
22885                                        int ox;
22886                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22887                                        oi32data[it.oIndex] = ox;
22888                                }
22889                        }
22890                        break;
22891                case Dataset.ARRAYINT8:
22892                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
22893                        if (is == 1) {
22894                                if (it.isOutputDouble()) {
22895                                        while (it.hasNext()) {
22896                                                final double ix = it.aDouble;
22897                                                byte ox;
22898                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22899                                                oai8data[it.oIndex] = ox;
22900                                        }
22901                                } else {
22902                                        while (it.hasNext()) {
22903                                                final long ix = it.aLong;
22904                                                byte ox;
22905                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22906                                                oai8data[it.oIndex] = ox;
22907                                        }
22908                                }
22909                        } else if (as == 1) {
22910                                if (it.isOutputDouble()) {
22911                                        while (it.hasNext()) {
22912                                                final double ix = it.aDouble;
22913                                                byte ox;
22914                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22915                                                for (int j = 0; j < is; j++) {
22916                                                        oai8data[it.oIndex + j] = ox;
22917                                                }
22918                                        }
22919                                } else {
22920                                        while (it.hasNext()) {
22921                                                final long ix = it.aLong;
22922                                                byte ox;
22923                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22924                                                for (int j = 0; j < is; j++) {
22925                                                        oai8data[it.oIndex + j] = ox;
22926                                                }
22927                                        }
22928                                }
22929                        } else {
22930                                if (it.isOutputDouble()) {
22931                                        while (it.hasNext()) {
22932                                                for (int j = 0; j < is; j++) {
22933                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22934                                                        byte ox;
22935                                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22936                                                        oai8data[it.oIndex + j] = ox;
22937                                                }
22938                                        }
22939                                } else {
22940                                        while (it.hasNext()) {
22941                                                for (int j = 0; j < is; j++) {
22942                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
22943                                                        byte ox;
22944                                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22945                                                        oai8data[it.oIndex + j] = ox;
22946                                                }
22947                                        }
22948                                }
22949                        }
22950                        break;
22951                case Dataset.ARRAYINT16:
22952                        final short[] oai16data = ((CompoundShortDataset) result).getData();
22953                        if (is == 1) {
22954                                if (it.isOutputDouble()) {
22955                                        while (it.hasNext()) {
22956                                                final double ix = it.aDouble;
22957                                                short ox;
22958                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22959                                                oai16data[it.oIndex] = ox;
22960                                        }
22961                                } else {
22962                                        while (it.hasNext()) {
22963                                                final long ix = it.aLong;
22964                                                short ox;
22965                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22966                                                oai16data[it.oIndex] = ox;
22967                                        }
22968                                }
22969                        } else if (as == 1) {
22970                                if (it.isOutputDouble()) {
22971                                        while (it.hasNext()) {
22972                                                final double ix = it.aDouble;
22973                                                short ox;
22974                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22975                                                for (int j = 0; j < is; j++) {
22976                                                        oai16data[it.oIndex + j] = ox;
22977                                                }
22978                                        }
22979                                } else {
22980                                        while (it.hasNext()) {
22981                                                final long ix = it.aLong;
22982                                                short ox;
22983                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22984                                                for (int j = 0; j < is; j++) {
22985                                                        oai16data[it.oIndex + j] = ox;
22986                                                }
22987                                        }
22988                                }
22989                        } else {
22990                                if (it.isOutputDouble()) {
22991                                        while (it.hasNext()) {
22992                                                for (int j = 0; j < is; j++) {
22993                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
22994                                                        short ox;
22995                                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
22996                                                        oai16data[it.oIndex + j] = ox;
22997                                                }
22998                                        }
22999                                } else {
23000                                        while (it.hasNext()) {
23001                                                for (int j = 0; j < is; j++) {
23002                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23003                                                        short ox;
23004                                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23005                                                        oai16data[it.oIndex + j] = ox;
23006                                                }
23007                                        }
23008                                }
23009                        }
23010                        break;
23011                case Dataset.ARRAYINT64:
23012                        final long[] oai64data = ((CompoundLongDataset) result).getData();
23013                        if (is == 1) {
23014                                if (it.isOutputDouble()) {
23015                                        while (it.hasNext()) {
23016                                                final double ix = it.aDouble;
23017                                                long ox;
23018                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23019                                                oai64data[it.oIndex] = ox;
23020                                        }
23021                                } else {
23022                                        while (it.hasNext()) {
23023                                                final long ix = it.aLong;
23024                                                long ox;
23025                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23026                                                oai64data[it.oIndex] = ox;
23027                                        }
23028                                }
23029                        } else if (as == 1) {
23030                                if (it.isOutputDouble()) {
23031                                        while (it.hasNext()) {
23032                                                final double ix = it.aDouble;
23033                                                long ox;
23034                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23035                                                for (int j = 0; j < is; j++) {
23036                                                        oai64data[it.oIndex + j] = ox;
23037                                                }
23038                                        }
23039                                } else {
23040                                        while (it.hasNext()) {
23041                                                final long ix = it.aLong;
23042                                                long ox;
23043                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23044                                                for (int j = 0; j < is; j++) {
23045                                                        oai64data[it.oIndex + j] = ox;
23046                                                }
23047                                        }
23048                                }
23049                        } else {
23050                                if (it.isOutputDouble()) {
23051                                        while (it.hasNext()) {
23052                                                for (int j = 0; j < is; j++) {
23053                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23054                                                        long ox;
23055                                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23056                                                        oai64data[it.oIndex + j] = ox;
23057                                                }
23058                                        }
23059                                } else {
23060                                        while (it.hasNext()) {
23061                                                for (int j = 0; j < is; j++) {
23062                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23063                                                        long ox;
23064                                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23065                                                        oai64data[it.oIndex + j] = ox;
23066                                                }
23067                                        }
23068                                }
23069                        }
23070                        break;
23071                case Dataset.ARRAYINT32:
23072                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
23073                        if (is == 1) {
23074                                if (it.isOutputDouble()) {
23075                                        while (it.hasNext()) {
23076                                                final double ix = it.aDouble;
23077                                                int ox;
23078                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23079                                                oai32data[it.oIndex] = ox;
23080                                        }
23081                                } else {
23082                                        while (it.hasNext()) {
23083                                                final long ix = it.aLong;
23084                                                int ox;
23085                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23086                                                oai32data[it.oIndex] = ox;
23087                                        }
23088                                }
23089                        } else if (as == 1) {
23090                                if (it.isOutputDouble()) {
23091                                        while (it.hasNext()) {
23092                                                final double ix = it.aDouble;
23093                                                int ox;
23094                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23095                                                for (int j = 0; j < is; j++) {
23096                                                        oai32data[it.oIndex + j] = ox;
23097                                                }
23098                                        }
23099                                } else {
23100                                        while (it.hasNext()) {
23101                                                final long ix = it.aLong;
23102                                                int ox;
23103                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23104                                                for (int j = 0; j < is; j++) {
23105                                                        oai32data[it.oIndex + j] = ox;
23106                                                }
23107                                        }
23108                                }
23109                        } else {
23110                                if (it.isOutputDouble()) {
23111                                        while (it.hasNext()) {
23112                                                for (int j = 0; j < is; j++) {
23113                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23114                                                        int ox;
23115                                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23116                                                        oai32data[it.oIndex + j] = ox;
23117                                                }
23118                                        }
23119                                } else {
23120                                        while (it.hasNext()) {
23121                                                for (int j = 0; j < is; j++) {
23122                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23123                                                        int ox;
23124                                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
23125                                                        oai32data[it.oIndex + j] = ox;
23126                                                }
23127                                        }
23128                                }
23129                        }
23130                        break;
23131                case Dataset.FLOAT32:
23132                        final float[] of32data = ((FloatDataset) result).getData();
23133                        if (it.isOutputDouble()) {
23134                                while (it.hasNext()) {
23135                                        final double ix = it.aDouble;
23136                                        float ox;
23137                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23138                                        of32data[it.oIndex] = ox;
23139                                }
23140                        } else {
23141                                while (it.hasNext()) {
23142                                        final long ix = it.aLong;
23143                                        float ox;
23144                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23145                                        of32data[it.oIndex] = ox;
23146                                }
23147                        }
23148                        break;
23149                case Dataset.FLOAT64:
23150                        final double[] of64data = ((DoubleDataset) result).getData();
23151                        if (it.isOutputDouble()) {
23152                                while (it.hasNext()) {
23153                                        final double ix = it.aDouble;
23154                                        double ox;
23155                                        ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23156                                        of64data[it.oIndex] = ox;
23157                                }
23158                        } else {
23159                                while (it.hasNext()) {
23160                                        final long ix = it.aLong;
23161                                        double ox;
23162                                        ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23163                                        of64data[it.oIndex] = ox;
23164                                }
23165                        }
23166                        break;
23167                case Dataset.ARRAYFLOAT32:
23168                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
23169                        if (is == 1) {
23170                                if (it.isOutputDouble()) {
23171                                        while (it.hasNext()) {
23172                                                final double ix = it.aDouble;
23173                                                float ox;
23174                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23175                                                oaf32data[it.oIndex] = ox;
23176                                        }
23177                                } else {
23178                                        while (it.hasNext()) {
23179                                                final long ix = it.aLong;
23180                                                float ox;
23181                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23182                                                oaf32data[it.oIndex] = ox;
23183                                        }
23184                                }
23185                        } else if (as == 1) {
23186                                if (it.isOutputDouble()) {
23187                                        while (it.hasNext()) {
23188                                                final double ix = it.aDouble;
23189                                                float ox;
23190                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23191                                                for (int j = 0; j < is; j++) {
23192                                                        oaf32data[it.oIndex + j] = ox;
23193                                                }
23194                                        }
23195                                } else {
23196                                        while (it.hasNext()) {
23197                                                final long ix = it.aLong;
23198                                                float ox;
23199                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23200                                                for (int j = 0; j < is; j++) {
23201                                                        oaf32data[it.oIndex + j] = ox;
23202                                                }
23203                                        }
23204                                }
23205                        } else {
23206                                if (it.isOutputDouble()) {
23207                                        while (it.hasNext()) {
23208                                                for (int j = 0; j < is; j++) {
23209                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23210                                                        float ox;
23211                                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23212                                                        oaf32data[it.oIndex + j] = ox;
23213                                                }
23214                                        }
23215                                } else {
23216                                        while (it.hasNext()) {
23217                                                for (int j = 0; j < is; j++) {
23218                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23219                                                        float ox;
23220                                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
23221                                                        oaf32data[it.oIndex + j] = ox;
23222                                                }
23223                                        }
23224                                }
23225                        }
23226                        break;
23227                case Dataset.ARRAYFLOAT64:
23228                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
23229                        if (is == 1) {
23230                                if (it.isOutputDouble()) {
23231                                        while (it.hasNext()) {
23232                                                final double ix = it.aDouble;
23233                                                double ox;
23234                                                ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23235                                                oaf64data[it.oIndex] = ox;
23236                                        }
23237                                } else {
23238                                        while (it.hasNext()) {
23239                                                final long ix = it.aLong;
23240                                                double ox;
23241                                                ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23242                                                oaf64data[it.oIndex] = ox;
23243                                        }
23244                                }
23245                        } else if (as == 1) {
23246                                if (it.isOutputDouble()) {
23247                                        while (it.hasNext()) {
23248                                                final double ix = it.aDouble;
23249                                                double ox;
23250                                                ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23251                                                for (int j = 0; j < is; j++) {
23252                                                        oaf64data[it.oIndex + j] = ox;
23253                                                }
23254                                        }
23255                                } else {
23256                                        while (it.hasNext()) {
23257                                                final long ix = it.aLong;
23258                                                double ox;
23259                                                ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23260                                                for (int j = 0; j < is; j++) {
23261                                                        oaf64data[it.oIndex + j] = ox;
23262                                                }
23263                                        }
23264                                }
23265                        } else {
23266                                if (it.isOutputDouble()) {
23267                                        while (it.hasNext()) {
23268                                                for (int j = 0; j < is; j++) {
23269                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23270                                                        double ox;
23271                                                        ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23272                                                        oaf64data[it.oIndex + j] = ox;
23273                                                }
23274                                        }
23275                                } else {
23276                                        while (it.hasNext()) {
23277                                                for (int j = 0; j < is; j++) {
23278                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23279                                                        double ox;
23280                                                        ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
23281                                                        oaf64data[it.oIndex + j] = ox;
23282                                                }
23283                                        }
23284                                }
23285                        }
23286                        break;
23287                case Dataset.COMPLEX64:
23288                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
23289                        if (!da.isComplex()) {
23290                                if (it.isOutputDouble()) {
23291                                        final double iy = 0;
23292                                        while (it.hasNext()) {
23293                                                final double ix = it.aDouble;
23294                                                Complex tz;
23295                                                float ox;
23296                                                float oy;
23297                                                tz = new Complex(-iy, ix).asin();
23298                                                ox = (float) (tz.getImaginary());
23299                                                oy = (float) (-tz.getReal());
23300                                                oc64data[it.oIndex] = ox;
23301                                                oc64data[it.oIndex + 1] = oy;
23302                                        }
23303                                } else {
23304                                        final long iy = 0;
23305                                        while (it.hasNext()) {
23306                                                final long ix = it.aLong;
23307                                                Complex tz;
23308                                                float ox;
23309                                                float oy;
23310                                                tz = new Complex(-iy, ix).asin();
23311                                                ox = (float) toLong(tz.getImaginary());
23312                                                oy = (float) toLong(-tz.getReal());
23313                                                oc64data[it.oIndex] = ox;
23314                                                oc64data[it.oIndex + 1] = oy;
23315                                        }
23316                                }
23317                        } else {
23318                                while (it.hasNext()) {
23319                                        final double ix = it.aDouble;
23320                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
23321                                        Complex tz;
23322                                        float ox;
23323                                        float oy;
23324                                        tz = new Complex(-iy, ix).asin();
23325                                        ox = (float) (tz.getImaginary());
23326                                        oy = (float) (-tz.getReal());
23327                                        oc64data[it.oIndex] = ox;
23328                                        oc64data[it.oIndex + 1] = oy;
23329                                }
23330                        }
23331                        break;
23332                case Dataset.COMPLEX128:
23333                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
23334                        if (!da.isComplex()) {
23335                                if (it.isOutputDouble()) {
23336                                        final double iy = 0;
23337                                        while (it.hasNext()) {
23338                                                final double ix = it.aDouble;
23339                                                Complex tz;
23340                                                double ox;
23341                                                double oy;
23342                                                tz = new Complex(-iy, ix).asin();
23343                                                ox = (tz.getImaginary());
23344                                                oy = (-tz.getReal());
23345                                                oc128data[it.oIndex] = ox;
23346                                                oc128data[it.oIndex + 1] = oy;
23347                                        }
23348                                } else {
23349                                        final long iy = 0;
23350                                        while (it.hasNext()) {
23351                                                final long ix = it.aLong;
23352                                                Complex tz;
23353                                                double ox;
23354                                                double oy;
23355                                                tz = new Complex(-iy, ix).asin();
23356                                                ox = (tz.getImaginary());
23357                                                oy = (-tz.getReal());
23358                                                oc128data[it.oIndex] = ox;
23359                                                oc128data[it.oIndex + 1] = oy;
23360                                        }
23361                                }
23362                        } else {
23363                                while (it.hasNext()) {
23364                                        final double ix = it.aDouble;
23365                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
23366                                        Complex tz;
23367                                        double ox;
23368                                        double oy;
23369                                        tz = new Complex(-iy, ix).asin();
23370                                        ox = (tz.getImaginary());
23371                                        oy = (-tz.getReal());
23372                                        oc128data[it.oIndex] = ox;
23373                                        oc128data[it.oIndex + 1] = oy;
23374                                }
23375                        }
23376                        break;
23377                default:
23378                        throw new IllegalArgumentException("arcsinh supports integer, compound integer, real, compound real, complex datasets only");
23379                }
23380
23381                addFunctionName(result, "arcsinh");
23382                return result;
23383        }
23384
23385        /**
23386         * arccosh - evaluate the inverse hyperbolic cosine function on each element of the dataset
23387         * @param a single operand
23388         * @return dataset
23389         */
23390        public static Dataset arccosh(final Object a) {
23391                return arccosh(a, null);
23392        }
23393
23394        /**
23395         * arccosh - evaluate the inverse hyperbolic cosine function on each element of the dataset
23396         * @param a single operand
23397         * @param o output can be null - in which case, a new dataset is created
23398         * @return dataset
23399         */
23400        public static Dataset arccosh(final Object a, final Dataset o) {
23401                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
23402                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
23403                final Dataset result = it.getOutput();
23404                if (!result.isComplex()) {
23405                        if (da.isComplex()) {
23406                                da = da.getRealView();
23407                                it = new SingleInputBroadcastIterator(da, result, true);
23408                        }
23409                }
23410                final int is = result.getElementsPerItem();
23411                final int as = da.getElementsPerItem();
23412                final int dt = result.getDType();
23413
23414                switch(dt) {
23415                case Dataset.INT8:
23416                        final byte[] oi8data = ((ByteDataset) result).getData();
23417                        if (it.isOutputDouble()) {
23418                                while (it.hasNext()) {
23419                                        final double ix = it.aDouble;
23420                                        byte ox;
23421                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23422                                        oi8data[it.oIndex] = ox;
23423                                }
23424                        } else {
23425                                while (it.hasNext()) {
23426                                        final long ix = it.aLong;
23427                                        byte ox;
23428                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23429                                        oi8data[it.oIndex] = ox;
23430                                }
23431                        }
23432                        break;
23433                case Dataset.INT16:
23434                        final short[] oi16data = ((ShortDataset) result).getData();
23435                        if (it.isOutputDouble()) {
23436                                while (it.hasNext()) {
23437                                        final double ix = it.aDouble;
23438                                        short ox;
23439                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23440                                        oi16data[it.oIndex] = ox;
23441                                }
23442                        } else {
23443                                while (it.hasNext()) {
23444                                        final long ix = it.aLong;
23445                                        short ox;
23446                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23447                                        oi16data[it.oIndex] = ox;
23448                                }
23449                        }
23450                        break;
23451                case Dataset.INT64:
23452                        final long[] oi64data = ((LongDataset) result).getData();
23453                        if (it.isOutputDouble()) {
23454                                while (it.hasNext()) {
23455                                        final double ix = it.aDouble;
23456                                        long ox;
23457                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23458                                        oi64data[it.oIndex] = ox;
23459                                }
23460                        } else {
23461                                while (it.hasNext()) {
23462                                        final long ix = it.aLong;
23463                                        long ox;
23464                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23465                                        oi64data[it.oIndex] = ox;
23466                                }
23467                        }
23468                        break;
23469                case Dataset.INT32:
23470                        final int[] oi32data = ((IntegerDataset) result).getData();
23471                        if (it.isOutputDouble()) {
23472                                while (it.hasNext()) {
23473                                        final double ix = it.aDouble;
23474                                        int ox;
23475                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23476                                        oi32data[it.oIndex] = ox;
23477                                }
23478                        } else {
23479                                while (it.hasNext()) {
23480                                        final long ix = it.aLong;
23481                                        int ox;
23482                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23483                                        oi32data[it.oIndex] = ox;
23484                                }
23485                        }
23486                        break;
23487                case Dataset.ARRAYINT8:
23488                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
23489                        if (is == 1) {
23490                                if (it.isOutputDouble()) {
23491                                        while (it.hasNext()) {
23492                                                final double ix = it.aDouble;
23493                                                byte ox;
23494                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23495                                                oai8data[it.oIndex] = ox;
23496                                        }
23497                                } else {
23498                                        while (it.hasNext()) {
23499                                                final long ix = it.aLong;
23500                                                byte ox;
23501                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23502                                                oai8data[it.oIndex] = ox;
23503                                        }
23504                                }
23505                        } else if (as == 1) {
23506                                if (it.isOutputDouble()) {
23507                                        while (it.hasNext()) {
23508                                                final double ix = it.aDouble;
23509                                                byte ox;
23510                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23511                                                for (int j = 0; j < is; j++) {
23512                                                        oai8data[it.oIndex + j] = ox;
23513                                                }
23514                                        }
23515                                } else {
23516                                        while (it.hasNext()) {
23517                                                final long ix = it.aLong;
23518                                                byte ox;
23519                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23520                                                for (int j = 0; j < is; j++) {
23521                                                        oai8data[it.oIndex + j] = ox;
23522                                                }
23523                                        }
23524                                }
23525                        } else {
23526                                if (it.isOutputDouble()) {
23527                                        while (it.hasNext()) {
23528                                                for (int j = 0; j < is; j++) {
23529                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23530                                                        byte ox;
23531                                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23532                                                        oai8data[it.oIndex + j] = ox;
23533                                                }
23534                                        }
23535                                } else {
23536                                        while (it.hasNext()) {
23537                                                for (int j = 0; j < is; j++) {
23538                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23539                                                        byte ox;
23540                                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23541                                                        oai8data[it.oIndex + j] = ox;
23542                                                }
23543                                        }
23544                                }
23545                        }
23546                        break;
23547                case Dataset.ARRAYINT16:
23548                        final short[] oai16data = ((CompoundShortDataset) result).getData();
23549                        if (is == 1) {
23550                                if (it.isOutputDouble()) {
23551                                        while (it.hasNext()) {
23552                                                final double ix = it.aDouble;
23553                                                short ox;
23554                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23555                                                oai16data[it.oIndex] = ox;
23556                                        }
23557                                } else {
23558                                        while (it.hasNext()) {
23559                                                final long ix = it.aLong;
23560                                                short ox;
23561                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23562                                                oai16data[it.oIndex] = ox;
23563                                        }
23564                                }
23565                        } else if (as == 1) {
23566                                if (it.isOutputDouble()) {
23567                                        while (it.hasNext()) {
23568                                                final double ix = it.aDouble;
23569                                                short ox;
23570                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23571                                                for (int j = 0; j < is; j++) {
23572                                                        oai16data[it.oIndex + j] = ox;
23573                                                }
23574                                        }
23575                                } else {
23576                                        while (it.hasNext()) {
23577                                                final long ix = it.aLong;
23578                                                short ox;
23579                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23580                                                for (int j = 0; j < is; j++) {
23581                                                        oai16data[it.oIndex + j] = ox;
23582                                                }
23583                                        }
23584                                }
23585                        } else {
23586                                if (it.isOutputDouble()) {
23587                                        while (it.hasNext()) {
23588                                                for (int j = 0; j < is; j++) {
23589                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23590                                                        short ox;
23591                                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23592                                                        oai16data[it.oIndex + j] = ox;
23593                                                }
23594                                        }
23595                                } else {
23596                                        while (it.hasNext()) {
23597                                                for (int j = 0; j < is; j++) {
23598                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23599                                                        short ox;
23600                                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23601                                                        oai16data[it.oIndex + j] = ox;
23602                                                }
23603                                        }
23604                                }
23605                        }
23606                        break;
23607                case Dataset.ARRAYINT64:
23608                        final long[] oai64data = ((CompoundLongDataset) result).getData();
23609                        if (is == 1) {
23610                                if (it.isOutputDouble()) {
23611                                        while (it.hasNext()) {
23612                                                final double ix = it.aDouble;
23613                                                long ox;
23614                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23615                                                oai64data[it.oIndex] = ox;
23616                                        }
23617                                } else {
23618                                        while (it.hasNext()) {
23619                                                final long ix = it.aLong;
23620                                                long ox;
23621                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23622                                                oai64data[it.oIndex] = ox;
23623                                        }
23624                                }
23625                        } else if (as == 1) {
23626                                if (it.isOutputDouble()) {
23627                                        while (it.hasNext()) {
23628                                                final double ix = it.aDouble;
23629                                                long ox;
23630                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23631                                                for (int j = 0; j < is; j++) {
23632                                                        oai64data[it.oIndex + j] = ox;
23633                                                }
23634                                        }
23635                                } else {
23636                                        while (it.hasNext()) {
23637                                                final long ix = it.aLong;
23638                                                long ox;
23639                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23640                                                for (int j = 0; j < is; j++) {
23641                                                        oai64data[it.oIndex + j] = ox;
23642                                                }
23643                                        }
23644                                }
23645                        } else {
23646                                if (it.isOutputDouble()) {
23647                                        while (it.hasNext()) {
23648                                                for (int j = 0; j < is; j++) {
23649                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23650                                                        long ox;
23651                                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23652                                                        oai64data[it.oIndex + j] = ox;
23653                                                }
23654                                        }
23655                                } else {
23656                                        while (it.hasNext()) {
23657                                                for (int j = 0; j < is; j++) {
23658                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23659                                                        long ox;
23660                                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23661                                                        oai64data[it.oIndex + j] = ox;
23662                                                }
23663                                        }
23664                                }
23665                        }
23666                        break;
23667                case Dataset.ARRAYINT32:
23668                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
23669                        if (is == 1) {
23670                                if (it.isOutputDouble()) {
23671                                        while (it.hasNext()) {
23672                                                final double ix = it.aDouble;
23673                                                int ox;
23674                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23675                                                oai32data[it.oIndex] = ox;
23676                                        }
23677                                } else {
23678                                        while (it.hasNext()) {
23679                                                final long ix = it.aLong;
23680                                                int ox;
23681                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23682                                                oai32data[it.oIndex] = ox;
23683                                        }
23684                                }
23685                        } else if (as == 1) {
23686                                if (it.isOutputDouble()) {
23687                                        while (it.hasNext()) {
23688                                                final double ix = it.aDouble;
23689                                                int ox;
23690                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23691                                                for (int j = 0; j < is; j++) {
23692                                                        oai32data[it.oIndex + j] = ox;
23693                                                }
23694                                        }
23695                                } else {
23696                                        while (it.hasNext()) {
23697                                                final long ix = it.aLong;
23698                                                int ox;
23699                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23700                                                for (int j = 0; j < is; j++) {
23701                                                        oai32data[it.oIndex + j] = ox;
23702                                                }
23703                                        }
23704                                }
23705                        } else {
23706                                if (it.isOutputDouble()) {
23707                                        while (it.hasNext()) {
23708                                                for (int j = 0; j < is; j++) {
23709                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23710                                                        int ox;
23711                                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23712                                                        oai32data[it.oIndex + j] = ox;
23713                                                }
23714                                        }
23715                                } else {
23716                                        while (it.hasNext()) {
23717                                                for (int j = 0; j < is; j++) {
23718                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23719                                                        int ox;
23720                                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
23721                                                        oai32data[it.oIndex + j] = ox;
23722                                                }
23723                                        }
23724                                }
23725                        }
23726                        break;
23727                case Dataset.FLOAT32:
23728                        final float[] of32data = ((FloatDataset) result).getData();
23729                        if (it.isOutputDouble()) {
23730                                while (it.hasNext()) {
23731                                        final double ix = it.aDouble;
23732                                        float ox;
23733                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
23734                                        of32data[it.oIndex] = ox;
23735                                }
23736                        } else {
23737                                while (it.hasNext()) {
23738                                        final long ix = it.aLong;
23739                                        float ox;
23740                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
23741                                        of32data[it.oIndex] = ox;
23742                                }
23743                        }
23744                        break;
23745                case Dataset.FLOAT64:
23746                        final double[] of64data = ((DoubleDataset) result).getData();
23747                        if (it.isOutputDouble()) {
23748                                while (it.hasNext()) {
23749                                        final double ix = it.aDouble;
23750                                        double ox;
23751                                        ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
23752                                        of64data[it.oIndex] = ox;
23753                                }
23754                        } else {
23755                                while (it.hasNext()) {
23756                                        final long ix = it.aLong;
23757                                        double ox;
23758                                        ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
23759                                        of64data[it.oIndex] = ox;
23760                                }
23761                        }
23762                        break;
23763                case Dataset.ARRAYFLOAT32:
23764                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
23765                        if (is == 1) {
23766                                if (it.isOutputDouble()) {
23767                                        while (it.hasNext()) {
23768                                                final double ix = it.aDouble;
23769                                                float ox;
23770                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
23771                                                oaf32data[it.oIndex] = ox;
23772                                        }
23773                                } else {
23774                                        while (it.hasNext()) {
23775                                                final long ix = it.aLong;
23776                                                float ox;
23777                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
23778                                                oaf32data[it.oIndex] = ox;
23779                                        }
23780                                }
23781                        } else if (as == 1) {
23782                                if (it.isOutputDouble()) {
23783                                        while (it.hasNext()) {
23784                                                final double ix = it.aDouble;
23785                                                float ox;
23786                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
23787                                                for (int j = 0; j < is; j++) {
23788                                                        oaf32data[it.oIndex + j] = ox;
23789                                                }
23790                                        }
23791                                } else {
23792                                        while (it.hasNext()) {
23793                                                final long ix = it.aLong;
23794                                                float ox;
23795                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
23796                                                for (int j = 0; j < is; j++) {
23797                                                        oaf32data[it.oIndex + j] = ox;
23798                                                }
23799                                        }
23800                                }
23801                        } else {
23802                                if (it.isOutputDouble()) {
23803                                        while (it.hasNext()) {
23804                                                for (int j = 0; j < is; j++) {
23805                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23806                                                        float ox;
23807                                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
23808                                                        oaf32data[it.oIndex + j] = ox;
23809                                                }
23810                                        }
23811                                } else {
23812                                        while (it.hasNext()) {
23813                                                for (int j = 0; j < is; j++) {
23814                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23815                                                        float ox;
23816                                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
23817                                                        oaf32data[it.oIndex + j] = ox;
23818                                                }
23819                                        }
23820                                }
23821                        }
23822                        break;
23823                case Dataset.ARRAYFLOAT64:
23824                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
23825                        if (is == 1) {
23826                                if (it.isOutputDouble()) {
23827                                        while (it.hasNext()) {
23828                                                final double ix = it.aDouble;
23829                                                double ox;
23830                                                ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
23831                                                oaf64data[it.oIndex] = ox;
23832                                        }
23833                                } else {
23834                                        while (it.hasNext()) {
23835                                                final long ix = it.aLong;
23836                                                double ox;
23837                                                ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
23838                                                oaf64data[it.oIndex] = ox;
23839                                        }
23840                                }
23841                        } else if (as == 1) {
23842                                if (it.isOutputDouble()) {
23843                                        while (it.hasNext()) {
23844                                                final double ix = it.aDouble;
23845                                                double ox;
23846                                                ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
23847                                                for (int j = 0; j < is; j++) {
23848                                                        oaf64data[it.oIndex + j] = ox;
23849                                                }
23850                                        }
23851                                } else {
23852                                        while (it.hasNext()) {
23853                                                final long ix = it.aLong;
23854                                                double ox;
23855                                                ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
23856                                                for (int j = 0; j < is; j++) {
23857                                                        oaf64data[it.oIndex + j] = ox;
23858                                                }
23859                                        }
23860                                }
23861                        } else {
23862                                if (it.isOutputDouble()) {
23863                                        while (it.hasNext()) {
23864                                                for (int j = 0; j < is; j++) {
23865                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
23866                                                        double ox;
23867                                                        ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
23868                                                        oaf64data[it.oIndex + j] = ox;
23869                                                }
23870                                        }
23871                                } else {
23872                                        while (it.hasNext()) {
23873                                                for (int j = 0; j < is; j++) {
23874                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
23875                                                        double ox;
23876                                                        ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
23877                                                        oaf64data[it.oIndex + j] = ox;
23878                                                }
23879                                        }
23880                                }
23881                        }
23882                        break;
23883                case Dataset.COMPLEX64:
23884                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
23885                        if (!da.isComplex()) {
23886                                if (it.isOutputDouble()) {
23887                                        final double iy = 0;
23888                                        while (it.hasNext()) {
23889                                                final double ix = it.aDouble;
23890                                                Complex tz;
23891                                                float ox;
23892                                                float oy;
23893                                                tz = new Complex(-iy, ix).acos();
23894                                                ox = (float) (tz.getImaginary());
23895                                                oy = (float) (-tz.getReal());
23896                                                oc64data[it.oIndex] = ox;
23897                                                oc64data[it.oIndex + 1] = oy;
23898                                        }
23899                                } else {
23900                                        final long iy = 0;
23901                                        while (it.hasNext()) {
23902                                                final long ix = it.aLong;
23903                                                Complex tz;
23904                                                float ox;
23905                                                float oy;
23906                                                tz = new Complex(-iy, ix).acos();
23907                                                ox = (float) toLong(tz.getImaginary());
23908                                                oy = (float) toLong(-tz.getReal());
23909                                                oc64data[it.oIndex] = ox;
23910                                                oc64data[it.oIndex + 1] = oy;
23911                                        }
23912                                }
23913                        } else {
23914                                while (it.hasNext()) {
23915                                        final double ix = it.aDouble;
23916                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
23917                                        Complex tz;
23918                                        float ox;
23919                                        float oy;
23920                                        tz = new Complex(-iy, ix).acos();
23921                                        ox = (float) (tz.getImaginary());
23922                                        oy = (float) (-tz.getReal());
23923                                        oc64data[it.oIndex] = ox;
23924                                        oc64data[it.oIndex + 1] = oy;
23925                                }
23926                        }
23927                        break;
23928                case Dataset.COMPLEX128:
23929                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
23930                        if (!da.isComplex()) {
23931                                if (it.isOutputDouble()) {
23932                                        final double iy = 0;
23933                                        while (it.hasNext()) {
23934                                                final double ix = it.aDouble;
23935                                                Complex tz;
23936                                                double ox;
23937                                                double oy;
23938                                                tz = new Complex(-iy, ix).acos();
23939                                                ox = (tz.getImaginary());
23940                                                oy = (-tz.getReal());
23941                                                oc128data[it.oIndex] = ox;
23942                                                oc128data[it.oIndex + 1] = oy;
23943                                        }
23944                                } else {
23945                                        final long iy = 0;
23946                                        while (it.hasNext()) {
23947                                                final long ix = it.aLong;
23948                                                Complex tz;
23949                                                double ox;
23950                                                double oy;
23951                                                tz = new Complex(-iy, ix).acos();
23952                                                ox = (tz.getImaginary());
23953                                                oy = (-tz.getReal());
23954                                                oc128data[it.oIndex] = ox;
23955                                                oc128data[it.oIndex + 1] = oy;
23956                                        }
23957                                }
23958                        } else {
23959                                while (it.hasNext()) {
23960                                        final double ix = it.aDouble;
23961                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
23962                                        Complex tz;
23963                                        double ox;
23964                                        double oy;
23965                                        tz = new Complex(-iy, ix).acos();
23966                                        ox = (tz.getImaginary());
23967                                        oy = (-tz.getReal());
23968                                        oc128data[it.oIndex] = ox;
23969                                        oc128data[it.oIndex + 1] = oy;
23970                                }
23971                        }
23972                        break;
23973                default:
23974                        throw new IllegalArgumentException("arccosh supports integer, compound integer, real, compound real, complex datasets only");
23975                }
23976
23977                addFunctionName(result, "arccosh");
23978                return result;
23979        }
23980
23981        /**
23982         * arctanh - evaluate the inverse hyperbolic tangent function on each element of the dataset
23983         * @param a single operand
23984         * @return dataset
23985         */
23986        public static Dataset arctanh(final Object a) {
23987                return arctanh(a, null);
23988        }
23989
23990        /**
23991         * arctanh - evaluate the inverse hyperbolic tangent function on each element of the dataset
23992         * @param a single operand
23993         * @param o output can be null - in which case, a new dataset is created
23994         * @return dataset
23995         */
23996        public static Dataset arctanh(final Object a, final Dataset o) {
23997                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
23998                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
23999                final Dataset result = it.getOutput();
24000                if (!result.isComplex()) {
24001                        if (da.isComplex()) {
24002                                da = da.getRealView();
24003                                it = new SingleInputBroadcastIterator(da, result, true);
24004                        }
24005                }
24006                final int is = result.getElementsPerItem();
24007                final int as = da.getElementsPerItem();
24008                final int dt = result.getDType();
24009
24010                switch(dt) {
24011                case Dataset.INT8:
24012                        final byte[] oi8data = ((ByteDataset) result).getData();
24013                        if (it.isOutputDouble()) {
24014                                while (it.hasNext()) {
24015                                        final double ix = it.aDouble;
24016                                        byte ox;
24017                                        ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24018                                        oi8data[it.oIndex] = ox;
24019                                }
24020                        } else {
24021                                while (it.hasNext()) {
24022                                        final long ix = it.aLong;
24023                                        byte ox;
24024                                        ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24025                                        oi8data[it.oIndex] = ox;
24026                                }
24027                        }
24028                        break;
24029                case Dataset.INT16:
24030                        final short[] oi16data = ((ShortDataset) result).getData();
24031                        if (it.isOutputDouble()) {
24032                                while (it.hasNext()) {
24033                                        final double ix = it.aDouble;
24034                                        short ox;
24035                                        ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24036                                        oi16data[it.oIndex] = ox;
24037                                }
24038                        } else {
24039                                while (it.hasNext()) {
24040                                        final long ix = it.aLong;
24041                                        short ox;
24042                                        ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24043                                        oi16data[it.oIndex] = ox;
24044                                }
24045                        }
24046                        break;
24047                case Dataset.INT64:
24048                        final long[] oi64data = ((LongDataset) result).getData();
24049                        if (it.isOutputDouble()) {
24050                                while (it.hasNext()) {
24051                                        final double ix = it.aDouble;
24052                                        long ox;
24053                                        ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24054                                        oi64data[it.oIndex] = ox;
24055                                }
24056                        } else {
24057                                while (it.hasNext()) {
24058                                        final long ix = it.aLong;
24059                                        long ox;
24060                                        ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24061                                        oi64data[it.oIndex] = ox;
24062                                }
24063                        }
24064                        break;
24065                case Dataset.INT32:
24066                        final int[] oi32data = ((IntegerDataset) result).getData();
24067                        if (it.isOutputDouble()) {
24068                                while (it.hasNext()) {
24069                                        final double ix = it.aDouble;
24070                                        int ox;
24071                                        ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24072                                        oi32data[it.oIndex] = ox;
24073                                }
24074                        } else {
24075                                while (it.hasNext()) {
24076                                        final long ix = it.aLong;
24077                                        int ox;
24078                                        ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24079                                        oi32data[it.oIndex] = ox;
24080                                }
24081                        }
24082                        break;
24083                case Dataset.ARRAYINT8:
24084                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
24085                        if (is == 1) {
24086                                if (it.isOutputDouble()) {
24087                                        while (it.hasNext()) {
24088                                                final double ix = it.aDouble;
24089                                                byte ox;
24090                                                ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24091                                                oai8data[it.oIndex] = ox;
24092                                        }
24093                                } else {
24094                                        while (it.hasNext()) {
24095                                                final long ix = it.aLong;
24096                                                byte ox;
24097                                                ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24098                                                oai8data[it.oIndex] = ox;
24099                                        }
24100                                }
24101                        } else if (as == 1) {
24102                                if (it.isOutputDouble()) {
24103                                        while (it.hasNext()) {
24104                                                final double ix = it.aDouble;
24105                                                byte ox;
24106                                                ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24107                                                for (int j = 0; j < is; j++) {
24108                                                        oai8data[it.oIndex + j] = ox;
24109                                                }
24110                                        }
24111                                } else {
24112                                        while (it.hasNext()) {
24113                                                final long ix = it.aLong;
24114                                                byte ox;
24115                                                ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24116                                                for (int j = 0; j < is; j++) {
24117                                                        oai8data[it.oIndex + j] = ox;
24118                                                }
24119                                        }
24120                                }
24121                        } else {
24122                                if (it.isOutputDouble()) {
24123                                        while (it.hasNext()) {
24124                                                for (int j = 0; j < is; j++) {
24125                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24126                                                        byte ox;
24127                                                        ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24128                                                        oai8data[it.oIndex + j] = ox;
24129                                                }
24130                                        }
24131                                } else {
24132                                        while (it.hasNext()) {
24133                                                for (int j = 0; j < is; j++) {
24134                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24135                                                        byte ox;
24136                                                        ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24137                                                        oai8data[it.oIndex + j] = ox;
24138                                                }
24139                                        }
24140                                }
24141                        }
24142                        break;
24143                case Dataset.ARRAYINT16:
24144                        final short[] oai16data = ((CompoundShortDataset) result).getData();
24145                        if (is == 1) {
24146                                if (it.isOutputDouble()) {
24147                                        while (it.hasNext()) {
24148                                                final double ix = it.aDouble;
24149                                                short ox;
24150                                                ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24151                                                oai16data[it.oIndex] = ox;
24152                                        }
24153                                } else {
24154                                        while (it.hasNext()) {
24155                                                final long ix = it.aLong;
24156                                                short ox;
24157                                                ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24158                                                oai16data[it.oIndex] = ox;
24159                                        }
24160                                }
24161                        } else if (as == 1) {
24162                                if (it.isOutputDouble()) {
24163                                        while (it.hasNext()) {
24164                                                final double ix = it.aDouble;
24165                                                short ox;
24166                                                ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24167                                                for (int j = 0; j < is; j++) {
24168                                                        oai16data[it.oIndex + j] = ox;
24169                                                }
24170                                        }
24171                                } else {
24172                                        while (it.hasNext()) {
24173                                                final long ix = it.aLong;
24174                                                short ox;
24175                                                ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24176                                                for (int j = 0; j < is; j++) {
24177                                                        oai16data[it.oIndex + j] = ox;
24178                                                }
24179                                        }
24180                                }
24181                        } else {
24182                                if (it.isOutputDouble()) {
24183                                        while (it.hasNext()) {
24184                                                for (int j = 0; j < is; j++) {
24185                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24186                                                        short ox;
24187                                                        ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24188                                                        oai16data[it.oIndex + j] = ox;
24189                                                }
24190                                        }
24191                                } else {
24192                                        while (it.hasNext()) {
24193                                                for (int j = 0; j < is; j++) {
24194                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24195                                                        short ox;
24196                                                        ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24197                                                        oai16data[it.oIndex + j] = ox;
24198                                                }
24199                                        }
24200                                }
24201                        }
24202                        break;
24203                case Dataset.ARRAYINT64:
24204                        final long[] oai64data = ((CompoundLongDataset) result).getData();
24205                        if (is == 1) {
24206                                if (it.isOutputDouble()) {
24207                                        while (it.hasNext()) {
24208                                                final double ix = it.aDouble;
24209                                                long ox;
24210                                                ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24211                                                oai64data[it.oIndex] = ox;
24212                                        }
24213                                } else {
24214                                        while (it.hasNext()) {
24215                                                final long ix = it.aLong;
24216                                                long ox;
24217                                                ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24218                                                oai64data[it.oIndex] = ox;
24219                                        }
24220                                }
24221                        } else if (as == 1) {
24222                                if (it.isOutputDouble()) {
24223                                        while (it.hasNext()) {
24224                                                final double ix = it.aDouble;
24225                                                long ox;
24226                                                ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24227                                                for (int j = 0; j < is; j++) {
24228                                                        oai64data[it.oIndex + j] = ox;
24229                                                }
24230                                        }
24231                                } else {
24232                                        while (it.hasNext()) {
24233                                                final long ix = it.aLong;
24234                                                long ox;
24235                                                ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24236                                                for (int j = 0; j < is; j++) {
24237                                                        oai64data[it.oIndex + j] = ox;
24238                                                }
24239                                        }
24240                                }
24241                        } else {
24242                                if (it.isOutputDouble()) {
24243                                        while (it.hasNext()) {
24244                                                for (int j = 0; j < is; j++) {
24245                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24246                                                        long ox;
24247                                                        ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24248                                                        oai64data[it.oIndex + j] = ox;
24249                                                }
24250                                        }
24251                                } else {
24252                                        while (it.hasNext()) {
24253                                                for (int j = 0; j < is; j++) {
24254                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24255                                                        long ox;
24256                                                        ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24257                                                        oai64data[it.oIndex + j] = ox;
24258                                                }
24259                                        }
24260                                }
24261                        }
24262                        break;
24263                case Dataset.ARRAYINT32:
24264                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
24265                        if (is == 1) {
24266                                if (it.isOutputDouble()) {
24267                                        while (it.hasNext()) {
24268                                                final double ix = it.aDouble;
24269                                                int ox;
24270                                                ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24271                                                oai32data[it.oIndex] = ox;
24272                                        }
24273                                } else {
24274                                        while (it.hasNext()) {
24275                                                final long ix = it.aLong;
24276                                                int ox;
24277                                                ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24278                                                oai32data[it.oIndex] = ox;
24279                                        }
24280                                }
24281                        } else if (as == 1) {
24282                                if (it.isOutputDouble()) {
24283                                        while (it.hasNext()) {
24284                                                final double ix = it.aDouble;
24285                                                int ox;
24286                                                ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24287                                                for (int j = 0; j < is; j++) {
24288                                                        oai32data[it.oIndex + j] = ox;
24289                                                }
24290                                        }
24291                                } else {
24292                                        while (it.hasNext()) {
24293                                                final long ix = it.aLong;
24294                                                int ox;
24295                                                ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24296                                                for (int j = 0; j < is; j++) {
24297                                                        oai32data[it.oIndex + j] = ox;
24298                                                }
24299                                        }
24300                                }
24301                        } else {
24302                                if (it.isOutputDouble()) {
24303                                        while (it.hasNext()) {
24304                                                for (int j = 0; j < is; j++) {
24305                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24306                                                        int ox;
24307                                                        ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24308                                                        oai32data[it.oIndex + j] = ox;
24309                                                }
24310                                        }
24311                                } else {
24312                                        while (it.hasNext()) {
24313                                                for (int j = 0; j < is; j++) {
24314                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24315                                                        int ox;
24316                                                        ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
24317                                                        oai32data[it.oIndex + j] = ox;
24318                                                }
24319                                        }
24320                                }
24321                        }
24322                        break;
24323                case Dataset.FLOAT32:
24324                        final float[] of32data = ((FloatDataset) result).getData();
24325                        if (it.isOutputDouble()) {
24326                                while (it.hasNext()) {
24327                                        final double ix = it.aDouble;
24328                                        float ox;
24329                                        ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24330                                        of32data[it.oIndex] = ox;
24331                                }
24332                        } else {
24333                                while (it.hasNext()) {
24334                                        final long ix = it.aLong;
24335                                        float ox;
24336                                        ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24337                                        of32data[it.oIndex] = ox;
24338                                }
24339                        }
24340                        break;
24341                case Dataset.FLOAT64:
24342                        final double[] of64data = ((DoubleDataset) result).getData();
24343                        if (it.isOutputDouble()) {
24344                                while (it.hasNext()) {
24345                                        final double ix = it.aDouble;
24346                                        double ox;
24347                                        ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24348                                        of64data[it.oIndex] = ox;
24349                                }
24350                        } else {
24351                                while (it.hasNext()) {
24352                                        final long ix = it.aLong;
24353                                        double ox;
24354                                        ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24355                                        of64data[it.oIndex] = ox;
24356                                }
24357                        }
24358                        break;
24359                case Dataset.ARRAYFLOAT32:
24360                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
24361                        if (is == 1) {
24362                                if (it.isOutputDouble()) {
24363                                        while (it.hasNext()) {
24364                                                final double ix = it.aDouble;
24365                                                float ox;
24366                                                ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24367                                                oaf32data[it.oIndex] = ox;
24368                                        }
24369                                } else {
24370                                        while (it.hasNext()) {
24371                                                final long ix = it.aLong;
24372                                                float ox;
24373                                                ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24374                                                oaf32data[it.oIndex] = ox;
24375                                        }
24376                                }
24377                        } else if (as == 1) {
24378                                if (it.isOutputDouble()) {
24379                                        while (it.hasNext()) {
24380                                                final double ix = it.aDouble;
24381                                                float ox;
24382                                                ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24383                                                for (int j = 0; j < is; j++) {
24384                                                        oaf32data[it.oIndex + j] = ox;
24385                                                }
24386                                        }
24387                                } else {
24388                                        while (it.hasNext()) {
24389                                                final long ix = it.aLong;
24390                                                float ox;
24391                                                ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24392                                                for (int j = 0; j < is; j++) {
24393                                                        oaf32data[it.oIndex + j] = ox;
24394                                                }
24395                                        }
24396                                }
24397                        } else {
24398                                if (it.isOutputDouble()) {
24399                                        while (it.hasNext()) {
24400                                                for (int j = 0; j < is; j++) {
24401                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24402                                                        float ox;
24403                                                        ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24404                                                        oaf32data[it.oIndex + j] = ox;
24405                                                }
24406                                        }
24407                                } else {
24408                                        while (it.hasNext()) {
24409                                                for (int j = 0; j < is; j++) {
24410                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24411                                                        float ox;
24412                                                        ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
24413                                                        oaf32data[it.oIndex + j] = ox;
24414                                                }
24415                                        }
24416                                }
24417                        }
24418                        break;
24419                case Dataset.ARRAYFLOAT64:
24420                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
24421                        if (is == 1) {
24422                                if (it.isOutputDouble()) {
24423                                        while (it.hasNext()) {
24424                                                final double ix = it.aDouble;
24425                                                double ox;
24426                                                ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24427                                                oaf64data[it.oIndex] = ox;
24428                                        }
24429                                } else {
24430                                        while (it.hasNext()) {
24431                                                final long ix = it.aLong;
24432                                                double ox;
24433                                                ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24434                                                oaf64data[it.oIndex] = ox;
24435                                        }
24436                                }
24437                        } else if (as == 1) {
24438                                if (it.isOutputDouble()) {
24439                                        while (it.hasNext()) {
24440                                                final double ix = it.aDouble;
24441                                                double ox;
24442                                                ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24443                                                for (int j = 0; j < is; j++) {
24444                                                        oaf64data[it.oIndex + j] = ox;
24445                                                }
24446                                        }
24447                                } else {
24448                                        while (it.hasNext()) {
24449                                                final long ix = it.aLong;
24450                                                double ox;
24451                                                ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24452                                                for (int j = 0; j < is; j++) {
24453                                                        oaf64data[it.oIndex + j] = ox;
24454                                                }
24455                                        }
24456                                }
24457                        } else {
24458                                if (it.isOutputDouble()) {
24459                                        while (it.hasNext()) {
24460                                                for (int j = 0; j < is; j++) {
24461                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24462                                                        double ox;
24463                                                        ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24464                                                        oaf64data[it.oIndex + j] = ox;
24465                                                }
24466                                        }
24467                                } else {
24468                                        while (it.hasNext()) {
24469                                                for (int j = 0; j < is; j++) {
24470                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24471                                                        double ox;
24472                                                        ox = (0.5*Math.log((1 + ix)/(1 - ix)));
24473                                                        oaf64data[it.oIndex + j] = ox;
24474                                                }
24475                                        }
24476                                }
24477                        }
24478                        break;
24479                case Dataset.COMPLEX64:
24480                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
24481                        if (!da.isComplex()) {
24482                                if (it.isOutputDouble()) {
24483                                        final double iy = 0;
24484                                        while (it.hasNext()) {
24485                                                final double ix = it.aDouble;
24486                                                Complex tz;
24487                                                float ox;
24488                                                float oy;
24489                                                tz = new Complex(-iy, ix).atan();
24490                                                ox = (float) (tz.getImaginary());
24491                                                oy = (float) (-tz.getReal());
24492                                                oc64data[it.oIndex] = ox;
24493                                                oc64data[it.oIndex + 1] = oy;
24494                                        }
24495                                } else {
24496                                        final long iy = 0;
24497                                        while (it.hasNext()) {
24498                                                final long ix = it.aLong;
24499                                                Complex tz;
24500                                                float ox;
24501                                                float oy;
24502                                                tz = new Complex(-iy, ix).atan();
24503                                                ox = (float) toLong(tz.getImaginary());
24504                                                oy = (float) toLong(-tz.getReal());
24505                                                oc64data[it.oIndex] = ox;
24506                                                oc64data[it.oIndex + 1] = oy;
24507                                        }
24508                                }
24509                        } else {
24510                                while (it.hasNext()) {
24511                                        final double ix = it.aDouble;
24512                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
24513                                        Complex tz;
24514                                        float ox;
24515                                        float oy;
24516                                        tz = new Complex(-iy, ix).atan();
24517                                        ox = (float) (tz.getImaginary());
24518                                        oy = (float) (-tz.getReal());
24519                                        oc64data[it.oIndex] = ox;
24520                                        oc64data[it.oIndex + 1] = oy;
24521                                }
24522                        }
24523                        break;
24524                case Dataset.COMPLEX128:
24525                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
24526                        if (!da.isComplex()) {
24527                                if (it.isOutputDouble()) {
24528                                        final double iy = 0;
24529                                        while (it.hasNext()) {
24530                                                final double ix = it.aDouble;
24531                                                Complex tz;
24532                                                double ox;
24533                                                double oy;
24534                                                tz = new Complex(-iy, ix).atan();
24535                                                ox = (tz.getImaginary());
24536                                                oy = (-tz.getReal());
24537                                                oc128data[it.oIndex] = ox;
24538                                                oc128data[it.oIndex + 1] = oy;
24539                                        }
24540                                } else {
24541                                        final long iy = 0;
24542                                        while (it.hasNext()) {
24543                                                final long ix = it.aLong;
24544                                                Complex tz;
24545                                                double ox;
24546                                                double oy;
24547                                                tz = new Complex(-iy, ix).atan();
24548                                                ox = (tz.getImaginary());
24549                                                oy = (-tz.getReal());
24550                                                oc128data[it.oIndex] = ox;
24551                                                oc128data[it.oIndex + 1] = oy;
24552                                        }
24553                                }
24554                        } else {
24555                                while (it.hasNext()) {
24556                                        final double ix = it.aDouble;
24557                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
24558                                        Complex tz;
24559                                        double ox;
24560                                        double oy;
24561                                        tz = new Complex(-iy, ix).atan();
24562                                        ox = (tz.getImaginary());
24563                                        oy = (-tz.getReal());
24564                                        oc128data[it.oIndex] = ox;
24565                                        oc128data[it.oIndex + 1] = oy;
24566                                }
24567                        }
24568                        break;
24569                default:
24570                        throw new IllegalArgumentException("arctanh supports integer, compound integer, real, compound real, complex datasets only");
24571                }
24572
24573                addFunctionName(result, "arctanh");
24574                return result;
24575        }
24576
24577        /**
24578         * log - evaluate the logarithm function on each element of the dataset
24579         * @param a single operand
24580         * @return dataset
24581         */
24582        public static Dataset log(final Object a) {
24583                return log(a, null);
24584        }
24585
24586        /**
24587         * log - evaluate the logarithm function on each element of the dataset
24588         * @param a single operand
24589         * @param o output can be null - in which case, a new dataset is created
24590         * @return dataset
24591         */
24592        public static Dataset log(final Object a, final Dataset o) {
24593                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
24594                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
24595                final Dataset result = it.getOutput();
24596                if (!result.isComplex()) {
24597                        if (da.isComplex()) {
24598                                da = da.getRealView();
24599                                it = new SingleInputBroadcastIterator(da, result, true);
24600                        }
24601                }
24602                final int is = result.getElementsPerItem();
24603                final int as = da.getElementsPerItem();
24604                final int dt = result.getDType();
24605
24606                switch(dt) {
24607                case Dataset.INT8:
24608                        final byte[] oi8data = ((ByteDataset) result).getData();
24609                        if (it.isOutputDouble()) {
24610                                while (it.hasNext()) {
24611                                        final double ix = it.aDouble;
24612                                        byte ox;
24613                                        ox = (byte) toLong(Math.log(ix));
24614                                        oi8data[it.oIndex] = ox;
24615                                }
24616                        } else {
24617                                while (it.hasNext()) {
24618                                        final long ix = it.aLong;
24619                                        byte ox;
24620                                        ox = (byte) toLong(Math.log(ix));
24621                                        oi8data[it.oIndex] = ox;
24622                                }
24623                        }
24624                        break;
24625                case Dataset.INT16:
24626                        final short[] oi16data = ((ShortDataset) result).getData();
24627                        if (it.isOutputDouble()) {
24628                                while (it.hasNext()) {
24629                                        final double ix = it.aDouble;
24630                                        short ox;
24631                                        ox = (short) toLong(Math.log(ix));
24632                                        oi16data[it.oIndex] = ox;
24633                                }
24634                        } else {
24635                                while (it.hasNext()) {
24636                                        final long ix = it.aLong;
24637                                        short ox;
24638                                        ox = (short) toLong(Math.log(ix));
24639                                        oi16data[it.oIndex] = ox;
24640                                }
24641                        }
24642                        break;
24643                case Dataset.INT64:
24644                        final long[] oi64data = ((LongDataset) result).getData();
24645                        if (it.isOutputDouble()) {
24646                                while (it.hasNext()) {
24647                                        final double ix = it.aDouble;
24648                                        long ox;
24649                                        ox = toLong(Math.log(ix));
24650                                        oi64data[it.oIndex] = ox;
24651                                }
24652                        } else {
24653                                while (it.hasNext()) {
24654                                        final long ix = it.aLong;
24655                                        long ox;
24656                                        ox = toLong(Math.log(ix));
24657                                        oi64data[it.oIndex] = ox;
24658                                }
24659                        }
24660                        break;
24661                case Dataset.INT32:
24662                        final int[] oi32data = ((IntegerDataset) result).getData();
24663                        if (it.isOutputDouble()) {
24664                                while (it.hasNext()) {
24665                                        final double ix = it.aDouble;
24666                                        int ox;
24667                                        ox = (int) toLong(Math.log(ix));
24668                                        oi32data[it.oIndex] = ox;
24669                                }
24670                        } else {
24671                                while (it.hasNext()) {
24672                                        final long ix = it.aLong;
24673                                        int ox;
24674                                        ox = (int) toLong(Math.log(ix));
24675                                        oi32data[it.oIndex] = ox;
24676                                }
24677                        }
24678                        break;
24679                case Dataset.ARRAYINT8:
24680                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
24681                        if (is == 1) {
24682                                if (it.isOutputDouble()) {
24683                                        while (it.hasNext()) {
24684                                                final double ix = it.aDouble;
24685                                                byte ox;
24686                                                ox = (byte) toLong(Math.log(ix));
24687                                                oai8data[it.oIndex] = ox;
24688                                        }
24689                                } else {
24690                                        while (it.hasNext()) {
24691                                                final long ix = it.aLong;
24692                                                byte ox;
24693                                                ox = (byte) toLong(Math.log(ix));
24694                                                oai8data[it.oIndex] = ox;
24695                                        }
24696                                }
24697                        } else if (as == 1) {
24698                                if (it.isOutputDouble()) {
24699                                        while (it.hasNext()) {
24700                                                final double ix = it.aDouble;
24701                                                byte ox;
24702                                                ox = (byte) toLong(Math.log(ix));
24703                                                for (int j = 0; j < is; j++) {
24704                                                        oai8data[it.oIndex + j] = ox;
24705                                                }
24706                                        }
24707                                } else {
24708                                        while (it.hasNext()) {
24709                                                final long ix = it.aLong;
24710                                                byte ox;
24711                                                ox = (byte) toLong(Math.log(ix));
24712                                                for (int j = 0; j < is; j++) {
24713                                                        oai8data[it.oIndex + j] = ox;
24714                                                }
24715                                        }
24716                                }
24717                        } else {
24718                                if (it.isOutputDouble()) {
24719                                        while (it.hasNext()) {
24720                                                for (int j = 0; j < is; j++) {
24721                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24722                                                        byte ox;
24723                                                        ox = (byte) toLong(Math.log(ix));
24724                                                        oai8data[it.oIndex + j] = ox;
24725                                                }
24726                                        }
24727                                } else {
24728                                        while (it.hasNext()) {
24729                                                for (int j = 0; j < is; j++) {
24730                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24731                                                        byte ox;
24732                                                        ox = (byte) toLong(Math.log(ix));
24733                                                        oai8data[it.oIndex + j] = ox;
24734                                                }
24735                                        }
24736                                }
24737                        }
24738                        break;
24739                case Dataset.ARRAYINT16:
24740                        final short[] oai16data = ((CompoundShortDataset) result).getData();
24741                        if (is == 1) {
24742                                if (it.isOutputDouble()) {
24743                                        while (it.hasNext()) {
24744                                                final double ix = it.aDouble;
24745                                                short ox;
24746                                                ox = (short) toLong(Math.log(ix));
24747                                                oai16data[it.oIndex] = ox;
24748                                        }
24749                                } else {
24750                                        while (it.hasNext()) {
24751                                                final long ix = it.aLong;
24752                                                short ox;
24753                                                ox = (short) toLong(Math.log(ix));
24754                                                oai16data[it.oIndex] = ox;
24755                                        }
24756                                }
24757                        } else if (as == 1) {
24758                                if (it.isOutputDouble()) {
24759                                        while (it.hasNext()) {
24760                                                final double ix = it.aDouble;
24761                                                short ox;
24762                                                ox = (short) toLong(Math.log(ix));
24763                                                for (int j = 0; j < is; j++) {
24764                                                        oai16data[it.oIndex + j] = ox;
24765                                                }
24766                                        }
24767                                } else {
24768                                        while (it.hasNext()) {
24769                                                final long ix = it.aLong;
24770                                                short ox;
24771                                                ox = (short) toLong(Math.log(ix));
24772                                                for (int j = 0; j < is; j++) {
24773                                                        oai16data[it.oIndex + j] = ox;
24774                                                }
24775                                        }
24776                                }
24777                        } else {
24778                                if (it.isOutputDouble()) {
24779                                        while (it.hasNext()) {
24780                                                for (int j = 0; j < is; j++) {
24781                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24782                                                        short ox;
24783                                                        ox = (short) toLong(Math.log(ix));
24784                                                        oai16data[it.oIndex + j] = ox;
24785                                                }
24786                                        }
24787                                } else {
24788                                        while (it.hasNext()) {
24789                                                for (int j = 0; j < is; j++) {
24790                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24791                                                        short ox;
24792                                                        ox = (short) toLong(Math.log(ix));
24793                                                        oai16data[it.oIndex + j] = ox;
24794                                                }
24795                                        }
24796                                }
24797                        }
24798                        break;
24799                case Dataset.ARRAYINT64:
24800                        final long[] oai64data = ((CompoundLongDataset) result).getData();
24801                        if (is == 1) {
24802                                if (it.isOutputDouble()) {
24803                                        while (it.hasNext()) {
24804                                                final double ix = it.aDouble;
24805                                                long ox;
24806                                                ox = toLong(Math.log(ix));
24807                                                oai64data[it.oIndex] = ox;
24808                                        }
24809                                } else {
24810                                        while (it.hasNext()) {
24811                                                final long ix = it.aLong;
24812                                                long ox;
24813                                                ox = toLong(Math.log(ix));
24814                                                oai64data[it.oIndex] = ox;
24815                                        }
24816                                }
24817                        } else if (as == 1) {
24818                                if (it.isOutputDouble()) {
24819                                        while (it.hasNext()) {
24820                                                final double ix = it.aDouble;
24821                                                long ox;
24822                                                ox = toLong(Math.log(ix));
24823                                                for (int j = 0; j < is; j++) {
24824                                                        oai64data[it.oIndex + j] = ox;
24825                                                }
24826                                        }
24827                                } else {
24828                                        while (it.hasNext()) {
24829                                                final long ix = it.aLong;
24830                                                long ox;
24831                                                ox = toLong(Math.log(ix));
24832                                                for (int j = 0; j < is; j++) {
24833                                                        oai64data[it.oIndex + j] = ox;
24834                                                }
24835                                        }
24836                                }
24837                        } else {
24838                                if (it.isOutputDouble()) {
24839                                        while (it.hasNext()) {
24840                                                for (int j = 0; j < is; j++) {
24841                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24842                                                        long ox;
24843                                                        ox = toLong(Math.log(ix));
24844                                                        oai64data[it.oIndex + j] = ox;
24845                                                }
24846                                        }
24847                                } else {
24848                                        while (it.hasNext()) {
24849                                                for (int j = 0; j < is; j++) {
24850                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24851                                                        long ox;
24852                                                        ox = toLong(Math.log(ix));
24853                                                        oai64data[it.oIndex + j] = ox;
24854                                                }
24855                                        }
24856                                }
24857                        }
24858                        break;
24859                case Dataset.ARRAYINT32:
24860                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
24861                        if (is == 1) {
24862                                if (it.isOutputDouble()) {
24863                                        while (it.hasNext()) {
24864                                                final double ix = it.aDouble;
24865                                                int ox;
24866                                                ox = (int) toLong(Math.log(ix));
24867                                                oai32data[it.oIndex] = ox;
24868                                        }
24869                                } else {
24870                                        while (it.hasNext()) {
24871                                                final long ix = it.aLong;
24872                                                int ox;
24873                                                ox = (int) toLong(Math.log(ix));
24874                                                oai32data[it.oIndex] = ox;
24875                                        }
24876                                }
24877                        } else if (as == 1) {
24878                                if (it.isOutputDouble()) {
24879                                        while (it.hasNext()) {
24880                                                final double ix = it.aDouble;
24881                                                int ox;
24882                                                ox = (int) toLong(Math.log(ix));
24883                                                for (int j = 0; j < is; j++) {
24884                                                        oai32data[it.oIndex + j] = ox;
24885                                                }
24886                                        }
24887                                } else {
24888                                        while (it.hasNext()) {
24889                                                final long ix = it.aLong;
24890                                                int ox;
24891                                                ox = (int) toLong(Math.log(ix));
24892                                                for (int j = 0; j < is; j++) {
24893                                                        oai32data[it.oIndex + j] = ox;
24894                                                }
24895                                        }
24896                                }
24897                        } else {
24898                                if (it.isOutputDouble()) {
24899                                        while (it.hasNext()) {
24900                                                for (int j = 0; j < is; j++) {
24901                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24902                                                        int ox;
24903                                                        ox = (int) toLong(Math.log(ix));
24904                                                        oai32data[it.oIndex + j] = ox;
24905                                                }
24906                                        }
24907                                } else {
24908                                        while (it.hasNext()) {
24909                                                for (int j = 0; j < is; j++) {
24910                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
24911                                                        int ox;
24912                                                        ox = (int) toLong(Math.log(ix));
24913                                                        oai32data[it.oIndex + j] = ox;
24914                                                }
24915                                        }
24916                                }
24917                        }
24918                        break;
24919                case Dataset.FLOAT32:
24920                        final float[] of32data = ((FloatDataset) result).getData();
24921                        if (it.isOutputDouble()) {
24922                                while (it.hasNext()) {
24923                                        final double ix = it.aDouble;
24924                                        float ox;
24925                                        ox = (float) (Math.log(ix));
24926                                        of32data[it.oIndex] = ox;
24927                                }
24928                        } else {
24929                                while (it.hasNext()) {
24930                                        final long ix = it.aLong;
24931                                        float ox;
24932                                        ox = (float) (Math.log(ix));
24933                                        of32data[it.oIndex] = ox;
24934                                }
24935                        }
24936                        break;
24937                case Dataset.FLOAT64:
24938                        final double[] of64data = ((DoubleDataset) result).getData();
24939                        if (it.isOutputDouble()) {
24940                                while (it.hasNext()) {
24941                                        final double ix = it.aDouble;
24942                                        double ox;
24943                                        ox = (Math.log(ix));
24944                                        of64data[it.oIndex] = ox;
24945                                }
24946                        } else {
24947                                while (it.hasNext()) {
24948                                        final long ix = it.aLong;
24949                                        double ox;
24950                                        ox = (Math.log(ix));
24951                                        of64data[it.oIndex] = ox;
24952                                }
24953                        }
24954                        break;
24955                case Dataset.ARRAYFLOAT32:
24956                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
24957                        if (is == 1) {
24958                                if (it.isOutputDouble()) {
24959                                        while (it.hasNext()) {
24960                                                final double ix = it.aDouble;
24961                                                float ox;
24962                                                ox = (float) (Math.log(ix));
24963                                                oaf32data[it.oIndex] = ox;
24964                                        }
24965                                } else {
24966                                        while (it.hasNext()) {
24967                                                final long ix = it.aLong;
24968                                                float ox;
24969                                                ox = (float) (Math.log(ix));
24970                                                oaf32data[it.oIndex] = ox;
24971                                        }
24972                                }
24973                        } else if (as == 1) {
24974                                if (it.isOutputDouble()) {
24975                                        while (it.hasNext()) {
24976                                                final double ix = it.aDouble;
24977                                                float ox;
24978                                                ox = (float) (Math.log(ix));
24979                                                for (int j = 0; j < is; j++) {
24980                                                        oaf32data[it.oIndex + j] = ox;
24981                                                }
24982                                        }
24983                                } else {
24984                                        while (it.hasNext()) {
24985                                                final long ix = it.aLong;
24986                                                float ox;
24987                                                ox = (float) (Math.log(ix));
24988                                                for (int j = 0; j < is; j++) {
24989                                                        oaf32data[it.oIndex + j] = ox;
24990                                                }
24991                                        }
24992                                }
24993                        } else {
24994                                if (it.isOutputDouble()) {
24995                                        while (it.hasNext()) {
24996                                                for (int j = 0; j < is; j++) {
24997                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
24998                                                        float ox;
24999                                                        ox = (float) (Math.log(ix));
25000                                                        oaf32data[it.oIndex + j] = ox;
25001                                                }
25002                                        }
25003                                } else {
25004                                        while (it.hasNext()) {
25005                                                for (int j = 0; j < is; j++) {
25006                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25007                                                        float ox;
25008                                                        ox = (float) (Math.log(ix));
25009                                                        oaf32data[it.oIndex + j] = ox;
25010                                                }
25011                                        }
25012                                }
25013                        }
25014                        break;
25015                case Dataset.ARRAYFLOAT64:
25016                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
25017                        if (is == 1) {
25018                                if (it.isOutputDouble()) {
25019                                        while (it.hasNext()) {
25020                                                final double ix = it.aDouble;
25021                                                double ox;
25022                                                ox = (Math.log(ix));
25023                                                oaf64data[it.oIndex] = ox;
25024                                        }
25025                                } else {
25026                                        while (it.hasNext()) {
25027                                                final long ix = it.aLong;
25028                                                double ox;
25029                                                ox = (Math.log(ix));
25030                                                oaf64data[it.oIndex] = ox;
25031                                        }
25032                                }
25033                        } else if (as == 1) {
25034                                if (it.isOutputDouble()) {
25035                                        while (it.hasNext()) {
25036                                                final double ix = it.aDouble;
25037                                                double ox;
25038                                                ox = (Math.log(ix));
25039                                                for (int j = 0; j < is; j++) {
25040                                                        oaf64data[it.oIndex + j] = ox;
25041                                                }
25042                                        }
25043                                } else {
25044                                        while (it.hasNext()) {
25045                                                final long ix = it.aLong;
25046                                                double ox;
25047                                                ox = (Math.log(ix));
25048                                                for (int j = 0; j < is; j++) {
25049                                                        oaf64data[it.oIndex + j] = ox;
25050                                                }
25051                                        }
25052                                }
25053                        } else {
25054                                if (it.isOutputDouble()) {
25055                                        while (it.hasNext()) {
25056                                                for (int j = 0; j < is; j++) {
25057                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25058                                                        double ox;
25059                                                        ox = (Math.log(ix));
25060                                                        oaf64data[it.oIndex + j] = ox;
25061                                                }
25062                                        }
25063                                } else {
25064                                        while (it.hasNext()) {
25065                                                for (int j = 0; j < is; j++) {
25066                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25067                                                        double ox;
25068                                                        ox = (Math.log(ix));
25069                                                        oaf64data[it.oIndex + j] = ox;
25070                                                }
25071                                        }
25072                                }
25073                        }
25074                        break;
25075                case Dataset.COMPLEX64:
25076                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
25077                        if (!da.isComplex()) {
25078                                if (it.isOutputDouble()) {
25079                                        final double iy = 0;
25080                                        while (it.hasNext()) {
25081                                                final double ix = it.aDouble;
25082                                                float ox;
25083                                                float oy;
25084                                                ox = (float) (Math.log(Math.hypot(ix, iy)));
25085                                                oy = (float) (Math.atan2(iy, ix));
25086                                                oc64data[it.oIndex] = ox;
25087                                                oc64data[it.oIndex + 1] = oy;
25088                                        }
25089                                } else {
25090                                        final long iy = 0;
25091                                        while (it.hasNext()) {
25092                                                final long ix = it.aLong;
25093                                                float ox;
25094                                                float oy;
25095                                                ox = (float) toLong(Math.log(Math.hypot(ix, iy)));
25096                                                oy = (float) toLong(Math.atan2(iy, ix));
25097                                                oc64data[it.oIndex] = ox;
25098                                                oc64data[it.oIndex + 1] = oy;
25099                                        }
25100                                }
25101                        } else {
25102                                while (it.hasNext()) {
25103                                        final double ix = it.aDouble;
25104                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
25105                                        float ox;
25106                                        float oy;
25107                                        ox = (float) (Math.log(Math.hypot(ix, iy)));
25108                                        oy = (float) (Math.atan2(iy, ix));
25109                                        oc64data[it.oIndex] = ox;
25110                                        oc64data[it.oIndex + 1] = oy;
25111                                }
25112                        }
25113                        break;
25114                case Dataset.COMPLEX128:
25115                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
25116                        if (!da.isComplex()) {
25117                                if (it.isOutputDouble()) {
25118                                        final double iy = 0;
25119                                        while (it.hasNext()) {
25120                                                final double ix = it.aDouble;
25121                                                double ox;
25122                                                double oy;
25123                                                ox = (Math.log(Math.hypot(ix, iy)));
25124                                                oy = (Math.atan2(iy, ix));
25125                                                oc128data[it.oIndex] = ox;
25126                                                oc128data[it.oIndex + 1] = oy;
25127                                        }
25128                                } else {
25129                                        final long iy = 0;
25130                                        while (it.hasNext()) {
25131                                                final long ix = it.aLong;
25132                                                double ox;
25133                                                double oy;
25134                                                ox = (double) (Math.log(Math.hypot(ix, iy)));
25135                                                oy = (double) (Math.atan2(iy, ix));
25136                                                oc128data[it.oIndex] = ox;
25137                                                oc128data[it.oIndex + 1] = oy;
25138                                        }
25139                                }
25140                        } else {
25141                                while (it.hasNext()) {
25142                                        final double ix = it.aDouble;
25143                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
25144                                        double ox;
25145                                        double oy;
25146                                        ox = (Math.log(Math.hypot(ix, iy)));
25147                                        oy = (Math.atan2(iy, ix));
25148                                        oc128data[it.oIndex] = ox;
25149                                        oc128data[it.oIndex + 1] = oy;
25150                                }
25151                        }
25152                        break;
25153                default:
25154                        throw new IllegalArgumentException("log supports integer, compound integer, real, compound real, complex datasets only");
25155                }
25156
25157                addFunctionName(result, "log");
25158                return result;
25159        }
25160
25161        /**
25162         * log2 - evaluate the logarithm function on each element of the dataset
25163         * @param a single operand
25164         * @return dataset
25165         */
25166        public static Dataset log2(final Object a) {
25167                return log2(a, null);
25168        }
25169
25170        /**
25171         * log2 - evaluate the logarithm function on each element of the dataset
25172         * @param a single operand
25173         * @param o output can be null - in which case, a new dataset is created
25174         * @return dataset
25175         */
25176        public static Dataset log2(final Object a, final Dataset o) {
25177                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
25178                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
25179                final Dataset result = it.getOutput();
25180                if (!result.isComplex()) {
25181                        if (da.isComplex()) {
25182                                da = da.getRealView();
25183                                it = new SingleInputBroadcastIterator(da, result, true);
25184                        }
25185                }
25186                final int is = result.getElementsPerItem();
25187                final int as = da.getElementsPerItem();
25188                final int dt = result.getDType();
25189
25190                switch(dt) {
25191                case Dataset.INT8:
25192                        final byte[] oi8data = ((ByteDataset) result).getData();
25193                        if (it.isOutputDouble()) {
25194                                while (it.hasNext()) {
25195                                        final double ix = it.aDouble;
25196                                        byte ox;
25197                                        ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25198                                        oi8data[it.oIndex] = ox;
25199                                }
25200                        } else {
25201                                while (it.hasNext()) {
25202                                        final long ix = it.aLong;
25203                                        byte ox;
25204                                        ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25205                                        oi8data[it.oIndex] = ox;
25206                                }
25207                        }
25208                        break;
25209                case Dataset.INT16:
25210                        final short[] oi16data = ((ShortDataset) result).getData();
25211                        if (it.isOutputDouble()) {
25212                                while (it.hasNext()) {
25213                                        final double ix = it.aDouble;
25214                                        short ox;
25215                                        ox = (short) toLong(Math.log(ix)/Math.log(2.));
25216                                        oi16data[it.oIndex] = ox;
25217                                }
25218                        } else {
25219                                while (it.hasNext()) {
25220                                        final long ix = it.aLong;
25221                                        short ox;
25222                                        ox = (short) toLong(Math.log(ix)/Math.log(2.));
25223                                        oi16data[it.oIndex] = ox;
25224                                }
25225                        }
25226                        break;
25227                case Dataset.INT64:
25228                        final long[] oi64data = ((LongDataset) result).getData();
25229                        if (it.isOutputDouble()) {
25230                                while (it.hasNext()) {
25231                                        final double ix = it.aDouble;
25232                                        long ox;
25233                                        ox = toLong(Math.log(ix)/Math.log(2.));
25234                                        oi64data[it.oIndex] = ox;
25235                                }
25236                        } else {
25237                                while (it.hasNext()) {
25238                                        final long ix = it.aLong;
25239                                        long ox;
25240                                        ox = toLong(Math.log(ix)/Math.log(2.));
25241                                        oi64data[it.oIndex] = ox;
25242                                }
25243                        }
25244                        break;
25245                case Dataset.INT32:
25246                        final int[] oi32data = ((IntegerDataset) result).getData();
25247                        if (it.isOutputDouble()) {
25248                                while (it.hasNext()) {
25249                                        final double ix = it.aDouble;
25250                                        int ox;
25251                                        ox = (int) toLong(Math.log(ix)/Math.log(2.));
25252                                        oi32data[it.oIndex] = ox;
25253                                }
25254                        } else {
25255                                while (it.hasNext()) {
25256                                        final long ix = it.aLong;
25257                                        int ox;
25258                                        ox = (int) toLong(Math.log(ix)/Math.log(2.));
25259                                        oi32data[it.oIndex] = ox;
25260                                }
25261                        }
25262                        break;
25263                case Dataset.ARRAYINT8:
25264                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
25265                        if (is == 1) {
25266                                if (it.isOutputDouble()) {
25267                                        while (it.hasNext()) {
25268                                                final double ix = it.aDouble;
25269                                                byte ox;
25270                                                ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25271                                                oai8data[it.oIndex] = ox;
25272                                        }
25273                                } else {
25274                                        while (it.hasNext()) {
25275                                                final long ix = it.aLong;
25276                                                byte ox;
25277                                                ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25278                                                oai8data[it.oIndex] = ox;
25279                                        }
25280                                }
25281                        } else if (as == 1) {
25282                                if (it.isOutputDouble()) {
25283                                        while (it.hasNext()) {
25284                                                final double ix = it.aDouble;
25285                                                byte ox;
25286                                                ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25287                                                for (int j = 0; j < is; j++) {
25288                                                        oai8data[it.oIndex + j] = ox;
25289                                                }
25290                                        }
25291                                } else {
25292                                        while (it.hasNext()) {
25293                                                final long ix = it.aLong;
25294                                                byte ox;
25295                                                ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25296                                                for (int j = 0; j < is; j++) {
25297                                                        oai8data[it.oIndex + j] = ox;
25298                                                }
25299                                        }
25300                                }
25301                        } else {
25302                                if (it.isOutputDouble()) {
25303                                        while (it.hasNext()) {
25304                                                for (int j = 0; j < is; j++) {
25305                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25306                                                        byte ox;
25307                                                        ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25308                                                        oai8data[it.oIndex + j] = ox;
25309                                                }
25310                                        }
25311                                } else {
25312                                        while (it.hasNext()) {
25313                                                for (int j = 0; j < is; j++) {
25314                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25315                                                        byte ox;
25316                                                        ox = (byte) toLong(Math.log(ix)/Math.log(2.));
25317                                                        oai8data[it.oIndex + j] = ox;
25318                                                }
25319                                        }
25320                                }
25321                        }
25322                        break;
25323                case Dataset.ARRAYINT16:
25324                        final short[] oai16data = ((CompoundShortDataset) result).getData();
25325                        if (is == 1) {
25326                                if (it.isOutputDouble()) {
25327                                        while (it.hasNext()) {
25328                                                final double ix = it.aDouble;
25329                                                short ox;
25330                                                ox = (short) toLong(Math.log(ix)/Math.log(2.));
25331                                                oai16data[it.oIndex] = ox;
25332                                        }
25333                                } else {
25334                                        while (it.hasNext()) {
25335                                                final long ix = it.aLong;
25336                                                short ox;
25337                                                ox = (short) toLong(Math.log(ix)/Math.log(2.));
25338                                                oai16data[it.oIndex] = ox;
25339                                        }
25340                                }
25341                        } else if (as == 1) {
25342                                if (it.isOutputDouble()) {
25343                                        while (it.hasNext()) {
25344                                                final double ix = it.aDouble;
25345                                                short ox;
25346                                                ox = (short) toLong(Math.log(ix)/Math.log(2.));
25347                                                for (int j = 0; j < is; j++) {
25348                                                        oai16data[it.oIndex + j] = ox;
25349                                                }
25350                                        }
25351                                } else {
25352                                        while (it.hasNext()) {
25353                                                final long ix = it.aLong;
25354                                                short ox;
25355                                                ox = (short) toLong(Math.log(ix)/Math.log(2.));
25356                                                for (int j = 0; j < is; j++) {
25357                                                        oai16data[it.oIndex + j] = ox;
25358                                                }
25359                                        }
25360                                }
25361                        } else {
25362                                if (it.isOutputDouble()) {
25363                                        while (it.hasNext()) {
25364                                                for (int j = 0; j < is; j++) {
25365                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25366                                                        short ox;
25367                                                        ox = (short) toLong(Math.log(ix)/Math.log(2.));
25368                                                        oai16data[it.oIndex + j] = ox;
25369                                                }
25370                                        }
25371                                } else {
25372                                        while (it.hasNext()) {
25373                                                for (int j = 0; j < is; j++) {
25374                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25375                                                        short ox;
25376                                                        ox = (short) toLong(Math.log(ix)/Math.log(2.));
25377                                                        oai16data[it.oIndex + j] = ox;
25378                                                }
25379                                        }
25380                                }
25381                        }
25382                        break;
25383                case Dataset.ARRAYINT64:
25384                        final long[] oai64data = ((CompoundLongDataset) result).getData();
25385                        if (is == 1) {
25386                                if (it.isOutputDouble()) {
25387                                        while (it.hasNext()) {
25388                                                final double ix = it.aDouble;
25389                                                long ox;
25390                                                ox = toLong(Math.log(ix)/Math.log(2.));
25391                                                oai64data[it.oIndex] = ox;
25392                                        }
25393                                } else {
25394                                        while (it.hasNext()) {
25395                                                final long ix = it.aLong;
25396                                                long ox;
25397                                                ox = toLong(Math.log(ix)/Math.log(2.));
25398                                                oai64data[it.oIndex] = ox;
25399                                        }
25400                                }
25401                        } else if (as == 1) {
25402                                if (it.isOutputDouble()) {
25403                                        while (it.hasNext()) {
25404                                                final double ix = it.aDouble;
25405                                                long ox;
25406                                                ox = toLong(Math.log(ix)/Math.log(2.));
25407                                                for (int j = 0; j < is; j++) {
25408                                                        oai64data[it.oIndex + j] = ox;
25409                                                }
25410                                        }
25411                                } else {
25412                                        while (it.hasNext()) {
25413                                                final long ix = it.aLong;
25414                                                long ox;
25415                                                ox = toLong(Math.log(ix)/Math.log(2.));
25416                                                for (int j = 0; j < is; j++) {
25417                                                        oai64data[it.oIndex + j] = ox;
25418                                                }
25419                                        }
25420                                }
25421                        } else {
25422                                if (it.isOutputDouble()) {
25423                                        while (it.hasNext()) {
25424                                                for (int j = 0; j < is; j++) {
25425                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25426                                                        long ox;
25427                                                        ox = toLong(Math.log(ix)/Math.log(2.));
25428                                                        oai64data[it.oIndex + j] = ox;
25429                                                }
25430                                        }
25431                                } else {
25432                                        while (it.hasNext()) {
25433                                                for (int j = 0; j < is; j++) {
25434                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25435                                                        long ox;
25436                                                        ox = toLong(Math.log(ix)/Math.log(2.));
25437                                                        oai64data[it.oIndex + j] = ox;
25438                                                }
25439                                        }
25440                                }
25441                        }
25442                        break;
25443                case Dataset.ARRAYINT32:
25444                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
25445                        if (is == 1) {
25446                                if (it.isOutputDouble()) {
25447                                        while (it.hasNext()) {
25448                                                final double ix = it.aDouble;
25449                                                int ox;
25450                                                ox = (int) toLong(Math.log(ix)/Math.log(2.));
25451                                                oai32data[it.oIndex] = ox;
25452                                        }
25453                                } else {
25454                                        while (it.hasNext()) {
25455                                                final long ix = it.aLong;
25456                                                int ox;
25457                                                ox = (int) toLong(Math.log(ix)/Math.log(2.));
25458                                                oai32data[it.oIndex] = ox;
25459                                        }
25460                                }
25461                        } else if (as == 1) {
25462                                if (it.isOutputDouble()) {
25463                                        while (it.hasNext()) {
25464                                                final double ix = it.aDouble;
25465                                                int ox;
25466                                                ox = (int) toLong(Math.log(ix)/Math.log(2.));
25467                                                for (int j = 0; j < is; j++) {
25468                                                        oai32data[it.oIndex + j] = ox;
25469                                                }
25470                                        }
25471                                } else {
25472                                        while (it.hasNext()) {
25473                                                final long ix = it.aLong;
25474                                                int ox;
25475                                                ox = (int) toLong(Math.log(ix)/Math.log(2.));
25476                                                for (int j = 0; j < is; j++) {
25477                                                        oai32data[it.oIndex + j] = ox;
25478                                                }
25479                                        }
25480                                }
25481                        } else {
25482                                if (it.isOutputDouble()) {
25483                                        while (it.hasNext()) {
25484                                                for (int j = 0; j < is; j++) {
25485                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25486                                                        int ox;
25487                                                        ox = (int) toLong(Math.log(ix)/Math.log(2.));
25488                                                        oai32data[it.oIndex + j] = ox;
25489                                                }
25490                                        }
25491                                } else {
25492                                        while (it.hasNext()) {
25493                                                for (int j = 0; j < is; j++) {
25494                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25495                                                        int ox;
25496                                                        ox = (int) toLong(Math.log(ix)/Math.log(2.));
25497                                                        oai32data[it.oIndex + j] = ox;
25498                                                }
25499                                        }
25500                                }
25501                        }
25502                        break;
25503                case Dataset.FLOAT32:
25504                        final float[] of32data = ((FloatDataset) result).getData();
25505                        if (it.isOutputDouble()) {
25506                                while (it.hasNext()) {
25507                                        final double ix = it.aDouble;
25508                                        float ox;
25509                                        ox = (float) (Math.log(ix)/Math.log(2.));
25510                                        of32data[it.oIndex] = ox;
25511                                }
25512                        } else {
25513                                while (it.hasNext()) {
25514                                        final long ix = it.aLong;
25515                                        float ox;
25516                                        ox = (float) (Math.log(ix)/Math.log(2.));
25517                                        of32data[it.oIndex] = ox;
25518                                }
25519                        }
25520                        break;
25521                case Dataset.FLOAT64:
25522                        final double[] of64data = ((DoubleDataset) result).getData();
25523                        if (it.isOutputDouble()) {
25524                                while (it.hasNext()) {
25525                                        final double ix = it.aDouble;
25526                                        double ox;
25527                                        ox = (Math.log(ix)/Math.log(2.));
25528                                        of64data[it.oIndex] = ox;
25529                                }
25530                        } else {
25531                                while (it.hasNext()) {
25532                                        final long ix = it.aLong;
25533                                        double ox;
25534                                        ox = (Math.log(ix)/Math.log(2.));
25535                                        of64data[it.oIndex] = ox;
25536                                }
25537                        }
25538                        break;
25539                case Dataset.ARRAYFLOAT32:
25540                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
25541                        if (is == 1) {
25542                                if (it.isOutputDouble()) {
25543                                        while (it.hasNext()) {
25544                                                final double ix = it.aDouble;
25545                                                float ox;
25546                                                ox = (float) (Math.log(ix)/Math.log(2.));
25547                                                oaf32data[it.oIndex] = ox;
25548                                        }
25549                                } else {
25550                                        while (it.hasNext()) {
25551                                                final long ix = it.aLong;
25552                                                float ox;
25553                                                ox = (float) (Math.log(ix)/Math.log(2.));
25554                                                oaf32data[it.oIndex] = ox;
25555                                        }
25556                                }
25557                        } else if (as == 1) {
25558                                if (it.isOutputDouble()) {
25559                                        while (it.hasNext()) {
25560                                                final double ix = it.aDouble;
25561                                                float ox;
25562                                                ox = (float) (Math.log(ix)/Math.log(2.));
25563                                                for (int j = 0; j < is; j++) {
25564                                                        oaf32data[it.oIndex + j] = ox;
25565                                                }
25566                                        }
25567                                } else {
25568                                        while (it.hasNext()) {
25569                                                final long ix = it.aLong;
25570                                                float ox;
25571                                                ox = (float) (Math.log(ix)/Math.log(2.));
25572                                                for (int j = 0; j < is; j++) {
25573                                                        oaf32data[it.oIndex + j] = ox;
25574                                                }
25575                                        }
25576                                }
25577                        } else {
25578                                if (it.isOutputDouble()) {
25579                                        while (it.hasNext()) {
25580                                                for (int j = 0; j < is; j++) {
25581                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25582                                                        float ox;
25583                                                        ox = (float) (Math.log(ix)/Math.log(2.));
25584                                                        oaf32data[it.oIndex + j] = ox;
25585                                                }
25586                                        }
25587                                } else {
25588                                        while (it.hasNext()) {
25589                                                for (int j = 0; j < is; j++) {
25590                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25591                                                        float ox;
25592                                                        ox = (float) (Math.log(ix)/Math.log(2.));
25593                                                        oaf32data[it.oIndex + j] = ox;
25594                                                }
25595                                        }
25596                                }
25597                        }
25598                        break;
25599                case Dataset.ARRAYFLOAT64:
25600                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
25601                        if (is == 1) {
25602                                if (it.isOutputDouble()) {
25603                                        while (it.hasNext()) {
25604                                                final double ix = it.aDouble;
25605                                                double ox;
25606                                                ox = (Math.log(ix)/Math.log(2.));
25607                                                oaf64data[it.oIndex] = ox;
25608                                        }
25609                                } else {
25610                                        while (it.hasNext()) {
25611                                                final long ix = it.aLong;
25612                                                double ox;
25613                                                ox = (Math.log(ix)/Math.log(2.));
25614                                                oaf64data[it.oIndex] = ox;
25615                                        }
25616                                }
25617                        } else if (as == 1) {
25618                                if (it.isOutputDouble()) {
25619                                        while (it.hasNext()) {
25620                                                final double ix = it.aDouble;
25621                                                double ox;
25622                                                ox = (Math.log(ix)/Math.log(2.));
25623                                                for (int j = 0; j < is; j++) {
25624                                                        oaf64data[it.oIndex + j] = ox;
25625                                                }
25626                                        }
25627                                } else {
25628                                        while (it.hasNext()) {
25629                                                final long ix = it.aLong;
25630                                                double ox;
25631                                                ox = (Math.log(ix)/Math.log(2.));
25632                                                for (int j = 0; j < is; j++) {
25633                                                        oaf64data[it.oIndex + j] = ox;
25634                                                }
25635                                        }
25636                                }
25637                        } else {
25638                                if (it.isOutputDouble()) {
25639                                        while (it.hasNext()) {
25640                                                for (int j = 0; j < is; j++) {
25641                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25642                                                        double ox;
25643                                                        ox = (Math.log(ix)/Math.log(2.));
25644                                                        oaf64data[it.oIndex + j] = ox;
25645                                                }
25646                                        }
25647                                } else {
25648                                        while (it.hasNext()) {
25649                                                for (int j = 0; j < is; j++) {
25650                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25651                                                        double ox;
25652                                                        ox = (Math.log(ix)/Math.log(2.));
25653                                                        oaf64data[it.oIndex + j] = ox;
25654                                                }
25655                                        }
25656                                }
25657                        }
25658                        break;
25659                case Dataset.COMPLEX64:
25660                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
25661                        if (!da.isComplex()) {
25662                                if (it.isOutputDouble()) {
25663                                        final double iy = 0;
25664                                        while (it.hasNext()) {
25665                                                final double ix = it.aDouble;
25666                                                float ox;
25667                                                float oy;
25668                                                ox = (float) (Math.log(Math.hypot(ix, iy))/Math.log(2.));
25669                                                oy = (float) (Math.atan2(iy, ix));
25670                                                oc64data[it.oIndex] = ox;
25671                                                oc64data[it.oIndex + 1] = oy;
25672                                        }
25673                                } else {
25674                                        final long iy = 0;
25675                                        while (it.hasNext()) {
25676                                                final long ix = it.aLong;
25677                                                float ox;
25678                                                float oy;
25679                                                ox = (float) toLong(Math.log(Math.hypot(ix, iy))/Math.log(2.));
25680                                                oy = (float) toLong(Math.atan2(iy, ix));
25681                                                oc64data[it.oIndex] = ox;
25682                                                oc64data[it.oIndex + 1] = oy;
25683                                        }
25684                                }
25685                        } else {
25686                                while (it.hasNext()) {
25687                                        final double ix = it.aDouble;
25688                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
25689                                        float ox;
25690                                        float oy;
25691                                        ox = (float) (Math.log(Math.hypot(ix, iy))/Math.log(2.));
25692                                        oy = (float) (Math.atan2(iy, ix));
25693                                        oc64data[it.oIndex] = ox;
25694                                        oc64data[it.oIndex + 1] = oy;
25695                                }
25696                        }
25697                        break;
25698                case Dataset.COMPLEX128:
25699                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
25700                        if (!da.isComplex()) {
25701                                if (it.isOutputDouble()) {
25702                                        final double iy = 0;
25703                                        while (it.hasNext()) {
25704                                                final double ix = it.aDouble;
25705                                                double ox;
25706                                                double oy;
25707                                                ox = (Math.log(Math.hypot(ix, iy))/Math.log(2.));
25708                                                oy = (Math.atan2(iy, ix));
25709                                                oc128data[it.oIndex] = ox;
25710                                                oc128data[it.oIndex + 1] = oy;
25711                                        }
25712                                } else {
25713                                        final long iy = 0;
25714                                        while (it.hasNext()) {
25715                                                final long ix = it.aLong;
25716                                                double ox;
25717                                                double oy;
25718                                                ox = (double) (Math.log(Math.hypot(ix, iy))/Math.log(2.));
25719                                                oy = (double) (Math.atan2(iy, ix));
25720                                                oc128data[it.oIndex] = ox;
25721                                                oc128data[it.oIndex + 1] = oy;
25722                                        }
25723                                }
25724                        } else {
25725                                while (it.hasNext()) {
25726                                        final double ix = it.aDouble;
25727                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
25728                                        double ox;
25729                                        double oy;
25730                                        ox = (Math.log(Math.hypot(ix, iy))/Math.log(2.));
25731                                        oy = (Math.atan2(iy, ix));
25732                                        oc128data[it.oIndex] = ox;
25733                                        oc128data[it.oIndex + 1] = oy;
25734                                }
25735                        }
25736                        break;
25737                default:
25738                        throw new IllegalArgumentException("log2 supports integer, compound integer, real, compound real, complex datasets only");
25739                }
25740
25741                addFunctionName(result, "log2");
25742                return result;
25743        }
25744
25745        /**
25746         * log10 - evaluate the logarithm function on each element of the dataset
25747         * @param a single operand
25748         * @return dataset
25749         */
25750        public static Dataset log10(final Object a) {
25751                return log10(a, null);
25752        }
25753
25754        /**
25755         * log10 - evaluate the logarithm function on each element of the dataset
25756         * @param a single operand
25757         * @param o output can be null - in which case, a new dataset is created
25758         * @return dataset
25759         */
25760        public static Dataset log10(final Object a, final Dataset o) {
25761                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
25762                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
25763                final Dataset result = it.getOutput();
25764                if (!result.isComplex()) {
25765                        if (da.isComplex()) {
25766                                da = da.getRealView();
25767                                it = new SingleInputBroadcastIterator(da, result, true);
25768                        }
25769                }
25770                final int is = result.getElementsPerItem();
25771                final int as = da.getElementsPerItem();
25772                final int dt = result.getDType();
25773
25774                switch(dt) {
25775                case Dataset.INT8:
25776                        final byte[] oi8data = ((ByteDataset) result).getData();
25777                        if (it.isOutputDouble()) {
25778                                while (it.hasNext()) {
25779                                        final double ix = it.aDouble;
25780                                        byte ox;
25781                                        ox = (byte) toLong(Math.log10(ix));
25782                                        oi8data[it.oIndex] = ox;
25783                                }
25784                        } else {
25785                                while (it.hasNext()) {
25786                                        final long ix = it.aLong;
25787                                        byte ox;
25788                                        ox = (byte) toLong(Math.log10(ix));
25789                                        oi8data[it.oIndex] = ox;
25790                                }
25791                        }
25792                        break;
25793                case Dataset.INT16:
25794                        final short[] oi16data = ((ShortDataset) result).getData();
25795                        if (it.isOutputDouble()) {
25796                                while (it.hasNext()) {
25797                                        final double ix = it.aDouble;
25798                                        short ox;
25799                                        ox = (short) toLong(Math.log10(ix));
25800                                        oi16data[it.oIndex] = ox;
25801                                }
25802                        } else {
25803                                while (it.hasNext()) {
25804                                        final long ix = it.aLong;
25805                                        short ox;
25806                                        ox = (short) toLong(Math.log10(ix));
25807                                        oi16data[it.oIndex] = ox;
25808                                }
25809                        }
25810                        break;
25811                case Dataset.INT64:
25812                        final long[] oi64data = ((LongDataset) result).getData();
25813                        if (it.isOutputDouble()) {
25814                                while (it.hasNext()) {
25815                                        final double ix = it.aDouble;
25816                                        long ox;
25817                                        ox = toLong(Math.log10(ix));
25818                                        oi64data[it.oIndex] = ox;
25819                                }
25820                        } else {
25821                                while (it.hasNext()) {
25822                                        final long ix = it.aLong;
25823                                        long ox;
25824                                        ox = toLong(Math.log10(ix));
25825                                        oi64data[it.oIndex] = ox;
25826                                }
25827                        }
25828                        break;
25829                case Dataset.INT32:
25830                        final int[] oi32data = ((IntegerDataset) result).getData();
25831                        if (it.isOutputDouble()) {
25832                                while (it.hasNext()) {
25833                                        final double ix = it.aDouble;
25834                                        int ox;
25835                                        ox = (int) toLong(Math.log10(ix));
25836                                        oi32data[it.oIndex] = ox;
25837                                }
25838                        } else {
25839                                while (it.hasNext()) {
25840                                        final long ix = it.aLong;
25841                                        int ox;
25842                                        ox = (int) toLong(Math.log10(ix));
25843                                        oi32data[it.oIndex] = ox;
25844                                }
25845                        }
25846                        break;
25847                case Dataset.ARRAYINT8:
25848                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
25849                        if (is == 1) {
25850                                if (it.isOutputDouble()) {
25851                                        while (it.hasNext()) {
25852                                                final double ix = it.aDouble;
25853                                                byte ox;
25854                                                ox = (byte) toLong(Math.log10(ix));
25855                                                oai8data[it.oIndex] = ox;
25856                                        }
25857                                } else {
25858                                        while (it.hasNext()) {
25859                                                final long ix = it.aLong;
25860                                                byte ox;
25861                                                ox = (byte) toLong(Math.log10(ix));
25862                                                oai8data[it.oIndex] = ox;
25863                                        }
25864                                }
25865                        } else if (as == 1) {
25866                                if (it.isOutputDouble()) {
25867                                        while (it.hasNext()) {
25868                                                final double ix = it.aDouble;
25869                                                byte ox;
25870                                                ox = (byte) toLong(Math.log10(ix));
25871                                                for (int j = 0; j < is; j++) {
25872                                                        oai8data[it.oIndex + j] = ox;
25873                                                }
25874                                        }
25875                                } else {
25876                                        while (it.hasNext()) {
25877                                                final long ix = it.aLong;
25878                                                byte ox;
25879                                                ox = (byte) toLong(Math.log10(ix));
25880                                                for (int j = 0; j < is; j++) {
25881                                                        oai8data[it.oIndex + j] = ox;
25882                                                }
25883                                        }
25884                                }
25885                        } else {
25886                                if (it.isOutputDouble()) {
25887                                        while (it.hasNext()) {
25888                                                for (int j = 0; j < is; j++) {
25889                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25890                                                        byte ox;
25891                                                        ox = (byte) toLong(Math.log10(ix));
25892                                                        oai8data[it.oIndex + j] = ox;
25893                                                }
25894                                        }
25895                                } else {
25896                                        while (it.hasNext()) {
25897                                                for (int j = 0; j < is; j++) {
25898                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25899                                                        byte ox;
25900                                                        ox = (byte) toLong(Math.log10(ix));
25901                                                        oai8data[it.oIndex + j] = ox;
25902                                                }
25903                                        }
25904                                }
25905                        }
25906                        break;
25907                case Dataset.ARRAYINT16:
25908                        final short[] oai16data = ((CompoundShortDataset) result).getData();
25909                        if (is == 1) {
25910                                if (it.isOutputDouble()) {
25911                                        while (it.hasNext()) {
25912                                                final double ix = it.aDouble;
25913                                                short ox;
25914                                                ox = (short) toLong(Math.log10(ix));
25915                                                oai16data[it.oIndex] = ox;
25916                                        }
25917                                } else {
25918                                        while (it.hasNext()) {
25919                                                final long ix = it.aLong;
25920                                                short ox;
25921                                                ox = (short) toLong(Math.log10(ix));
25922                                                oai16data[it.oIndex] = ox;
25923                                        }
25924                                }
25925                        } else if (as == 1) {
25926                                if (it.isOutputDouble()) {
25927                                        while (it.hasNext()) {
25928                                                final double ix = it.aDouble;
25929                                                short ox;
25930                                                ox = (short) toLong(Math.log10(ix));
25931                                                for (int j = 0; j < is; j++) {
25932                                                        oai16data[it.oIndex + j] = ox;
25933                                                }
25934                                        }
25935                                } else {
25936                                        while (it.hasNext()) {
25937                                                final long ix = it.aLong;
25938                                                short ox;
25939                                                ox = (short) toLong(Math.log10(ix));
25940                                                for (int j = 0; j < is; j++) {
25941                                                        oai16data[it.oIndex + j] = ox;
25942                                                }
25943                                        }
25944                                }
25945                        } else {
25946                                if (it.isOutputDouble()) {
25947                                        while (it.hasNext()) {
25948                                                for (int j = 0; j < is; j++) {
25949                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
25950                                                        short ox;
25951                                                        ox = (short) toLong(Math.log10(ix));
25952                                                        oai16data[it.oIndex + j] = ox;
25953                                                }
25954                                        }
25955                                } else {
25956                                        while (it.hasNext()) {
25957                                                for (int j = 0; j < is; j++) {
25958                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
25959                                                        short ox;
25960                                                        ox = (short) toLong(Math.log10(ix));
25961                                                        oai16data[it.oIndex + j] = ox;
25962                                                }
25963                                        }
25964                                }
25965                        }
25966                        break;
25967                case Dataset.ARRAYINT64:
25968                        final long[] oai64data = ((CompoundLongDataset) result).getData();
25969                        if (is == 1) {
25970                                if (it.isOutputDouble()) {
25971                                        while (it.hasNext()) {
25972                                                final double ix = it.aDouble;
25973                                                long ox;
25974                                                ox = toLong(Math.log10(ix));
25975                                                oai64data[it.oIndex] = ox;
25976                                        }
25977                                } else {
25978                                        while (it.hasNext()) {
25979                                                final long ix = it.aLong;
25980                                                long ox;
25981                                                ox = toLong(Math.log10(ix));
25982                                                oai64data[it.oIndex] = ox;
25983                                        }
25984                                }
25985                        } else if (as == 1) {
25986                                if (it.isOutputDouble()) {
25987                                        while (it.hasNext()) {
25988                                                final double ix = it.aDouble;
25989                                                long ox;
25990                                                ox = toLong(Math.log10(ix));
25991                                                for (int j = 0; j < is; j++) {
25992                                                        oai64data[it.oIndex + j] = ox;
25993                                                }
25994                                        }
25995                                } else {
25996                                        while (it.hasNext()) {
25997                                                final long ix = it.aLong;
25998                                                long ox;
25999                                                ox = toLong(Math.log10(ix));
26000                                                for (int j = 0; j < is; j++) {
26001                                                        oai64data[it.oIndex + j] = ox;
26002                                                }
26003                                        }
26004                                }
26005                        } else {
26006                                if (it.isOutputDouble()) {
26007                                        while (it.hasNext()) {
26008                                                for (int j = 0; j < is; j++) {
26009                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26010                                                        long ox;
26011                                                        ox = toLong(Math.log10(ix));
26012                                                        oai64data[it.oIndex + j] = ox;
26013                                                }
26014                                        }
26015                                } else {
26016                                        while (it.hasNext()) {
26017                                                for (int j = 0; j < is; j++) {
26018                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26019                                                        long ox;
26020                                                        ox = toLong(Math.log10(ix));
26021                                                        oai64data[it.oIndex + j] = ox;
26022                                                }
26023                                        }
26024                                }
26025                        }
26026                        break;
26027                case Dataset.ARRAYINT32:
26028                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
26029                        if (is == 1) {
26030                                if (it.isOutputDouble()) {
26031                                        while (it.hasNext()) {
26032                                                final double ix = it.aDouble;
26033                                                int ox;
26034                                                ox = (int) toLong(Math.log10(ix));
26035                                                oai32data[it.oIndex] = ox;
26036                                        }
26037                                } else {
26038                                        while (it.hasNext()) {
26039                                                final long ix = it.aLong;
26040                                                int ox;
26041                                                ox = (int) toLong(Math.log10(ix));
26042                                                oai32data[it.oIndex] = ox;
26043                                        }
26044                                }
26045                        } else if (as == 1) {
26046                                if (it.isOutputDouble()) {
26047                                        while (it.hasNext()) {
26048                                                final double ix = it.aDouble;
26049                                                int ox;
26050                                                ox = (int) toLong(Math.log10(ix));
26051                                                for (int j = 0; j < is; j++) {
26052                                                        oai32data[it.oIndex + j] = ox;
26053                                                }
26054                                        }
26055                                } else {
26056                                        while (it.hasNext()) {
26057                                                final long ix = it.aLong;
26058                                                int ox;
26059                                                ox = (int) toLong(Math.log10(ix));
26060                                                for (int j = 0; j < is; j++) {
26061                                                        oai32data[it.oIndex + j] = ox;
26062                                                }
26063                                        }
26064                                }
26065                        } else {
26066                                if (it.isOutputDouble()) {
26067                                        while (it.hasNext()) {
26068                                                for (int j = 0; j < is; j++) {
26069                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26070                                                        int ox;
26071                                                        ox = (int) toLong(Math.log10(ix));
26072                                                        oai32data[it.oIndex + j] = ox;
26073                                                }
26074                                        }
26075                                } else {
26076                                        while (it.hasNext()) {
26077                                                for (int j = 0; j < is; j++) {
26078                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26079                                                        int ox;
26080                                                        ox = (int) toLong(Math.log10(ix));
26081                                                        oai32data[it.oIndex + j] = ox;
26082                                                }
26083                                        }
26084                                }
26085                        }
26086                        break;
26087                case Dataset.FLOAT32:
26088                        final float[] of32data = ((FloatDataset) result).getData();
26089                        if (it.isOutputDouble()) {
26090                                while (it.hasNext()) {
26091                                        final double ix = it.aDouble;
26092                                        float ox;
26093                                        ox = (float) (Math.log10(ix));
26094                                        of32data[it.oIndex] = ox;
26095                                }
26096                        } else {
26097                                while (it.hasNext()) {
26098                                        final long ix = it.aLong;
26099                                        float ox;
26100                                        ox = (float) (Math.log10(ix));
26101                                        of32data[it.oIndex] = ox;
26102                                }
26103                        }
26104                        break;
26105                case Dataset.FLOAT64:
26106                        final double[] of64data = ((DoubleDataset) result).getData();
26107                        if (it.isOutputDouble()) {
26108                                while (it.hasNext()) {
26109                                        final double ix = it.aDouble;
26110                                        double ox;
26111                                        ox = (Math.log10(ix));
26112                                        of64data[it.oIndex] = ox;
26113                                }
26114                        } else {
26115                                while (it.hasNext()) {
26116                                        final long ix = it.aLong;
26117                                        double ox;
26118                                        ox = (Math.log10(ix));
26119                                        of64data[it.oIndex] = ox;
26120                                }
26121                        }
26122                        break;
26123                case Dataset.ARRAYFLOAT32:
26124                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
26125                        if (is == 1) {
26126                                if (it.isOutputDouble()) {
26127                                        while (it.hasNext()) {
26128                                                final double ix = it.aDouble;
26129                                                float ox;
26130                                                ox = (float) (Math.log10(ix));
26131                                                oaf32data[it.oIndex] = ox;
26132                                        }
26133                                } else {
26134                                        while (it.hasNext()) {
26135                                                final long ix = it.aLong;
26136                                                float ox;
26137                                                ox = (float) (Math.log10(ix));
26138                                                oaf32data[it.oIndex] = ox;
26139                                        }
26140                                }
26141                        } else if (as == 1) {
26142                                if (it.isOutputDouble()) {
26143                                        while (it.hasNext()) {
26144                                                final double ix = it.aDouble;
26145                                                float ox;
26146                                                ox = (float) (Math.log10(ix));
26147                                                for (int j = 0; j < is; j++) {
26148                                                        oaf32data[it.oIndex + j] = ox;
26149                                                }
26150                                        }
26151                                } else {
26152                                        while (it.hasNext()) {
26153                                                final long ix = it.aLong;
26154                                                float ox;
26155                                                ox = (float) (Math.log10(ix));
26156                                                for (int j = 0; j < is; j++) {
26157                                                        oaf32data[it.oIndex + j] = ox;
26158                                                }
26159                                        }
26160                                }
26161                        } else {
26162                                if (it.isOutputDouble()) {
26163                                        while (it.hasNext()) {
26164                                                for (int j = 0; j < is; j++) {
26165                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26166                                                        float ox;
26167                                                        ox = (float) (Math.log10(ix));
26168                                                        oaf32data[it.oIndex + j] = ox;
26169                                                }
26170                                        }
26171                                } else {
26172                                        while (it.hasNext()) {
26173                                                for (int j = 0; j < is; j++) {
26174                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26175                                                        float ox;
26176                                                        ox = (float) (Math.log10(ix));
26177                                                        oaf32data[it.oIndex + j] = ox;
26178                                                }
26179                                        }
26180                                }
26181                        }
26182                        break;
26183                case Dataset.ARRAYFLOAT64:
26184                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
26185                        if (is == 1) {
26186                                if (it.isOutputDouble()) {
26187                                        while (it.hasNext()) {
26188                                                final double ix = it.aDouble;
26189                                                double ox;
26190                                                ox = (Math.log10(ix));
26191                                                oaf64data[it.oIndex] = ox;
26192                                        }
26193                                } else {
26194                                        while (it.hasNext()) {
26195                                                final long ix = it.aLong;
26196                                                double ox;
26197                                                ox = (Math.log10(ix));
26198                                                oaf64data[it.oIndex] = ox;
26199                                        }
26200                                }
26201                        } else if (as == 1) {
26202                                if (it.isOutputDouble()) {
26203                                        while (it.hasNext()) {
26204                                                final double ix = it.aDouble;
26205                                                double ox;
26206                                                ox = (Math.log10(ix));
26207                                                for (int j = 0; j < is; j++) {
26208                                                        oaf64data[it.oIndex + j] = ox;
26209                                                }
26210                                        }
26211                                } else {
26212                                        while (it.hasNext()) {
26213                                                final long ix = it.aLong;
26214                                                double ox;
26215                                                ox = (Math.log10(ix));
26216                                                for (int j = 0; j < is; j++) {
26217                                                        oaf64data[it.oIndex + j] = ox;
26218                                                }
26219                                        }
26220                                }
26221                        } else {
26222                                if (it.isOutputDouble()) {
26223                                        while (it.hasNext()) {
26224                                                for (int j = 0; j < is; j++) {
26225                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26226                                                        double ox;
26227                                                        ox = (Math.log10(ix));
26228                                                        oaf64data[it.oIndex + j] = ox;
26229                                                }
26230                                        }
26231                                } else {
26232                                        while (it.hasNext()) {
26233                                                for (int j = 0; j < is; j++) {
26234                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26235                                                        double ox;
26236                                                        ox = (Math.log10(ix));
26237                                                        oaf64data[it.oIndex + j] = ox;
26238                                                }
26239                                        }
26240                                }
26241                        }
26242                        break;
26243                case Dataset.COMPLEX64:
26244                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
26245                        if (!da.isComplex()) {
26246                                if (it.isOutputDouble()) {
26247                                        final double iy = 0;
26248                                        while (it.hasNext()) {
26249                                                final double ix = it.aDouble;
26250                                                float ox;
26251                                                float oy;
26252                                                ox = (float) (Math.log10(Math.hypot(ix, iy)));
26253                                                oy = (float) (Math.atan2(iy, ix));
26254                                                oc64data[it.oIndex] = ox;
26255                                                oc64data[it.oIndex + 1] = oy;
26256                                        }
26257                                } else {
26258                                        final long iy = 0;
26259                                        while (it.hasNext()) {
26260                                                final long ix = it.aLong;
26261                                                float ox;
26262                                                float oy;
26263                                                ox = (float) toLong(Math.log10(Math.hypot(ix, iy)));
26264                                                oy = (float) toLong(Math.atan2(iy, ix));
26265                                                oc64data[it.oIndex] = ox;
26266                                                oc64data[it.oIndex + 1] = oy;
26267                                        }
26268                                }
26269                        } else {
26270                                while (it.hasNext()) {
26271                                        final double ix = it.aDouble;
26272                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
26273                                        float ox;
26274                                        float oy;
26275                                        ox = (float) (Math.log10(Math.hypot(ix, iy)));
26276                                        oy = (float) (Math.atan2(iy, ix));
26277                                        oc64data[it.oIndex] = ox;
26278                                        oc64data[it.oIndex + 1] = oy;
26279                                }
26280                        }
26281                        break;
26282                case Dataset.COMPLEX128:
26283                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
26284                        if (!da.isComplex()) {
26285                                if (it.isOutputDouble()) {
26286                                        final double iy = 0;
26287                                        while (it.hasNext()) {
26288                                                final double ix = it.aDouble;
26289                                                double ox;
26290                                                double oy;
26291                                                ox = (Math.log10(Math.hypot(ix, iy)));
26292                                                oy = (Math.atan2(iy, ix));
26293                                                oc128data[it.oIndex] = ox;
26294                                                oc128data[it.oIndex + 1] = oy;
26295                                        }
26296                                } else {
26297                                        final long iy = 0;
26298                                        while (it.hasNext()) {
26299                                                final long ix = it.aLong;
26300                                                double ox;
26301                                                double oy;
26302                                                ox = (double) (Math.log10(Math.hypot(ix, iy)));
26303                                                oy = (double) (Math.atan2(iy, ix));
26304                                                oc128data[it.oIndex] = ox;
26305                                                oc128data[it.oIndex + 1] = oy;
26306                                        }
26307                                }
26308                        } else {
26309                                while (it.hasNext()) {
26310                                        final double ix = it.aDouble;
26311                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
26312                                        double ox;
26313                                        double oy;
26314                                        ox = (Math.log10(Math.hypot(ix, iy)));
26315                                        oy = (Math.atan2(iy, ix));
26316                                        oc128data[it.oIndex] = ox;
26317                                        oc128data[it.oIndex + 1] = oy;
26318                                }
26319                        }
26320                        break;
26321                default:
26322                        throw new IllegalArgumentException("log10 supports integer, compound integer, real, compound real, complex datasets only");
26323                }
26324
26325                addFunctionName(result, "log10");
26326                return result;
26327        }
26328
26329        /**
26330         * log1p - evaluate the logarithm function of 1 plus on each element of the dataset
26331         * @param a single operand
26332         * @return dataset
26333         */
26334        public static Dataset log1p(final Object a) {
26335                return log1p(a, null);
26336        }
26337
26338        /**
26339         * log1p - evaluate the logarithm function of 1 plus on each element of the dataset
26340         * @param a single operand
26341         * @param o output can be null - in which case, a new dataset is created
26342         * @return dataset
26343         */
26344        public static Dataset log1p(final Object a, final Dataset o) {
26345                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
26346                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
26347                final Dataset result = it.getOutput();
26348                if (!result.isComplex()) {
26349                        if (da.isComplex()) {
26350                                da = da.getRealView();
26351                                it = new SingleInputBroadcastIterator(da, result, true);
26352                        }
26353                }
26354                final int is = result.getElementsPerItem();
26355                final int as = da.getElementsPerItem();
26356                final int dt = result.getDType();
26357
26358                switch(dt) {
26359                case Dataset.INT8:
26360                        final byte[] oi8data = ((ByteDataset) result).getData();
26361                        if (it.isOutputDouble()) {
26362                                while (it.hasNext()) {
26363                                        final double ix = it.aDouble;
26364                                        byte ox;
26365                                        ox = (byte) toLong(Math.log1p(ix));
26366                                        oi8data[it.oIndex] = ox;
26367                                }
26368                        } else {
26369                                while (it.hasNext()) {
26370                                        final long ix = it.aLong;
26371                                        byte ox;
26372                                        ox = (byte) toLong(Math.log1p(ix));
26373                                        oi8data[it.oIndex] = ox;
26374                                }
26375                        }
26376                        break;
26377                case Dataset.INT16:
26378                        final short[] oi16data = ((ShortDataset) result).getData();
26379                        if (it.isOutputDouble()) {
26380                                while (it.hasNext()) {
26381                                        final double ix = it.aDouble;
26382                                        short ox;
26383                                        ox = (short) toLong(Math.log1p(ix));
26384                                        oi16data[it.oIndex] = ox;
26385                                }
26386                        } else {
26387                                while (it.hasNext()) {
26388                                        final long ix = it.aLong;
26389                                        short ox;
26390                                        ox = (short) toLong(Math.log1p(ix));
26391                                        oi16data[it.oIndex] = ox;
26392                                }
26393                        }
26394                        break;
26395                case Dataset.INT64:
26396                        final long[] oi64data = ((LongDataset) result).getData();
26397                        if (it.isOutputDouble()) {
26398                                while (it.hasNext()) {
26399                                        final double ix = it.aDouble;
26400                                        long ox;
26401                                        ox = toLong(Math.log1p(ix));
26402                                        oi64data[it.oIndex] = ox;
26403                                }
26404                        } else {
26405                                while (it.hasNext()) {
26406                                        final long ix = it.aLong;
26407                                        long ox;
26408                                        ox = toLong(Math.log1p(ix));
26409                                        oi64data[it.oIndex] = ox;
26410                                }
26411                        }
26412                        break;
26413                case Dataset.INT32:
26414                        final int[] oi32data = ((IntegerDataset) result).getData();
26415                        if (it.isOutputDouble()) {
26416                                while (it.hasNext()) {
26417                                        final double ix = it.aDouble;
26418                                        int ox;
26419                                        ox = (int) toLong(Math.log1p(ix));
26420                                        oi32data[it.oIndex] = ox;
26421                                }
26422                        } else {
26423                                while (it.hasNext()) {
26424                                        final long ix = it.aLong;
26425                                        int ox;
26426                                        ox = (int) toLong(Math.log1p(ix));
26427                                        oi32data[it.oIndex] = ox;
26428                                }
26429                        }
26430                        break;
26431                case Dataset.ARRAYINT8:
26432                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
26433                        if (is == 1) {
26434                                if (it.isOutputDouble()) {
26435                                        while (it.hasNext()) {
26436                                                final double ix = it.aDouble;
26437                                                byte ox;
26438                                                ox = (byte) toLong(Math.log1p(ix));
26439                                                oai8data[it.oIndex] = ox;
26440                                        }
26441                                } else {
26442                                        while (it.hasNext()) {
26443                                                final long ix = it.aLong;
26444                                                byte ox;
26445                                                ox = (byte) toLong(Math.log1p(ix));
26446                                                oai8data[it.oIndex] = ox;
26447                                        }
26448                                }
26449                        } else if (as == 1) {
26450                                if (it.isOutputDouble()) {
26451                                        while (it.hasNext()) {
26452                                                final double ix = it.aDouble;
26453                                                byte ox;
26454                                                ox = (byte) toLong(Math.log1p(ix));
26455                                                for (int j = 0; j < is; j++) {
26456                                                        oai8data[it.oIndex + j] = ox;
26457                                                }
26458                                        }
26459                                } else {
26460                                        while (it.hasNext()) {
26461                                                final long ix = it.aLong;
26462                                                byte ox;
26463                                                ox = (byte) toLong(Math.log1p(ix));
26464                                                for (int j = 0; j < is; j++) {
26465                                                        oai8data[it.oIndex + j] = ox;
26466                                                }
26467                                        }
26468                                }
26469                        } else {
26470                                if (it.isOutputDouble()) {
26471                                        while (it.hasNext()) {
26472                                                for (int j = 0; j < is; j++) {
26473                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26474                                                        byte ox;
26475                                                        ox = (byte) toLong(Math.log1p(ix));
26476                                                        oai8data[it.oIndex + j] = ox;
26477                                                }
26478                                        }
26479                                } else {
26480                                        while (it.hasNext()) {
26481                                                for (int j = 0; j < is; j++) {
26482                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26483                                                        byte ox;
26484                                                        ox = (byte) toLong(Math.log1p(ix));
26485                                                        oai8data[it.oIndex + j] = ox;
26486                                                }
26487                                        }
26488                                }
26489                        }
26490                        break;
26491                case Dataset.ARRAYINT16:
26492                        final short[] oai16data = ((CompoundShortDataset) result).getData();
26493                        if (is == 1) {
26494                                if (it.isOutputDouble()) {
26495                                        while (it.hasNext()) {
26496                                                final double ix = it.aDouble;
26497                                                short ox;
26498                                                ox = (short) toLong(Math.log1p(ix));
26499                                                oai16data[it.oIndex] = ox;
26500                                        }
26501                                } else {
26502                                        while (it.hasNext()) {
26503                                                final long ix = it.aLong;
26504                                                short ox;
26505                                                ox = (short) toLong(Math.log1p(ix));
26506                                                oai16data[it.oIndex] = ox;
26507                                        }
26508                                }
26509                        } else if (as == 1) {
26510                                if (it.isOutputDouble()) {
26511                                        while (it.hasNext()) {
26512                                                final double ix = it.aDouble;
26513                                                short ox;
26514                                                ox = (short) toLong(Math.log1p(ix));
26515                                                for (int j = 0; j < is; j++) {
26516                                                        oai16data[it.oIndex + j] = ox;
26517                                                }
26518                                        }
26519                                } else {
26520                                        while (it.hasNext()) {
26521                                                final long ix = it.aLong;
26522                                                short ox;
26523                                                ox = (short) toLong(Math.log1p(ix));
26524                                                for (int j = 0; j < is; j++) {
26525                                                        oai16data[it.oIndex + j] = ox;
26526                                                }
26527                                        }
26528                                }
26529                        } else {
26530                                if (it.isOutputDouble()) {
26531                                        while (it.hasNext()) {
26532                                                for (int j = 0; j < is; j++) {
26533                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26534                                                        short ox;
26535                                                        ox = (short) toLong(Math.log1p(ix));
26536                                                        oai16data[it.oIndex + j] = ox;
26537                                                }
26538                                        }
26539                                } else {
26540                                        while (it.hasNext()) {
26541                                                for (int j = 0; j < is; j++) {
26542                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26543                                                        short ox;
26544                                                        ox = (short) toLong(Math.log1p(ix));
26545                                                        oai16data[it.oIndex + j] = ox;
26546                                                }
26547                                        }
26548                                }
26549                        }
26550                        break;
26551                case Dataset.ARRAYINT64:
26552                        final long[] oai64data = ((CompoundLongDataset) result).getData();
26553                        if (is == 1) {
26554                                if (it.isOutputDouble()) {
26555                                        while (it.hasNext()) {
26556                                                final double ix = it.aDouble;
26557                                                long ox;
26558                                                ox = toLong(Math.log1p(ix));
26559                                                oai64data[it.oIndex] = ox;
26560                                        }
26561                                } else {
26562                                        while (it.hasNext()) {
26563                                                final long ix = it.aLong;
26564                                                long ox;
26565                                                ox = toLong(Math.log1p(ix));
26566                                                oai64data[it.oIndex] = ox;
26567                                        }
26568                                }
26569                        } else if (as == 1) {
26570                                if (it.isOutputDouble()) {
26571                                        while (it.hasNext()) {
26572                                                final double ix = it.aDouble;
26573                                                long ox;
26574                                                ox = toLong(Math.log1p(ix));
26575                                                for (int j = 0; j < is; j++) {
26576                                                        oai64data[it.oIndex + j] = ox;
26577                                                }
26578                                        }
26579                                } else {
26580                                        while (it.hasNext()) {
26581                                                final long ix = it.aLong;
26582                                                long ox;
26583                                                ox = toLong(Math.log1p(ix));
26584                                                for (int j = 0; j < is; j++) {
26585                                                        oai64data[it.oIndex + j] = ox;
26586                                                }
26587                                        }
26588                                }
26589                        } else {
26590                                if (it.isOutputDouble()) {
26591                                        while (it.hasNext()) {
26592                                                for (int j = 0; j < is; j++) {
26593                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26594                                                        long ox;
26595                                                        ox = toLong(Math.log1p(ix));
26596                                                        oai64data[it.oIndex + j] = ox;
26597                                                }
26598                                        }
26599                                } else {
26600                                        while (it.hasNext()) {
26601                                                for (int j = 0; j < is; j++) {
26602                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26603                                                        long ox;
26604                                                        ox = toLong(Math.log1p(ix));
26605                                                        oai64data[it.oIndex + j] = ox;
26606                                                }
26607                                        }
26608                                }
26609                        }
26610                        break;
26611                case Dataset.ARRAYINT32:
26612                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
26613                        if (is == 1) {
26614                                if (it.isOutputDouble()) {
26615                                        while (it.hasNext()) {
26616                                                final double ix = it.aDouble;
26617                                                int ox;
26618                                                ox = (int) toLong(Math.log1p(ix));
26619                                                oai32data[it.oIndex] = ox;
26620                                        }
26621                                } else {
26622                                        while (it.hasNext()) {
26623                                                final long ix = it.aLong;
26624                                                int ox;
26625                                                ox = (int) toLong(Math.log1p(ix));
26626                                                oai32data[it.oIndex] = ox;
26627                                        }
26628                                }
26629                        } else if (as == 1) {
26630                                if (it.isOutputDouble()) {
26631                                        while (it.hasNext()) {
26632                                                final double ix = it.aDouble;
26633                                                int ox;
26634                                                ox = (int) toLong(Math.log1p(ix));
26635                                                for (int j = 0; j < is; j++) {
26636                                                        oai32data[it.oIndex + j] = ox;
26637                                                }
26638                                        }
26639                                } else {
26640                                        while (it.hasNext()) {
26641                                                final long ix = it.aLong;
26642                                                int ox;
26643                                                ox = (int) toLong(Math.log1p(ix));
26644                                                for (int j = 0; j < is; j++) {
26645                                                        oai32data[it.oIndex + j] = ox;
26646                                                }
26647                                        }
26648                                }
26649                        } else {
26650                                if (it.isOutputDouble()) {
26651                                        while (it.hasNext()) {
26652                                                for (int j = 0; j < is; j++) {
26653                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26654                                                        int ox;
26655                                                        ox = (int) toLong(Math.log1p(ix));
26656                                                        oai32data[it.oIndex + j] = ox;
26657                                                }
26658                                        }
26659                                } else {
26660                                        while (it.hasNext()) {
26661                                                for (int j = 0; j < is; j++) {
26662                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26663                                                        int ox;
26664                                                        ox = (int) toLong(Math.log1p(ix));
26665                                                        oai32data[it.oIndex + j] = ox;
26666                                                }
26667                                        }
26668                                }
26669                        }
26670                        break;
26671                case Dataset.FLOAT32:
26672                        final float[] of32data = ((FloatDataset) result).getData();
26673                        if (it.isOutputDouble()) {
26674                                while (it.hasNext()) {
26675                                        final double ix = it.aDouble;
26676                                        float ox;
26677                                        ox = (float) (Math.log1p(ix));
26678                                        of32data[it.oIndex] = ox;
26679                                }
26680                        } else {
26681                                while (it.hasNext()) {
26682                                        final long ix = it.aLong;
26683                                        float ox;
26684                                        ox = (float) (Math.log1p(ix));
26685                                        of32data[it.oIndex] = ox;
26686                                }
26687                        }
26688                        break;
26689                case Dataset.FLOAT64:
26690                        final double[] of64data = ((DoubleDataset) result).getData();
26691                        if (it.isOutputDouble()) {
26692                                while (it.hasNext()) {
26693                                        final double ix = it.aDouble;
26694                                        double ox;
26695                                        ox = (Math.log1p(ix));
26696                                        of64data[it.oIndex] = ox;
26697                                }
26698                        } else {
26699                                while (it.hasNext()) {
26700                                        final long ix = it.aLong;
26701                                        double ox;
26702                                        ox = (Math.log1p(ix));
26703                                        of64data[it.oIndex] = ox;
26704                                }
26705                        }
26706                        break;
26707                case Dataset.ARRAYFLOAT32:
26708                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
26709                        if (is == 1) {
26710                                if (it.isOutputDouble()) {
26711                                        while (it.hasNext()) {
26712                                                final double ix = it.aDouble;
26713                                                float ox;
26714                                                ox = (float) (Math.log1p(ix));
26715                                                oaf32data[it.oIndex] = ox;
26716                                        }
26717                                } else {
26718                                        while (it.hasNext()) {
26719                                                final long ix = it.aLong;
26720                                                float ox;
26721                                                ox = (float) (Math.log1p(ix));
26722                                                oaf32data[it.oIndex] = ox;
26723                                        }
26724                                }
26725                        } else if (as == 1) {
26726                                if (it.isOutputDouble()) {
26727                                        while (it.hasNext()) {
26728                                                final double ix = it.aDouble;
26729                                                float ox;
26730                                                ox = (float) (Math.log1p(ix));
26731                                                for (int j = 0; j < is; j++) {
26732                                                        oaf32data[it.oIndex + j] = ox;
26733                                                }
26734                                        }
26735                                } else {
26736                                        while (it.hasNext()) {
26737                                                final long ix = it.aLong;
26738                                                float ox;
26739                                                ox = (float) (Math.log1p(ix));
26740                                                for (int j = 0; j < is; j++) {
26741                                                        oaf32data[it.oIndex + j] = ox;
26742                                                }
26743                                        }
26744                                }
26745                        } else {
26746                                if (it.isOutputDouble()) {
26747                                        while (it.hasNext()) {
26748                                                for (int j = 0; j < is; j++) {
26749                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26750                                                        float ox;
26751                                                        ox = (float) (Math.log1p(ix));
26752                                                        oaf32data[it.oIndex + j] = ox;
26753                                                }
26754                                        }
26755                                } else {
26756                                        while (it.hasNext()) {
26757                                                for (int j = 0; j < is; j++) {
26758                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26759                                                        float ox;
26760                                                        ox = (float) (Math.log1p(ix));
26761                                                        oaf32data[it.oIndex + j] = ox;
26762                                                }
26763                                        }
26764                                }
26765                        }
26766                        break;
26767                case Dataset.ARRAYFLOAT64:
26768                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
26769                        if (is == 1) {
26770                                if (it.isOutputDouble()) {
26771                                        while (it.hasNext()) {
26772                                                final double ix = it.aDouble;
26773                                                double ox;
26774                                                ox = (Math.log1p(ix));
26775                                                oaf64data[it.oIndex] = ox;
26776                                        }
26777                                } else {
26778                                        while (it.hasNext()) {
26779                                                final long ix = it.aLong;
26780                                                double ox;
26781                                                ox = (Math.log1p(ix));
26782                                                oaf64data[it.oIndex] = ox;
26783                                        }
26784                                }
26785                        } else if (as == 1) {
26786                                if (it.isOutputDouble()) {
26787                                        while (it.hasNext()) {
26788                                                final double ix = it.aDouble;
26789                                                double ox;
26790                                                ox = (Math.log1p(ix));
26791                                                for (int j = 0; j < is; j++) {
26792                                                        oaf64data[it.oIndex + j] = ox;
26793                                                }
26794                                        }
26795                                } else {
26796                                        while (it.hasNext()) {
26797                                                final long ix = it.aLong;
26798                                                double ox;
26799                                                ox = (Math.log1p(ix));
26800                                                for (int j = 0; j < is; j++) {
26801                                                        oaf64data[it.oIndex + j] = ox;
26802                                                }
26803                                        }
26804                                }
26805                        } else {
26806                                if (it.isOutputDouble()) {
26807                                        while (it.hasNext()) {
26808                                                for (int j = 0; j < is; j++) {
26809                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
26810                                                        double ox;
26811                                                        ox = (Math.log1p(ix));
26812                                                        oaf64data[it.oIndex + j] = ox;
26813                                                }
26814                                        }
26815                                } else {
26816                                        while (it.hasNext()) {
26817                                                for (int j = 0; j < is; j++) {
26818                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
26819                                                        double ox;
26820                                                        ox = (Math.log1p(ix));
26821                                                        oaf64data[it.oIndex + j] = ox;
26822                                                }
26823                                        }
26824                                }
26825                        }
26826                        break;
26827                case Dataset.COMPLEX64:
26828                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
26829                        if (!da.isComplex()) {
26830                                if (it.isOutputDouble()) {
26831                                        final double iy = 0;
26832                                        while (it.hasNext()) {
26833                                                final double ix = it.aDouble;
26834                                                float ox;
26835                                                float oy;
26836                                                ox = (float) (0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
26837                                                oy = (float) (Math.atan2(iy, ix+1));
26838                                                oc64data[it.oIndex] = ox;
26839                                                oc64data[it.oIndex + 1] = oy;
26840                                        }
26841                                } else {
26842                                        final long iy = 0;
26843                                        while (it.hasNext()) {
26844                                                final long ix = it.aLong;
26845                                                float ox;
26846                                                float oy;
26847                                                ox = (float) toLong(0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
26848                                                oy = (float) toLong(Math.atan2(iy, ix+1));
26849                                                oc64data[it.oIndex] = ox;
26850                                                oc64data[it.oIndex + 1] = oy;
26851                                        }
26852                                }
26853                        } else {
26854                                while (it.hasNext()) {
26855                                        final double ix = it.aDouble;
26856                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
26857                                        float ox;
26858                                        float oy;
26859                                        ox = (float) (0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
26860                                        oy = (float) (Math.atan2(iy, ix+1));
26861                                        oc64data[it.oIndex] = ox;
26862                                        oc64data[it.oIndex + 1] = oy;
26863                                }
26864                        }
26865                        break;
26866                case Dataset.COMPLEX128:
26867                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
26868                        if (!da.isComplex()) {
26869                                if (it.isOutputDouble()) {
26870                                        final double iy = 0;
26871                                        while (it.hasNext()) {
26872                                                final double ix = it.aDouble;
26873                                                double ox;
26874                                                double oy;
26875                                                ox = (0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
26876                                                oy = (Math.atan2(iy, ix+1));
26877                                                oc128data[it.oIndex] = ox;
26878                                                oc128data[it.oIndex + 1] = oy;
26879                                        }
26880                                } else {
26881                                        final long iy = 0;
26882                                        while (it.hasNext()) {
26883                                                final long ix = it.aLong;
26884                                                double ox;
26885                                                double oy;
26886                                                ox = (double) (0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
26887                                                oy = (double) (Math.atan2(iy, ix+1));
26888                                                oc128data[it.oIndex] = ox;
26889                                                oc128data[it.oIndex + 1] = oy;
26890                                        }
26891                                }
26892                        } else {
26893                                while (it.hasNext()) {
26894                                        final double ix = it.aDouble;
26895                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
26896                                        double ox;
26897                                        double oy;
26898                                        ox = (0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
26899                                        oy = (Math.atan2(iy, ix+1));
26900                                        oc128data[it.oIndex] = ox;
26901                                        oc128data[it.oIndex + 1] = oy;
26902                                }
26903                        }
26904                        break;
26905                default:
26906                        throw new IllegalArgumentException("log1p supports integer, compound integer, real, compound real, complex datasets only");
26907                }
26908
26909                addFunctionName(result, "log1p");
26910                return result;
26911        }
26912
26913        /**
26914         * exp - evaluate the exponential function on each element of the dataset
26915         * @param a single operand
26916         * @return dataset
26917         */
26918        public static Dataset exp(final Object a) {
26919                return exp(a, null);
26920        }
26921
26922        /**
26923         * exp - evaluate the exponential function on each element of the dataset
26924         * @param a single operand
26925         * @param o output can be null - in which case, a new dataset is created
26926         * @return dataset
26927         */
26928        public static Dataset exp(final Object a, final Dataset o) {
26929                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
26930                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
26931                final Dataset result = it.getOutput();
26932                if (!result.isComplex()) {
26933                        if (da.isComplex()) {
26934                                da = da.getRealView();
26935                                it = new SingleInputBroadcastIterator(da, result, true);
26936                        }
26937                }
26938                final int is = result.getElementsPerItem();
26939                final int as = da.getElementsPerItem();
26940                final int dt = result.getDType();
26941
26942                switch(dt) {
26943                case Dataset.INT8:
26944                        final byte[] oi8data = ((ByteDataset) result).getData();
26945                        if (it.isOutputDouble()) {
26946                                while (it.hasNext()) {
26947                                        final double ix = it.aDouble;
26948                                        byte ox;
26949                                        ox = (byte) toLong(Math.exp(ix));
26950                                        oi8data[it.oIndex] = ox;
26951                                }
26952                        } else {
26953                                while (it.hasNext()) {
26954                                        final long ix = it.aLong;
26955                                        byte ox;
26956                                        ox = (byte) toLong(Math.exp(ix));
26957                                        oi8data[it.oIndex] = ox;
26958                                }
26959                        }
26960                        break;
26961                case Dataset.INT16:
26962                        final short[] oi16data = ((ShortDataset) result).getData();
26963                        if (it.isOutputDouble()) {
26964                                while (it.hasNext()) {
26965                                        final double ix = it.aDouble;
26966                                        short ox;
26967                                        ox = (short) toLong(Math.exp(ix));
26968                                        oi16data[it.oIndex] = ox;
26969                                }
26970                        } else {
26971                                while (it.hasNext()) {
26972                                        final long ix = it.aLong;
26973                                        short ox;
26974                                        ox = (short) toLong(Math.exp(ix));
26975                                        oi16data[it.oIndex] = ox;
26976                                }
26977                        }
26978                        break;
26979                case Dataset.INT64:
26980                        final long[] oi64data = ((LongDataset) result).getData();
26981                        if (it.isOutputDouble()) {
26982                                while (it.hasNext()) {
26983                                        final double ix = it.aDouble;
26984                                        long ox;
26985                                        ox = toLong(Math.exp(ix));
26986                                        oi64data[it.oIndex] = ox;
26987                                }
26988                        } else {
26989                                while (it.hasNext()) {
26990                                        final long ix = it.aLong;
26991                                        long ox;
26992                                        ox = toLong(Math.exp(ix));
26993                                        oi64data[it.oIndex] = ox;
26994                                }
26995                        }
26996                        break;
26997                case Dataset.INT32:
26998                        final int[] oi32data = ((IntegerDataset) result).getData();
26999                        if (it.isOutputDouble()) {
27000                                while (it.hasNext()) {
27001                                        final double ix = it.aDouble;
27002                                        int ox;
27003                                        ox = (int) toLong(Math.exp(ix));
27004                                        oi32data[it.oIndex] = ox;
27005                                }
27006                        } else {
27007                                while (it.hasNext()) {
27008                                        final long ix = it.aLong;
27009                                        int ox;
27010                                        ox = (int) toLong(Math.exp(ix));
27011                                        oi32data[it.oIndex] = ox;
27012                                }
27013                        }
27014                        break;
27015                case Dataset.ARRAYINT8:
27016                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
27017                        if (is == 1) {
27018                                if (it.isOutputDouble()) {
27019                                        while (it.hasNext()) {
27020                                                final double ix = it.aDouble;
27021                                                byte ox;
27022                                                ox = (byte) toLong(Math.exp(ix));
27023                                                oai8data[it.oIndex] = ox;
27024                                        }
27025                                } else {
27026                                        while (it.hasNext()) {
27027                                                final long ix = it.aLong;
27028                                                byte ox;
27029                                                ox = (byte) toLong(Math.exp(ix));
27030                                                oai8data[it.oIndex] = ox;
27031                                        }
27032                                }
27033                        } else if (as == 1) {
27034                                if (it.isOutputDouble()) {
27035                                        while (it.hasNext()) {
27036                                                final double ix = it.aDouble;
27037                                                byte ox;
27038                                                ox = (byte) toLong(Math.exp(ix));
27039                                                for (int j = 0; j < is; j++) {
27040                                                        oai8data[it.oIndex + j] = ox;
27041                                                }
27042                                        }
27043                                } else {
27044                                        while (it.hasNext()) {
27045                                                final long ix = it.aLong;
27046                                                byte ox;
27047                                                ox = (byte) toLong(Math.exp(ix));
27048                                                for (int j = 0; j < is; j++) {
27049                                                        oai8data[it.oIndex + j] = ox;
27050                                                }
27051                                        }
27052                                }
27053                        } else {
27054                                if (it.isOutputDouble()) {
27055                                        while (it.hasNext()) {
27056                                                for (int j = 0; j < is; j++) {
27057                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27058                                                        byte ox;
27059                                                        ox = (byte) toLong(Math.exp(ix));
27060                                                        oai8data[it.oIndex + j] = ox;
27061                                                }
27062                                        }
27063                                } else {
27064                                        while (it.hasNext()) {
27065                                                for (int j = 0; j < is; j++) {
27066                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27067                                                        byte ox;
27068                                                        ox = (byte) toLong(Math.exp(ix));
27069                                                        oai8data[it.oIndex + j] = ox;
27070                                                }
27071                                        }
27072                                }
27073                        }
27074                        break;
27075                case Dataset.ARRAYINT16:
27076                        final short[] oai16data = ((CompoundShortDataset) result).getData();
27077                        if (is == 1) {
27078                                if (it.isOutputDouble()) {
27079                                        while (it.hasNext()) {
27080                                                final double ix = it.aDouble;
27081                                                short ox;
27082                                                ox = (short) toLong(Math.exp(ix));
27083                                                oai16data[it.oIndex] = ox;
27084                                        }
27085                                } else {
27086                                        while (it.hasNext()) {
27087                                                final long ix = it.aLong;
27088                                                short ox;
27089                                                ox = (short) toLong(Math.exp(ix));
27090                                                oai16data[it.oIndex] = ox;
27091                                        }
27092                                }
27093                        } else if (as == 1) {
27094                                if (it.isOutputDouble()) {
27095                                        while (it.hasNext()) {
27096                                                final double ix = it.aDouble;
27097                                                short ox;
27098                                                ox = (short) toLong(Math.exp(ix));
27099                                                for (int j = 0; j < is; j++) {
27100                                                        oai16data[it.oIndex + j] = ox;
27101                                                }
27102                                        }
27103                                } else {
27104                                        while (it.hasNext()) {
27105                                                final long ix = it.aLong;
27106                                                short ox;
27107                                                ox = (short) toLong(Math.exp(ix));
27108                                                for (int j = 0; j < is; j++) {
27109                                                        oai16data[it.oIndex + j] = ox;
27110                                                }
27111                                        }
27112                                }
27113                        } else {
27114                                if (it.isOutputDouble()) {
27115                                        while (it.hasNext()) {
27116                                                for (int j = 0; j < is; j++) {
27117                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27118                                                        short ox;
27119                                                        ox = (short) toLong(Math.exp(ix));
27120                                                        oai16data[it.oIndex + j] = ox;
27121                                                }
27122                                        }
27123                                } else {
27124                                        while (it.hasNext()) {
27125                                                for (int j = 0; j < is; j++) {
27126                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27127                                                        short ox;
27128                                                        ox = (short) toLong(Math.exp(ix));
27129                                                        oai16data[it.oIndex + j] = ox;
27130                                                }
27131                                        }
27132                                }
27133                        }
27134                        break;
27135                case Dataset.ARRAYINT64:
27136                        final long[] oai64data = ((CompoundLongDataset) result).getData();
27137                        if (is == 1) {
27138                                if (it.isOutputDouble()) {
27139                                        while (it.hasNext()) {
27140                                                final double ix = it.aDouble;
27141                                                long ox;
27142                                                ox = toLong(Math.exp(ix));
27143                                                oai64data[it.oIndex] = ox;
27144                                        }
27145                                } else {
27146                                        while (it.hasNext()) {
27147                                                final long ix = it.aLong;
27148                                                long ox;
27149                                                ox = toLong(Math.exp(ix));
27150                                                oai64data[it.oIndex] = ox;
27151                                        }
27152                                }
27153                        } else if (as == 1) {
27154                                if (it.isOutputDouble()) {
27155                                        while (it.hasNext()) {
27156                                                final double ix = it.aDouble;
27157                                                long ox;
27158                                                ox = toLong(Math.exp(ix));
27159                                                for (int j = 0; j < is; j++) {
27160                                                        oai64data[it.oIndex + j] = ox;
27161                                                }
27162                                        }
27163                                } else {
27164                                        while (it.hasNext()) {
27165                                                final long ix = it.aLong;
27166                                                long ox;
27167                                                ox = toLong(Math.exp(ix));
27168                                                for (int j = 0; j < is; j++) {
27169                                                        oai64data[it.oIndex + j] = ox;
27170                                                }
27171                                        }
27172                                }
27173                        } else {
27174                                if (it.isOutputDouble()) {
27175                                        while (it.hasNext()) {
27176                                                for (int j = 0; j < is; j++) {
27177                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27178                                                        long ox;
27179                                                        ox = toLong(Math.exp(ix));
27180                                                        oai64data[it.oIndex + j] = ox;
27181                                                }
27182                                        }
27183                                } else {
27184                                        while (it.hasNext()) {
27185                                                for (int j = 0; j < is; j++) {
27186                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27187                                                        long ox;
27188                                                        ox = toLong(Math.exp(ix));
27189                                                        oai64data[it.oIndex + j] = ox;
27190                                                }
27191                                        }
27192                                }
27193                        }
27194                        break;
27195                case Dataset.ARRAYINT32:
27196                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
27197                        if (is == 1) {
27198                                if (it.isOutputDouble()) {
27199                                        while (it.hasNext()) {
27200                                                final double ix = it.aDouble;
27201                                                int ox;
27202                                                ox = (int) toLong(Math.exp(ix));
27203                                                oai32data[it.oIndex] = ox;
27204                                        }
27205                                } else {
27206                                        while (it.hasNext()) {
27207                                                final long ix = it.aLong;
27208                                                int ox;
27209                                                ox = (int) toLong(Math.exp(ix));
27210                                                oai32data[it.oIndex] = ox;
27211                                        }
27212                                }
27213                        } else if (as == 1) {
27214                                if (it.isOutputDouble()) {
27215                                        while (it.hasNext()) {
27216                                                final double ix = it.aDouble;
27217                                                int ox;
27218                                                ox = (int) toLong(Math.exp(ix));
27219                                                for (int j = 0; j < is; j++) {
27220                                                        oai32data[it.oIndex + j] = ox;
27221                                                }
27222                                        }
27223                                } else {
27224                                        while (it.hasNext()) {
27225                                                final long ix = it.aLong;
27226                                                int ox;
27227                                                ox = (int) toLong(Math.exp(ix));
27228                                                for (int j = 0; j < is; j++) {
27229                                                        oai32data[it.oIndex + j] = ox;
27230                                                }
27231                                        }
27232                                }
27233                        } else {
27234                                if (it.isOutputDouble()) {
27235                                        while (it.hasNext()) {
27236                                                for (int j = 0; j < is; j++) {
27237                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27238                                                        int ox;
27239                                                        ox = (int) toLong(Math.exp(ix));
27240                                                        oai32data[it.oIndex + j] = ox;
27241                                                }
27242                                        }
27243                                } else {
27244                                        while (it.hasNext()) {
27245                                                for (int j = 0; j < is; j++) {
27246                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27247                                                        int ox;
27248                                                        ox = (int) toLong(Math.exp(ix));
27249                                                        oai32data[it.oIndex + j] = ox;
27250                                                }
27251                                        }
27252                                }
27253                        }
27254                        break;
27255                case Dataset.FLOAT32:
27256                        final float[] of32data = ((FloatDataset) result).getData();
27257                        if (it.isOutputDouble()) {
27258                                while (it.hasNext()) {
27259                                        final double ix = it.aDouble;
27260                                        float ox;
27261                                        ox = (float) (Math.exp(ix));
27262                                        of32data[it.oIndex] = ox;
27263                                }
27264                        } else {
27265                                while (it.hasNext()) {
27266                                        final long ix = it.aLong;
27267                                        float ox;
27268                                        ox = (float) (Math.exp(ix));
27269                                        of32data[it.oIndex] = ox;
27270                                }
27271                        }
27272                        break;
27273                case Dataset.FLOAT64:
27274                        final double[] of64data = ((DoubleDataset) result).getData();
27275                        if (it.isOutputDouble()) {
27276                                while (it.hasNext()) {
27277                                        final double ix = it.aDouble;
27278                                        double ox;
27279                                        ox = (Math.exp(ix));
27280                                        of64data[it.oIndex] = ox;
27281                                }
27282                        } else {
27283                                while (it.hasNext()) {
27284                                        final long ix = it.aLong;
27285                                        double ox;
27286                                        ox = (Math.exp(ix));
27287                                        of64data[it.oIndex] = ox;
27288                                }
27289                        }
27290                        break;
27291                case Dataset.ARRAYFLOAT32:
27292                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
27293                        if (is == 1) {
27294                                if (it.isOutputDouble()) {
27295                                        while (it.hasNext()) {
27296                                                final double ix = it.aDouble;
27297                                                float ox;
27298                                                ox = (float) (Math.exp(ix));
27299                                                oaf32data[it.oIndex] = ox;
27300                                        }
27301                                } else {
27302                                        while (it.hasNext()) {
27303                                                final long ix = it.aLong;
27304                                                float ox;
27305                                                ox = (float) (Math.exp(ix));
27306                                                oaf32data[it.oIndex] = ox;
27307                                        }
27308                                }
27309                        } else if (as == 1) {
27310                                if (it.isOutputDouble()) {
27311                                        while (it.hasNext()) {
27312                                                final double ix = it.aDouble;
27313                                                float ox;
27314                                                ox = (float) (Math.exp(ix));
27315                                                for (int j = 0; j < is; j++) {
27316                                                        oaf32data[it.oIndex + j] = ox;
27317                                                }
27318                                        }
27319                                } else {
27320                                        while (it.hasNext()) {
27321                                                final long ix = it.aLong;
27322                                                float ox;
27323                                                ox = (float) (Math.exp(ix));
27324                                                for (int j = 0; j < is; j++) {
27325                                                        oaf32data[it.oIndex + j] = ox;
27326                                                }
27327                                        }
27328                                }
27329                        } else {
27330                                if (it.isOutputDouble()) {
27331                                        while (it.hasNext()) {
27332                                                for (int j = 0; j < is; j++) {
27333                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27334                                                        float ox;
27335                                                        ox = (float) (Math.exp(ix));
27336                                                        oaf32data[it.oIndex + j] = ox;
27337                                                }
27338                                        }
27339                                } else {
27340                                        while (it.hasNext()) {
27341                                                for (int j = 0; j < is; j++) {
27342                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27343                                                        float ox;
27344                                                        ox = (float) (Math.exp(ix));
27345                                                        oaf32data[it.oIndex + j] = ox;
27346                                                }
27347                                        }
27348                                }
27349                        }
27350                        break;
27351                case Dataset.ARRAYFLOAT64:
27352                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
27353                        if (is == 1) {
27354                                if (it.isOutputDouble()) {
27355                                        while (it.hasNext()) {
27356                                                final double ix = it.aDouble;
27357                                                double ox;
27358                                                ox = (Math.exp(ix));
27359                                                oaf64data[it.oIndex] = ox;
27360                                        }
27361                                } else {
27362                                        while (it.hasNext()) {
27363                                                final long ix = it.aLong;
27364                                                double ox;
27365                                                ox = (Math.exp(ix));
27366                                                oaf64data[it.oIndex] = ox;
27367                                        }
27368                                }
27369                        } else if (as == 1) {
27370                                if (it.isOutputDouble()) {
27371                                        while (it.hasNext()) {
27372                                                final double ix = it.aDouble;
27373                                                double ox;
27374                                                ox = (Math.exp(ix));
27375                                                for (int j = 0; j < is; j++) {
27376                                                        oaf64data[it.oIndex + j] = ox;
27377                                                }
27378                                        }
27379                                } else {
27380                                        while (it.hasNext()) {
27381                                                final long ix = it.aLong;
27382                                                double ox;
27383                                                ox = (Math.exp(ix));
27384                                                for (int j = 0; j < is; j++) {
27385                                                        oaf64data[it.oIndex + j] = ox;
27386                                                }
27387                                        }
27388                                }
27389                        } else {
27390                                if (it.isOutputDouble()) {
27391                                        while (it.hasNext()) {
27392                                                for (int j = 0; j < is; j++) {
27393                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27394                                                        double ox;
27395                                                        ox = (Math.exp(ix));
27396                                                        oaf64data[it.oIndex + j] = ox;
27397                                                }
27398                                        }
27399                                } else {
27400                                        while (it.hasNext()) {
27401                                                for (int j = 0; j < is; j++) {
27402                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27403                                                        double ox;
27404                                                        ox = (Math.exp(ix));
27405                                                        oaf64data[it.oIndex + j] = ox;
27406                                                }
27407                                        }
27408                                }
27409                        }
27410                        break;
27411                case Dataset.COMPLEX64:
27412                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
27413                        if (!da.isComplex()) {
27414                                if (it.isOutputDouble()) {
27415                                        final double iy = 0;
27416                                        while (it.hasNext()) {
27417                                                final double ix = it.aDouble;
27418                                                float tf;
27419                                                float ox;
27420                                                float oy;
27421                                                tf = (float) (Math.exp(ix));
27422                                                ox = (float) (tf*Math.cos(iy));
27423                                                oy = (float) (tf*Math.sin(iy));
27424                                                oc64data[it.oIndex] = ox;
27425                                                oc64data[it.oIndex + 1] = oy;
27426                                        }
27427                                } else {
27428                                        final long iy = 0;
27429                                        while (it.hasNext()) {
27430                                                final long ix = it.aLong;
27431                                                float tf;
27432                                                float ox;
27433                                                float oy;
27434                                                tf = (float) toLong(Math.exp(ix));
27435                                                ox = (float) toLong(tf*Math.cos(iy));
27436                                                oy = (float) toLong(tf*Math.sin(iy));
27437                                                oc64data[it.oIndex] = ox;
27438                                                oc64data[it.oIndex + 1] = oy;
27439                                        }
27440                                }
27441                        } else {
27442                                while (it.hasNext()) {
27443                                        final double ix = it.aDouble;
27444                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
27445                                        float tf;
27446                                        float ox;
27447                                        float oy;
27448                                        tf = (float) (Math.exp(ix));
27449                                        ox = (float) (tf*Math.cos(iy));
27450                                        oy = (float) (tf*Math.sin(iy));
27451                                        oc64data[it.oIndex] = ox;
27452                                        oc64data[it.oIndex + 1] = oy;
27453                                }
27454                        }
27455                        break;
27456                case Dataset.COMPLEX128:
27457                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
27458                        if (!da.isComplex()) {
27459                                if (it.isOutputDouble()) {
27460                                        final double iy = 0;
27461                                        while (it.hasNext()) {
27462                                                final double ix = it.aDouble;
27463                                                double tf;
27464                                                double ox;
27465                                                double oy;
27466                                                tf = (Math.exp(ix));
27467                                                ox = (tf*Math.cos(iy));
27468                                                oy = (tf*Math.sin(iy));
27469                                                oc128data[it.oIndex] = ox;
27470                                                oc128data[it.oIndex + 1] = oy;
27471                                        }
27472                                } else {
27473                                        final long iy = 0;
27474                                        while (it.hasNext()) {
27475                                                final long ix = it.aLong;
27476                                                double tf;
27477                                                double ox;
27478                                                double oy;
27479                                                tf = (double) (Math.exp(ix));
27480                                                ox = (double) (tf*Math.cos(iy));
27481                                                oy = (double) (tf*Math.sin(iy));
27482                                                oc128data[it.oIndex] = ox;
27483                                                oc128data[it.oIndex + 1] = oy;
27484                                        }
27485                                }
27486                        } else {
27487                                while (it.hasNext()) {
27488                                        final double ix = it.aDouble;
27489                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
27490                                        double tf;
27491                                        double ox;
27492                                        double oy;
27493                                        tf = (Math.exp(ix));
27494                                        ox = (tf*Math.cos(iy));
27495                                        oy = (tf*Math.sin(iy));
27496                                        oc128data[it.oIndex] = ox;
27497                                        oc128data[it.oIndex + 1] = oy;
27498                                }
27499                        }
27500                        break;
27501                default:
27502                        throw new IllegalArgumentException("exp supports integer, compound integer, real, compound real, complex datasets only");
27503                }
27504
27505                addFunctionName(result, "exp");
27506                return result;
27507        }
27508
27509        /**
27510         * expm1 - evaluate the exponential function - 1 on each element of the dataset
27511         * @param a single operand
27512         * @return dataset
27513         */
27514        public static Dataset expm1(final Object a) {
27515                return expm1(a, null);
27516        }
27517
27518        /**
27519         * expm1 - evaluate the exponential function - 1 on each element of the dataset
27520         * @param a single operand
27521         * @param o output can be null - in which case, a new dataset is created
27522         * @return dataset
27523         */
27524        public static Dataset expm1(final Object a, final Dataset o) {
27525                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
27526                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
27527                final Dataset result = it.getOutput();
27528                if (!result.isComplex()) {
27529                        if (da.isComplex()) {
27530                                da = da.getRealView();
27531                                it = new SingleInputBroadcastIterator(da, result, true);
27532                        }
27533                }
27534                final int is = result.getElementsPerItem();
27535                final int as = da.getElementsPerItem();
27536                final int dt = result.getDType();
27537
27538                switch(dt) {
27539                case Dataset.INT8:
27540                        final byte[] oi8data = ((ByteDataset) result).getData();
27541                        if (it.isOutputDouble()) {
27542                                while (it.hasNext()) {
27543                                        final double ix = it.aDouble;
27544                                        byte ox;
27545                                        ox = (byte) toLong(Math.expm1(ix));
27546                                        oi8data[it.oIndex] = ox;
27547                                }
27548                        } else {
27549                                while (it.hasNext()) {
27550                                        final long ix = it.aLong;
27551                                        byte ox;
27552                                        ox = (byte) toLong(Math.expm1(ix));
27553                                        oi8data[it.oIndex] = ox;
27554                                }
27555                        }
27556                        break;
27557                case Dataset.INT16:
27558                        final short[] oi16data = ((ShortDataset) result).getData();
27559                        if (it.isOutputDouble()) {
27560                                while (it.hasNext()) {
27561                                        final double ix = it.aDouble;
27562                                        short ox;
27563                                        ox = (short) toLong(Math.expm1(ix));
27564                                        oi16data[it.oIndex] = ox;
27565                                }
27566                        } else {
27567                                while (it.hasNext()) {
27568                                        final long ix = it.aLong;
27569                                        short ox;
27570                                        ox = (short) toLong(Math.expm1(ix));
27571                                        oi16data[it.oIndex] = ox;
27572                                }
27573                        }
27574                        break;
27575                case Dataset.INT64:
27576                        final long[] oi64data = ((LongDataset) result).getData();
27577                        if (it.isOutputDouble()) {
27578                                while (it.hasNext()) {
27579                                        final double ix = it.aDouble;
27580                                        long ox;
27581                                        ox = toLong(Math.expm1(ix));
27582                                        oi64data[it.oIndex] = ox;
27583                                }
27584                        } else {
27585                                while (it.hasNext()) {
27586                                        final long ix = it.aLong;
27587                                        long ox;
27588                                        ox = toLong(Math.expm1(ix));
27589                                        oi64data[it.oIndex] = ox;
27590                                }
27591                        }
27592                        break;
27593                case Dataset.INT32:
27594                        final int[] oi32data = ((IntegerDataset) result).getData();
27595                        if (it.isOutputDouble()) {
27596                                while (it.hasNext()) {
27597                                        final double ix = it.aDouble;
27598                                        int ox;
27599                                        ox = (int) toLong(Math.expm1(ix));
27600                                        oi32data[it.oIndex] = ox;
27601                                }
27602                        } else {
27603                                while (it.hasNext()) {
27604                                        final long ix = it.aLong;
27605                                        int ox;
27606                                        ox = (int) toLong(Math.expm1(ix));
27607                                        oi32data[it.oIndex] = ox;
27608                                }
27609                        }
27610                        break;
27611                case Dataset.ARRAYINT8:
27612                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
27613                        if (is == 1) {
27614                                if (it.isOutputDouble()) {
27615                                        while (it.hasNext()) {
27616                                                final double ix = it.aDouble;
27617                                                byte ox;
27618                                                ox = (byte) toLong(Math.expm1(ix));
27619                                                oai8data[it.oIndex] = ox;
27620                                        }
27621                                } else {
27622                                        while (it.hasNext()) {
27623                                                final long ix = it.aLong;
27624                                                byte ox;
27625                                                ox = (byte) toLong(Math.expm1(ix));
27626                                                oai8data[it.oIndex] = ox;
27627                                        }
27628                                }
27629                        } else if (as == 1) {
27630                                if (it.isOutputDouble()) {
27631                                        while (it.hasNext()) {
27632                                                final double ix = it.aDouble;
27633                                                byte ox;
27634                                                ox = (byte) toLong(Math.expm1(ix));
27635                                                for (int j = 0; j < is; j++) {
27636                                                        oai8data[it.oIndex + j] = ox;
27637                                                }
27638                                        }
27639                                } else {
27640                                        while (it.hasNext()) {
27641                                                final long ix = it.aLong;
27642                                                byte ox;
27643                                                ox = (byte) toLong(Math.expm1(ix));
27644                                                for (int j = 0; j < is; j++) {
27645                                                        oai8data[it.oIndex + j] = ox;
27646                                                }
27647                                        }
27648                                }
27649                        } else {
27650                                if (it.isOutputDouble()) {
27651                                        while (it.hasNext()) {
27652                                                for (int j = 0; j < is; j++) {
27653                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27654                                                        byte ox;
27655                                                        ox = (byte) toLong(Math.expm1(ix));
27656                                                        oai8data[it.oIndex + j] = ox;
27657                                                }
27658                                        }
27659                                } else {
27660                                        while (it.hasNext()) {
27661                                                for (int j = 0; j < is; j++) {
27662                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27663                                                        byte ox;
27664                                                        ox = (byte) toLong(Math.expm1(ix));
27665                                                        oai8data[it.oIndex + j] = ox;
27666                                                }
27667                                        }
27668                                }
27669                        }
27670                        break;
27671                case Dataset.ARRAYINT16:
27672                        final short[] oai16data = ((CompoundShortDataset) result).getData();
27673                        if (is == 1) {
27674                                if (it.isOutputDouble()) {
27675                                        while (it.hasNext()) {
27676                                                final double ix = it.aDouble;
27677                                                short ox;
27678                                                ox = (short) toLong(Math.expm1(ix));
27679                                                oai16data[it.oIndex] = ox;
27680                                        }
27681                                } else {
27682                                        while (it.hasNext()) {
27683                                                final long ix = it.aLong;
27684                                                short ox;
27685                                                ox = (short) toLong(Math.expm1(ix));
27686                                                oai16data[it.oIndex] = ox;
27687                                        }
27688                                }
27689                        } else if (as == 1) {
27690                                if (it.isOutputDouble()) {
27691                                        while (it.hasNext()) {
27692                                                final double ix = it.aDouble;
27693                                                short ox;
27694                                                ox = (short) toLong(Math.expm1(ix));
27695                                                for (int j = 0; j < is; j++) {
27696                                                        oai16data[it.oIndex + j] = ox;
27697                                                }
27698                                        }
27699                                } else {
27700                                        while (it.hasNext()) {
27701                                                final long ix = it.aLong;
27702                                                short ox;
27703                                                ox = (short) toLong(Math.expm1(ix));
27704                                                for (int j = 0; j < is; j++) {
27705                                                        oai16data[it.oIndex + j] = ox;
27706                                                }
27707                                        }
27708                                }
27709                        } else {
27710                                if (it.isOutputDouble()) {
27711                                        while (it.hasNext()) {
27712                                                for (int j = 0; j < is; j++) {
27713                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27714                                                        short ox;
27715                                                        ox = (short) toLong(Math.expm1(ix));
27716                                                        oai16data[it.oIndex + j] = ox;
27717                                                }
27718                                        }
27719                                } else {
27720                                        while (it.hasNext()) {
27721                                                for (int j = 0; j < is; j++) {
27722                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27723                                                        short ox;
27724                                                        ox = (short) toLong(Math.expm1(ix));
27725                                                        oai16data[it.oIndex + j] = ox;
27726                                                }
27727                                        }
27728                                }
27729                        }
27730                        break;
27731                case Dataset.ARRAYINT64:
27732                        final long[] oai64data = ((CompoundLongDataset) result).getData();
27733                        if (is == 1) {
27734                                if (it.isOutputDouble()) {
27735                                        while (it.hasNext()) {
27736                                                final double ix = it.aDouble;
27737                                                long ox;
27738                                                ox = toLong(Math.expm1(ix));
27739                                                oai64data[it.oIndex] = ox;
27740                                        }
27741                                } else {
27742                                        while (it.hasNext()) {
27743                                                final long ix = it.aLong;
27744                                                long ox;
27745                                                ox = toLong(Math.expm1(ix));
27746                                                oai64data[it.oIndex] = ox;
27747                                        }
27748                                }
27749                        } else if (as == 1) {
27750                                if (it.isOutputDouble()) {
27751                                        while (it.hasNext()) {
27752                                                final double ix = it.aDouble;
27753                                                long ox;
27754                                                ox = toLong(Math.expm1(ix));
27755                                                for (int j = 0; j < is; j++) {
27756                                                        oai64data[it.oIndex + j] = ox;
27757                                                }
27758                                        }
27759                                } else {
27760                                        while (it.hasNext()) {
27761                                                final long ix = it.aLong;
27762                                                long ox;
27763                                                ox = toLong(Math.expm1(ix));
27764                                                for (int j = 0; j < is; j++) {
27765                                                        oai64data[it.oIndex + j] = ox;
27766                                                }
27767                                        }
27768                                }
27769                        } else {
27770                                if (it.isOutputDouble()) {
27771                                        while (it.hasNext()) {
27772                                                for (int j = 0; j < is; j++) {
27773                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27774                                                        long ox;
27775                                                        ox = toLong(Math.expm1(ix));
27776                                                        oai64data[it.oIndex + j] = ox;
27777                                                }
27778                                        }
27779                                } else {
27780                                        while (it.hasNext()) {
27781                                                for (int j = 0; j < is; j++) {
27782                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27783                                                        long ox;
27784                                                        ox = toLong(Math.expm1(ix));
27785                                                        oai64data[it.oIndex + j] = ox;
27786                                                }
27787                                        }
27788                                }
27789                        }
27790                        break;
27791                case Dataset.ARRAYINT32:
27792                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
27793                        if (is == 1) {
27794                                if (it.isOutputDouble()) {
27795                                        while (it.hasNext()) {
27796                                                final double ix = it.aDouble;
27797                                                int ox;
27798                                                ox = (int) toLong(Math.expm1(ix));
27799                                                oai32data[it.oIndex] = ox;
27800                                        }
27801                                } else {
27802                                        while (it.hasNext()) {
27803                                                final long ix = it.aLong;
27804                                                int ox;
27805                                                ox = (int) toLong(Math.expm1(ix));
27806                                                oai32data[it.oIndex] = ox;
27807                                        }
27808                                }
27809                        } else if (as == 1) {
27810                                if (it.isOutputDouble()) {
27811                                        while (it.hasNext()) {
27812                                                final double ix = it.aDouble;
27813                                                int ox;
27814                                                ox = (int) toLong(Math.expm1(ix));
27815                                                for (int j = 0; j < is; j++) {
27816                                                        oai32data[it.oIndex + j] = ox;
27817                                                }
27818                                        }
27819                                } else {
27820                                        while (it.hasNext()) {
27821                                                final long ix = it.aLong;
27822                                                int ox;
27823                                                ox = (int) toLong(Math.expm1(ix));
27824                                                for (int j = 0; j < is; j++) {
27825                                                        oai32data[it.oIndex + j] = ox;
27826                                                }
27827                                        }
27828                                }
27829                        } else {
27830                                if (it.isOutputDouble()) {
27831                                        while (it.hasNext()) {
27832                                                for (int j = 0; j < is; j++) {
27833                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27834                                                        int ox;
27835                                                        ox = (int) toLong(Math.expm1(ix));
27836                                                        oai32data[it.oIndex + j] = ox;
27837                                                }
27838                                        }
27839                                } else {
27840                                        while (it.hasNext()) {
27841                                                for (int j = 0; j < is; j++) {
27842                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27843                                                        int ox;
27844                                                        ox = (int) toLong(Math.expm1(ix));
27845                                                        oai32data[it.oIndex + j] = ox;
27846                                                }
27847                                        }
27848                                }
27849                        }
27850                        break;
27851                case Dataset.FLOAT32:
27852                        final float[] of32data = ((FloatDataset) result).getData();
27853                        if (it.isOutputDouble()) {
27854                                while (it.hasNext()) {
27855                                        final double ix = it.aDouble;
27856                                        float ox;
27857                                        ox = (float) (Math.expm1(ix));
27858                                        of32data[it.oIndex] = ox;
27859                                }
27860                        } else {
27861                                while (it.hasNext()) {
27862                                        final long ix = it.aLong;
27863                                        float ox;
27864                                        ox = (float) (Math.expm1(ix));
27865                                        of32data[it.oIndex] = ox;
27866                                }
27867                        }
27868                        break;
27869                case Dataset.FLOAT64:
27870                        final double[] of64data = ((DoubleDataset) result).getData();
27871                        if (it.isOutputDouble()) {
27872                                while (it.hasNext()) {
27873                                        final double ix = it.aDouble;
27874                                        double ox;
27875                                        ox = (Math.expm1(ix));
27876                                        of64data[it.oIndex] = ox;
27877                                }
27878                        } else {
27879                                while (it.hasNext()) {
27880                                        final long ix = it.aLong;
27881                                        double ox;
27882                                        ox = (Math.expm1(ix));
27883                                        of64data[it.oIndex] = ox;
27884                                }
27885                        }
27886                        break;
27887                case Dataset.ARRAYFLOAT32:
27888                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
27889                        if (is == 1) {
27890                                if (it.isOutputDouble()) {
27891                                        while (it.hasNext()) {
27892                                                final double ix = it.aDouble;
27893                                                float ox;
27894                                                ox = (float) (Math.expm1(ix));
27895                                                oaf32data[it.oIndex] = ox;
27896                                        }
27897                                } else {
27898                                        while (it.hasNext()) {
27899                                                final long ix = it.aLong;
27900                                                float ox;
27901                                                ox = (float) (Math.expm1(ix));
27902                                                oaf32data[it.oIndex] = ox;
27903                                        }
27904                                }
27905                        } else if (as == 1) {
27906                                if (it.isOutputDouble()) {
27907                                        while (it.hasNext()) {
27908                                                final double ix = it.aDouble;
27909                                                float ox;
27910                                                ox = (float) (Math.expm1(ix));
27911                                                for (int j = 0; j < is; j++) {
27912                                                        oaf32data[it.oIndex + j] = ox;
27913                                                }
27914                                        }
27915                                } else {
27916                                        while (it.hasNext()) {
27917                                                final long ix = it.aLong;
27918                                                float ox;
27919                                                ox = (float) (Math.expm1(ix));
27920                                                for (int j = 0; j < is; j++) {
27921                                                        oaf32data[it.oIndex + j] = ox;
27922                                                }
27923                                        }
27924                                }
27925                        } else {
27926                                if (it.isOutputDouble()) {
27927                                        while (it.hasNext()) {
27928                                                for (int j = 0; j < is; j++) {
27929                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27930                                                        float ox;
27931                                                        ox = (float) (Math.expm1(ix));
27932                                                        oaf32data[it.oIndex + j] = ox;
27933                                                }
27934                                        }
27935                                } else {
27936                                        while (it.hasNext()) {
27937                                                for (int j = 0; j < is; j++) {
27938                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27939                                                        float ox;
27940                                                        ox = (float) (Math.expm1(ix));
27941                                                        oaf32data[it.oIndex + j] = ox;
27942                                                }
27943                                        }
27944                                }
27945                        }
27946                        break;
27947                case Dataset.ARRAYFLOAT64:
27948                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
27949                        if (is == 1) {
27950                                if (it.isOutputDouble()) {
27951                                        while (it.hasNext()) {
27952                                                final double ix = it.aDouble;
27953                                                double ox;
27954                                                ox = (Math.expm1(ix));
27955                                                oaf64data[it.oIndex] = ox;
27956                                        }
27957                                } else {
27958                                        while (it.hasNext()) {
27959                                                final long ix = it.aLong;
27960                                                double ox;
27961                                                ox = (Math.expm1(ix));
27962                                                oaf64data[it.oIndex] = ox;
27963                                        }
27964                                }
27965                        } else if (as == 1) {
27966                                if (it.isOutputDouble()) {
27967                                        while (it.hasNext()) {
27968                                                final double ix = it.aDouble;
27969                                                double ox;
27970                                                ox = (Math.expm1(ix));
27971                                                for (int j = 0; j < is; j++) {
27972                                                        oaf64data[it.oIndex + j] = ox;
27973                                                }
27974                                        }
27975                                } else {
27976                                        while (it.hasNext()) {
27977                                                final long ix = it.aLong;
27978                                                double ox;
27979                                                ox = (Math.expm1(ix));
27980                                                for (int j = 0; j < is; j++) {
27981                                                        oaf64data[it.oIndex + j] = ox;
27982                                                }
27983                                        }
27984                                }
27985                        } else {
27986                                if (it.isOutputDouble()) {
27987                                        while (it.hasNext()) {
27988                                                for (int j = 0; j < is; j++) {
27989                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
27990                                                        double ox;
27991                                                        ox = (Math.expm1(ix));
27992                                                        oaf64data[it.oIndex + j] = ox;
27993                                                }
27994                                        }
27995                                } else {
27996                                        while (it.hasNext()) {
27997                                                for (int j = 0; j < is; j++) {
27998                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
27999                                                        double ox;
28000                                                        ox = (Math.expm1(ix));
28001                                                        oaf64data[it.oIndex + j] = ox;
28002                                                }
28003                                        }
28004                                }
28005                        }
28006                        break;
28007                case Dataset.COMPLEX64:
28008                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
28009                        if (!da.isComplex()) {
28010                                if (it.isOutputDouble()) {
28011                                        final double iy = 0;
28012                                        while (it.hasNext()) {
28013                                                final double ix = it.aDouble;
28014                                                float tf;
28015                                                float ox;
28016                                                float oy;
28017                                                tf = (float) (Math.expm1(ix));
28018                                                ox = (float) (tf*Math.cos(iy));
28019                                                oy = (float) (tf*Math.sin(iy));
28020                                                oc64data[it.oIndex] = ox;
28021                                                oc64data[it.oIndex + 1] = oy;
28022                                        }
28023                                } else {
28024                                        final long iy = 0;
28025                                        while (it.hasNext()) {
28026                                                final long ix = it.aLong;
28027                                                float tf;
28028                                                float ox;
28029                                                float oy;
28030                                                tf = (float) toLong(Math.expm1(ix));
28031                                                ox = (float) toLong(tf*Math.cos(iy));
28032                                                oy = (float) toLong(tf*Math.sin(iy));
28033                                                oc64data[it.oIndex] = ox;
28034                                                oc64data[it.oIndex + 1] = oy;
28035                                        }
28036                                }
28037                        } else {
28038                                while (it.hasNext()) {
28039                                        final double ix = it.aDouble;
28040                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
28041                                        float tf;
28042                                        float ox;
28043                                        float oy;
28044                                        tf = (float) (Math.expm1(ix));
28045                                        ox = (float) (tf*Math.cos(iy));
28046                                        oy = (float) (tf*Math.sin(iy));
28047                                        oc64data[it.oIndex] = ox;
28048                                        oc64data[it.oIndex + 1] = oy;
28049                                }
28050                        }
28051                        break;
28052                case Dataset.COMPLEX128:
28053                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
28054                        if (!da.isComplex()) {
28055                                if (it.isOutputDouble()) {
28056                                        final double iy = 0;
28057                                        while (it.hasNext()) {
28058                                                final double ix = it.aDouble;
28059                                                double tf;
28060                                                double ox;
28061                                                double oy;
28062                                                tf = (Math.expm1(ix));
28063                                                ox = (tf*Math.cos(iy));
28064                                                oy = (tf*Math.sin(iy));
28065                                                oc128data[it.oIndex] = ox;
28066                                                oc128data[it.oIndex + 1] = oy;
28067                                        }
28068                                } else {
28069                                        final long iy = 0;
28070                                        while (it.hasNext()) {
28071                                                final long ix = it.aLong;
28072                                                double tf;
28073                                                double ox;
28074                                                double oy;
28075                                                tf = (double) (Math.expm1(ix));
28076                                                ox = (double) (tf*Math.cos(iy));
28077                                                oy = (double) (tf*Math.sin(iy));
28078                                                oc128data[it.oIndex] = ox;
28079                                                oc128data[it.oIndex + 1] = oy;
28080                                        }
28081                                }
28082                        } else {
28083                                while (it.hasNext()) {
28084                                        final double ix = it.aDouble;
28085                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
28086                                        double tf;
28087                                        double ox;
28088                                        double oy;
28089                                        tf = (Math.expm1(ix));
28090                                        ox = (tf*Math.cos(iy));
28091                                        oy = (tf*Math.sin(iy));
28092                                        oc128data[it.oIndex] = ox;
28093                                        oc128data[it.oIndex + 1] = oy;
28094                                }
28095                        }
28096                        break;
28097                default:
28098                        throw new IllegalArgumentException("expm1 supports integer, compound integer, real, compound real, complex datasets only");
28099                }
28100
28101                addFunctionName(result, "expm1");
28102                return result;
28103        }
28104
28105        /**
28106         * sqrt - evaluate the square root function on each element of the dataset
28107         * @param a single operand
28108         * @return dataset
28109         */
28110        public static Dataset sqrt(final Object a) {
28111                return sqrt(a, null);
28112        }
28113
28114        /**
28115         * sqrt - evaluate the square root function on each element of the dataset
28116         * @param a single operand
28117         * @param o output can be null - in which case, a new dataset is created
28118         * @return dataset
28119         */
28120        public static Dataset sqrt(final Object a, final Dataset o) {
28121                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
28122                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
28123                final Dataset result = it.getOutput();
28124                if (!result.isComplex()) {
28125                        if (da.isComplex()) {
28126                                da = da.getRealView();
28127                                it = new SingleInputBroadcastIterator(da, result, true);
28128                        }
28129                }
28130                final int is = result.getElementsPerItem();
28131                final int as = da.getElementsPerItem();
28132                final int dt = result.getDType();
28133
28134                switch(dt) {
28135                case Dataset.INT8:
28136                        final byte[] oi8data = ((ByteDataset) result).getData();
28137                        if (it.isOutputDouble()) {
28138                                while (it.hasNext()) {
28139                                        final double ix = it.aDouble;
28140                                        byte ox;
28141                                        ox = (byte) toLong(Math.sqrt(ix));
28142                                        oi8data[it.oIndex] = ox;
28143                                }
28144                        } else {
28145                                while (it.hasNext()) {
28146                                        final long ix = it.aLong;
28147                                        byte ox;
28148                                        ox = (byte) toLong(Math.sqrt(ix));
28149                                        oi8data[it.oIndex] = ox;
28150                                }
28151                        }
28152                        break;
28153                case Dataset.INT16:
28154                        final short[] oi16data = ((ShortDataset) result).getData();
28155                        if (it.isOutputDouble()) {
28156                                while (it.hasNext()) {
28157                                        final double ix = it.aDouble;
28158                                        short ox;
28159                                        ox = (short) toLong(Math.sqrt(ix));
28160                                        oi16data[it.oIndex] = ox;
28161                                }
28162                        } else {
28163                                while (it.hasNext()) {
28164                                        final long ix = it.aLong;
28165                                        short ox;
28166                                        ox = (short) toLong(Math.sqrt(ix));
28167                                        oi16data[it.oIndex] = ox;
28168                                }
28169                        }
28170                        break;
28171                case Dataset.INT64:
28172                        final long[] oi64data = ((LongDataset) result).getData();
28173                        if (it.isOutputDouble()) {
28174                                while (it.hasNext()) {
28175                                        final double ix = it.aDouble;
28176                                        long ox;
28177                                        ox = toLong(Math.sqrt(ix));
28178                                        oi64data[it.oIndex] = ox;
28179                                }
28180                        } else {
28181                                while (it.hasNext()) {
28182                                        final long ix = it.aLong;
28183                                        long ox;
28184                                        ox = toLong(Math.sqrt(ix));
28185                                        oi64data[it.oIndex] = ox;
28186                                }
28187                        }
28188                        break;
28189                case Dataset.INT32:
28190                        final int[] oi32data = ((IntegerDataset) result).getData();
28191                        if (it.isOutputDouble()) {
28192                                while (it.hasNext()) {
28193                                        final double ix = it.aDouble;
28194                                        int ox;
28195                                        ox = (int) toLong(Math.sqrt(ix));
28196                                        oi32data[it.oIndex] = ox;
28197                                }
28198                        } else {
28199                                while (it.hasNext()) {
28200                                        final long ix = it.aLong;
28201                                        int ox;
28202                                        ox = (int) toLong(Math.sqrt(ix));
28203                                        oi32data[it.oIndex] = ox;
28204                                }
28205                        }
28206                        break;
28207                case Dataset.ARRAYINT8:
28208                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
28209                        if (is == 1) {
28210                                if (it.isOutputDouble()) {
28211                                        while (it.hasNext()) {
28212                                                final double ix = it.aDouble;
28213                                                byte ox;
28214                                                ox = (byte) toLong(Math.sqrt(ix));
28215                                                oai8data[it.oIndex] = ox;
28216                                        }
28217                                } else {
28218                                        while (it.hasNext()) {
28219                                                final long ix = it.aLong;
28220                                                byte ox;
28221                                                ox = (byte) toLong(Math.sqrt(ix));
28222                                                oai8data[it.oIndex] = ox;
28223                                        }
28224                                }
28225                        } else if (as == 1) {
28226                                if (it.isOutputDouble()) {
28227                                        while (it.hasNext()) {
28228                                                final double ix = it.aDouble;
28229                                                byte ox;
28230                                                ox = (byte) toLong(Math.sqrt(ix));
28231                                                for (int j = 0; j < is; j++) {
28232                                                        oai8data[it.oIndex + j] = ox;
28233                                                }
28234                                        }
28235                                } else {
28236                                        while (it.hasNext()) {
28237                                                final long ix = it.aLong;
28238                                                byte ox;
28239                                                ox = (byte) toLong(Math.sqrt(ix));
28240                                                for (int j = 0; j < is; j++) {
28241                                                        oai8data[it.oIndex + j] = ox;
28242                                                }
28243                                        }
28244                                }
28245                        } else {
28246                                if (it.isOutputDouble()) {
28247                                        while (it.hasNext()) {
28248                                                for (int j = 0; j < is; j++) {
28249                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28250                                                        byte ox;
28251                                                        ox = (byte) toLong(Math.sqrt(ix));
28252                                                        oai8data[it.oIndex + j] = ox;
28253                                                }
28254                                        }
28255                                } else {
28256                                        while (it.hasNext()) {
28257                                                for (int j = 0; j < is; j++) {
28258                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28259                                                        byte ox;
28260                                                        ox = (byte) toLong(Math.sqrt(ix));
28261                                                        oai8data[it.oIndex + j] = ox;
28262                                                }
28263                                        }
28264                                }
28265                        }
28266                        break;
28267                case Dataset.ARRAYINT16:
28268                        final short[] oai16data = ((CompoundShortDataset) result).getData();
28269                        if (is == 1) {
28270                                if (it.isOutputDouble()) {
28271                                        while (it.hasNext()) {
28272                                                final double ix = it.aDouble;
28273                                                short ox;
28274                                                ox = (short) toLong(Math.sqrt(ix));
28275                                                oai16data[it.oIndex] = ox;
28276                                        }
28277                                } else {
28278                                        while (it.hasNext()) {
28279                                                final long ix = it.aLong;
28280                                                short ox;
28281                                                ox = (short) toLong(Math.sqrt(ix));
28282                                                oai16data[it.oIndex] = ox;
28283                                        }
28284                                }
28285                        } else if (as == 1) {
28286                                if (it.isOutputDouble()) {
28287                                        while (it.hasNext()) {
28288                                                final double ix = it.aDouble;
28289                                                short ox;
28290                                                ox = (short) toLong(Math.sqrt(ix));
28291                                                for (int j = 0; j < is; j++) {
28292                                                        oai16data[it.oIndex + j] = ox;
28293                                                }
28294                                        }
28295                                } else {
28296                                        while (it.hasNext()) {
28297                                                final long ix = it.aLong;
28298                                                short ox;
28299                                                ox = (short) toLong(Math.sqrt(ix));
28300                                                for (int j = 0; j < is; j++) {
28301                                                        oai16data[it.oIndex + j] = ox;
28302                                                }
28303                                        }
28304                                }
28305                        } else {
28306                                if (it.isOutputDouble()) {
28307                                        while (it.hasNext()) {
28308                                                for (int j = 0; j < is; j++) {
28309                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28310                                                        short ox;
28311                                                        ox = (short) toLong(Math.sqrt(ix));
28312                                                        oai16data[it.oIndex + j] = ox;
28313                                                }
28314                                        }
28315                                } else {
28316                                        while (it.hasNext()) {
28317                                                for (int j = 0; j < is; j++) {
28318                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28319                                                        short ox;
28320                                                        ox = (short) toLong(Math.sqrt(ix));
28321                                                        oai16data[it.oIndex + j] = ox;
28322                                                }
28323                                        }
28324                                }
28325                        }
28326                        break;
28327                case Dataset.ARRAYINT64:
28328                        final long[] oai64data = ((CompoundLongDataset) result).getData();
28329                        if (is == 1) {
28330                                if (it.isOutputDouble()) {
28331                                        while (it.hasNext()) {
28332                                                final double ix = it.aDouble;
28333                                                long ox;
28334                                                ox = toLong(Math.sqrt(ix));
28335                                                oai64data[it.oIndex] = ox;
28336                                        }
28337                                } else {
28338                                        while (it.hasNext()) {
28339                                                final long ix = it.aLong;
28340                                                long ox;
28341                                                ox = toLong(Math.sqrt(ix));
28342                                                oai64data[it.oIndex] = ox;
28343                                        }
28344                                }
28345                        } else if (as == 1) {
28346                                if (it.isOutputDouble()) {
28347                                        while (it.hasNext()) {
28348                                                final double ix = it.aDouble;
28349                                                long ox;
28350                                                ox = toLong(Math.sqrt(ix));
28351                                                for (int j = 0; j < is; j++) {
28352                                                        oai64data[it.oIndex + j] = ox;
28353                                                }
28354                                        }
28355                                } else {
28356                                        while (it.hasNext()) {
28357                                                final long ix = it.aLong;
28358                                                long ox;
28359                                                ox = toLong(Math.sqrt(ix));
28360                                                for (int j = 0; j < is; j++) {
28361                                                        oai64data[it.oIndex + j] = ox;
28362                                                }
28363                                        }
28364                                }
28365                        } else {
28366                                if (it.isOutputDouble()) {
28367                                        while (it.hasNext()) {
28368                                                for (int j = 0; j < is; j++) {
28369                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28370                                                        long ox;
28371                                                        ox = toLong(Math.sqrt(ix));
28372                                                        oai64data[it.oIndex + j] = ox;
28373                                                }
28374                                        }
28375                                } else {
28376                                        while (it.hasNext()) {
28377                                                for (int j = 0; j < is; j++) {
28378                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28379                                                        long ox;
28380                                                        ox = toLong(Math.sqrt(ix));
28381                                                        oai64data[it.oIndex + j] = ox;
28382                                                }
28383                                        }
28384                                }
28385                        }
28386                        break;
28387                case Dataset.ARRAYINT32:
28388                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
28389                        if (is == 1) {
28390                                if (it.isOutputDouble()) {
28391                                        while (it.hasNext()) {
28392                                                final double ix = it.aDouble;
28393                                                int ox;
28394                                                ox = (int) toLong(Math.sqrt(ix));
28395                                                oai32data[it.oIndex] = ox;
28396                                        }
28397                                } else {
28398                                        while (it.hasNext()) {
28399                                                final long ix = it.aLong;
28400                                                int ox;
28401                                                ox = (int) toLong(Math.sqrt(ix));
28402                                                oai32data[it.oIndex] = ox;
28403                                        }
28404                                }
28405                        } else if (as == 1) {
28406                                if (it.isOutputDouble()) {
28407                                        while (it.hasNext()) {
28408                                                final double ix = it.aDouble;
28409                                                int ox;
28410                                                ox = (int) toLong(Math.sqrt(ix));
28411                                                for (int j = 0; j < is; j++) {
28412                                                        oai32data[it.oIndex + j] = ox;
28413                                                }
28414                                        }
28415                                } else {
28416                                        while (it.hasNext()) {
28417                                                final long ix = it.aLong;
28418                                                int ox;
28419                                                ox = (int) toLong(Math.sqrt(ix));
28420                                                for (int j = 0; j < is; j++) {
28421                                                        oai32data[it.oIndex + j] = ox;
28422                                                }
28423                                        }
28424                                }
28425                        } else {
28426                                if (it.isOutputDouble()) {
28427                                        while (it.hasNext()) {
28428                                                for (int j = 0; j < is; j++) {
28429                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28430                                                        int ox;
28431                                                        ox = (int) toLong(Math.sqrt(ix));
28432                                                        oai32data[it.oIndex + j] = ox;
28433                                                }
28434                                        }
28435                                } else {
28436                                        while (it.hasNext()) {
28437                                                for (int j = 0; j < is; j++) {
28438                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28439                                                        int ox;
28440                                                        ox = (int) toLong(Math.sqrt(ix));
28441                                                        oai32data[it.oIndex + j] = ox;
28442                                                }
28443                                        }
28444                                }
28445                        }
28446                        break;
28447                case Dataset.FLOAT32:
28448                        final float[] of32data = ((FloatDataset) result).getData();
28449                        if (it.isOutputDouble()) {
28450                                while (it.hasNext()) {
28451                                        final double ix = it.aDouble;
28452                                        float ox;
28453                                        ox = (float) (Math.sqrt(ix));
28454                                        of32data[it.oIndex] = ox;
28455                                }
28456                        } else {
28457                                while (it.hasNext()) {
28458                                        final long ix = it.aLong;
28459                                        float ox;
28460                                        ox = (float) (Math.sqrt(ix));
28461                                        of32data[it.oIndex] = ox;
28462                                }
28463                        }
28464                        break;
28465                case Dataset.FLOAT64:
28466                        final double[] of64data = ((DoubleDataset) result).getData();
28467                        if (it.isOutputDouble()) {
28468                                while (it.hasNext()) {
28469                                        final double ix = it.aDouble;
28470                                        double ox;
28471                                        ox = (Math.sqrt(ix));
28472                                        of64data[it.oIndex] = ox;
28473                                }
28474                        } else {
28475                                while (it.hasNext()) {
28476                                        final long ix = it.aLong;
28477                                        double ox;
28478                                        ox = (Math.sqrt(ix));
28479                                        of64data[it.oIndex] = ox;
28480                                }
28481                        }
28482                        break;
28483                case Dataset.ARRAYFLOAT32:
28484                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
28485                        if (is == 1) {
28486                                if (it.isOutputDouble()) {
28487                                        while (it.hasNext()) {
28488                                                final double ix = it.aDouble;
28489                                                float ox;
28490                                                ox = (float) (Math.sqrt(ix));
28491                                                oaf32data[it.oIndex] = ox;
28492                                        }
28493                                } else {
28494                                        while (it.hasNext()) {
28495                                                final long ix = it.aLong;
28496                                                float ox;
28497                                                ox = (float) (Math.sqrt(ix));
28498                                                oaf32data[it.oIndex] = ox;
28499                                        }
28500                                }
28501                        } else if (as == 1) {
28502                                if (it.isOutputDouble()) {
28503                                        while (it.hasNext()) {
28504                                                final double ix = it.aDouble;
28505                                                float ox;
28506                                                ox = (float) (Math.sqrt(ix));
28507                                                for (int j = 0; j < is; j++) {
28508                                                        oaf32data[it.oIndex + j] = ox;
28509                                                }
28510                                        }
28511                                } else {
28512                                        while (it.hasNext()) {
28513                                                final long ix = it.aLong;
28514                                                float ox;
28515                                                ox = (float) (Math.sqrt(ix));
28516                                                for (int j = 0; j < is; j++) {
28517                                                        oaf32data[it.oIndex + j] = ox;
28518                                                }
28519                                        }
28520                                }
28521                        } else {
28522                                if (it.isOutputDouble()) {
28523                                        while (it.hasNext()) {
28524                                                for (int j = 0; j < is; j++) {
28525                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28526                                                        float ox;
28527                                                        ox = (float) (Math.sqrt(ix));
28528                                                        oaf32data[it.oIndex + j] = ox;
28529                                                }
28530                                        }
28531                                } else {
28532                                        while (it.hasNext()) {
28533                                                for (int j = 0; j < is; j++) {
28534                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28535                                                        float ox;
28536                                                        ox = (float) (Math.sqrt(ix));
28537                                                        oaf32data[it.oIndex + j] = ox;
28538                                                }
28539                                        }
28540                                }
28541                        }
28542                        break;
28543                case Dataset.ARRAYFLOAT64:
28544                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
28545                        if (is == 1) {
28546                                if (it.isOutputDouble()) {
28547                                        while (it.hasNext()) {
28548                                                final double ix = it.aDouble;
28549                                                double ox;
28550                                                ox = (Math.sqrt(ix));
28551                                                oaf64data[it.oIndex] = ox;
28552                                        }
28553                                } else {
28554                                        while (it.hasNext()) {
28555                                                final long ix = it.aLong;
28556                                                double ox;
28557                                                ox = (Math.sqrt(ix));
28558                                                oaf64data[it.oIndex] = ox;
28559                                        }
28560                                }
28561                        } else if (as == 1) {
28562                                if (it.isOutputDouble()) {
28563                                        while (it.hasNext()) {
28564                                                final double ix = it.aDouble;
28565                                                double ox;
28566                                                ox = (Math.sqrt(ix));
28567                                                for (int j = 0; j < is; j++) {
28568                                                        oaf64data[it.oIndex + j] = ox;
28569                                                }
28570                                        }
28571                                } else {
28572                                        while (it.hasNext()) {
28573                                                final long ix = it.aLong;
28574                                                double ox;
28575                                                ox = (Math.sqrt(ix));
28576                                                for (int j = 0; j < is; j++) {
28577                                                        oaf64data[it.oIndex + j] = ox;
28578                                                }
28579                                        }
28580                                }
28581                        } else {
28582                                if (it.isOutputDouble()) {
28583                                        while (it.hasNext()) {
28584                                                for (int j = 0; j < is; j++) {
28585                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28586                                                        double ox;
28587                                                        ox = (Math.sqrt(ix));
28588                                                        oaf64data[it.oIndex + j] = ox;
28589                                                }
28590                                        }
28591                                } else {
28592                                        while (it.hasNext()) {
28593                                                for (int j = 0; j < is; j++) {
28594                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28595                                                        double ox;
28596                                                        ox = (Math.sqrt(ix));
28597                                                        oaf64data[it.oIndex + j] = ox;
28598                                                }
28599                                        }
28600                                }
28601                        }
28602                        break;
28603                case Dataset.COMPLEX64:
28604                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
28605                        if (!da.isComplex()) {
28606                                if (it.isOutputDouble()) {
28607                                        final double iy = 0;
28608                                        while (it.hasNext()) {
28609                                                final double ix = it.aDouble;
28610                                                Complex tz;
28611                                                float ox;
28612                                                float oy;
28613                                                tz = new Complex(ix, iy).sqrt();
28614                                                ox = (float) (tz.getReal());
28615                                                oy = (float) (tz.getImaginary());
28616                                                oc64data[it.oIndex] = ox;
28617                                                oc64data[it.oIndex + 1] = oy;
28618                                        }
28619                                } else {
28620                                        final long iy = 0;
28621                                        while (it.hasNext()) {
28622                                                final long ix = it.aLong;
28623                                                Complex tz;
28624                                                float ox;
28625                                                float oy;
28626                                                tz = new Complex(ix, iy).sqrt();
28627                                                ox = (float) toLong(tz.getReal());
28628                                                oy = (float) toLong(tz.getImaginary());
28629                                                oc64data[it.oIndex] = ox;
28630                                                oc64data[it.oIndex + 1] = oy;
28631                                        }
28632                                }
28633                        } else {
28634                                while (it.hasNext()) {
28635                                        final double ix = it.aDouble;
28636                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
28637                                        Complex tz;
28638                                        float ox;
28639                                        float oy;
28640                                        tz = new Complex(ix, iy).sqrt();
28641                                        ox = (float) (tz.getReal());
28642                                        oy = (float) (tz.getImaginary());
28643                                        oc64data[it.oIndex] = ox;
28644                                        oc64data[it.oIndex + 1] = oy;
28645                                }
28646                        }
28647                        break;
28648                case Dataset.COMPLEX128:
28649                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
28650                        if (!da.isComplex()) {
28651                                if (it.isOutputDouble()) {
28652                                        final double iy = 0;
28653                                        while (it.hasNext()) {
28654                                                final double ix = it.aDouble;
28655                                                Complex tz;
28656                                                double ox;
28657                                                double oy;
28658                                                tz = new Complex(ix, iy).sqrt();
28659                                                ox = (tz.getReal());
28660                                                oy = (tz.getImaginary());
28661                                                oc128data[it.oIndex] = ox;
28662                                                oc128data[it.oIndex + 1] = oy;
28663                                        }
28664                                } else {
28665                                        final long iy = 0;
28666                                        while (it.hasNext()) {
28667                                                final long ix = it.aLong;
28668                                                Complex tz;
28669                                                double ox;
28670                                                double oy;
28671                                                tz = new Complex(ix, iy).sqrt();
28672                                                ox = (tz.getReal());
28673                                                oy = (tz.getImaginary());
28674                                                oc128data[it.oIndex] = ox;
28675                                                oc128data[it.oIndex + 1] = oy;
28676                                        }
28677                                }
28678                        } else {
28679                                while (it.hasNext()) {
28680                                        final double ix = it.aDouble;
28681                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
28682                                        Complex tz;
28683                                        double ox;
28684                                        double oy;
28685                                        tz = new Complex(ix, iy).sqrt();
28686                                        ox = (tz.getReal());
28687                                        oy = (tz.getImaginary());
28688                                        oc128data[it.oIndex] = ox;
28689                                        oc128data[it.oIndex + 1] = oy;
28690                                }
28691                        }
28692                        break;
28693                default:
28694                        throw new IllegalArgumentException("sqrt supports integer, compound integer, real, compound real, complex datasets only");
28695                }
28696
28697                addFunctionName(result, "sqrt");
28698                return result;
28699        }
28700
28701        /**
28702         * cbrt - evaluate the cube root function on each element of the dataset
28703         * @param a single operand
28704         * @return dataset
28705         */
28706        public static Dataset cbrt(final Object a) {
28707                return cbrt(a, null);
28708        }
28709
28710        /**
28711         * cbrt - evaluate the cube root function on each element of the dataset
28712         * @param a single operand
28713         * @param o output can be null - in which case, a new dataset is created
28714         * @return dataset
28715         */
28716        public static Dataset cbrt(final Object a, final Dataset o) {
28717                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
28718                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
28719                final Dataset result = it.getOutput();
28720                if (!result.isComplex()) {
28721                        if (da.isComplex()) {
28722                                da = da.getRealView();
28723                                it = new SingleInputBroadcastIterator(da, result, true);
28724                        }
28725                }
28726                final int is = result.getElementsPerItem();
28727                final int as = da.getElementsPerItem();
28728                final int dt = result.getDType();
28729
28730                switch(dt) {
28731                case Dataset.INT8:
28732                        final byte[] oi8data = ((ByteDataset) result).getData();
28733                        if (it.isOutputDouble()) {
28734                                while (it.hasNext()) {
28735                                        final double ix = it.aDouble;
28736                                        byte ox;
28737                                        ox = (byte) toLong(Math.cbrt(ix));
28738                                        oi8data[it.oIndex] = ox;
28739                                }
28740                        } else {
28741                                while (it.hasNext()) {
28742                                        final long ix = it.aLong;
28743                                        byte ox;
28744                                        ox = (byte) toLong(Math.cbrt(ix));
28745                                        oi8data[it.oIndex] = ox;
28746                                }
28747                        }
28748                        break;
28749                case Dataset.INT16:
28750                        final short[] oi16data = ((ShortDataset) result).getData();
28751                        if (it.isOutputDouble()) {
28752                                while (it.hasNext()) {
28753                                        final double ix = it.aDouble;
28754                                        short ox;
28755                                        ox = (short) toLong(Math.cbrt(ix));
28756                                        oi16data[it.oIndex] = ox;
28757                                }
28758                        } else {
28759                                while (it.hasNext()) {
28760                                        final long ix = it.aLong;
28761                                        short ox;
28762                                        ox = (short) toLong(Math.cbrt(ix));
28763                                        oi16data[it.oIndex] = ox;
28764                                }
28765                        }
28766                        break;
28767                case Dataset.INT64:
28768                        final long[] oi64data = ((LongDataset) result).getData();
28769                        if (it.isOutputDouble()) {
28770                                while (it.hasNext()) {
28771                                        final double ix = it.aDouble;
28772                                        long ox;
28773                                        ox = toLong(Math.cbrt(ix));
28774                                        oi64data[it.oIndex] = ox;
28775                                }
28776                        } else {
28777                                while (it.hasNext()) {
28778                                        final long ix = it.aLong;
28779                                        long ox;
28780                                        ox = toLong(Math.cbrt(ix));
28781                                        oi64data[it.oIndex] = ox;
28782                                }
28783                        }
28784                        break;
28785                case Dataset.INT32:
28786                        final int[] oi32data = ((IntegerDataset) result).getData();
28787                        if (it.isOutputDouble()) {
28788                                while (it.hasNext()) {
28789                                        final double ix = it.aDouble;
28790                                        int ox;
28791                                        ox = (int) toLong(Math.cbrt(ix));
28792                                        oi32data[it.oIndex] = ox;
28793                                }
28794                        } else {
28795                                while (it.hasNext()) {
28796                                        final long ix = it.aLong;
28797                                        int ox;
28798                                        ox = (int) toLong(Math.cbrt(ix));
28799                                        oi32data[it.oIndex] = ox;
28800                                }
28801                        }
28802                        break;
28803                case Dataset.ARRAYINT8:
28804                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
28805                        if (is == 1) {
28806                                if (it.isOutputDouble()) {
28807                                        while (it.hasNext()) {
28808                                                final double ix = it.aDouble;
28809                                                byte ox;
28810                                                ox = (byte) toLong(Math.cbrt(ix));
28811                                                oai8data[it.oIndex] = ox;
28812                                        }
28813                                } else {
28814                                        while (it.hasNext()) {
28815                                                final long ix = it.aLong;
28816                                                byte ox;
28817                                                ox = (byte) toLong(Math.cbrt(ix));
28818                                                oai8data[it.oIndex] = ox;
28819                                        }
28820                                }
28821                        } else if (as == 1) {
28822                                if (it.isOutputDouble()) {
28823                                        while (it.hasNext()) {
28824                                                final double ix = it.aDouble;
28825                                                byte ox;
28826                                                ox = (byte) toLong(Math.cbrt(ix));
28827                                                for (int j = 0; j < is; j++) {
28828                                                        oai8data[it.oIndex + j] = ox;
28829                                                }
28830                                        }
28831                                } else {
28832                                        while (it.hasNext()) {
28833                                                final long ix = it.aLong;
28834                                                byte ox;
28835                                                ox = (byte) toLong(Math.cbrt(ix));
28836                                                for (int j = 0; j < is; j++) {
28837                                                        oai8data[it.oIndex + j] = ox;
28838                                                }
28839                                        }
28840                                }
28841                        } else {
28842                                if (it.isOutputDouble()) {
28843                                        while (it.hasNext()) {
28844                                                for (int j = 0; j < is; j++) {
28845                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28846                                                        byte ox;
28847                                                        ox = (byte) toLong(Math.cbrt(ix));
28848                                                        oai8data[it.oIndex + j] = ox;
28849                                                }
28850                                        }
28851                                } else {
28852                                        while (it.hasNext()) {
28853                                                for (int j = 0; j < is; j++) {
28854                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28855                                                        byte ox;
28856                                                        ox = (byte) toLong(Math.cbrt(ix));
28857                                                        oai8data[it.oIndex + j] = ox;
28858                                                }
28859                                        }
28860                                }
28861                        }
28862                        break;
28863                case Dataset.ARRAYINT16:
28864                        final short[] oai16data = ((CompoundShortDataset) result).getData();
28865                        if (is == 1) {
28866                                if (it.isOutputDouble()) {
28867                                        while (it.hasNext()) {
28868                                                final double ix = it.aDouble;
28869                                                short ox;
28870                                                ox = (short) toLong(Math.cbrt(ix));
28871                                                oai16data[it.oIndex] = ox;
28872                                        }
28873                                } else {
28874                                        while (it.hasNext()) {
28875                                                final long ix = it.aLong;
28876                                                short ox;
28877                                                ox = (short) toLong(Math.cbrt(ix));
28878                                                oai16data[it.oIndex] = ox;
28879                                        }
28880                                }
28881                        } else if (as == 1) {
28882                                if (it.isOutputDouble()) {
28883                                        while (it.hasNext()) {
28884                                                final double ix = it.aDouble;
28885                                                short ox;
28886                                                ox = (short) toLong(Math.cbrt(ix));
28887                                                for (int j = 0; j < is; j++) {
28888                                                        oai16data[it.oIndex + j] = ox;
28889                                                }
28890                                        }
28891                                } else {
28892                                        while (it.hasNext()) {
28893                                                final long ix = it.aLong;
28894                                                short ox;
28895                                                ox = (short) toLong(Math.cbrt(ix));
28896                                                for (int j = 0; j < is; j++) {
28897                                                        oai16data[it.oIndex + j] = ox;
28898                                                }
28899                                        }
28900                                }
28901                        } else {
28902                                if (it.isOutputDouble()) {
28903                                        while (it.hasNext()) {
28904                                                for (int j = 0; j < is; j++) {
28905                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28906                                                        short ox;
28907                                                        ox = (short) toLong(Math.cbrt(ix));
28908                                                        oai16data[it.oIndex + j] = ox;
28909                                                }
28910                                        }
28911                                } else {
28912                                        while (it.hasNext()) {
28913                                                for (int j = 0; j < is; j++) {
28914                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28915                                                        short ox;
28916                                                        ox = (short) toLong(Math.cbrt(ix));
28917                                                        oai16data[it.oIndex + j] = ox;
28918                                                }
28919                                        }
28920                                }
28921                        }
28922                        break;
28923                case Dataset.ARRAYINT64:
28924                        final long[] oai64data = ((CompoundLongDataset) result).getData();
28925                        if (is == 1) {
28926                                if (it.isOutputDouble()) {
28927                                        while (it.hasNext()) {
28928                                                final double ix = it.aDouble;
28929                                                long ox;
28930                                                ox = toLong(Math.cbrt(ix));
28931                                                oai64data[it.oIndex] = ox;
28932                                        }
28933                                } else {
28934                                        while (it.hasNext()) {
28935                                                final long ix = it.aLong;
28936                                                long ox;
28937                                                ox = toLong(Math.cbrt(ix));
28938                                                oai64data[it.oIndex] = ox;
28939                                        }
28940                                }
28941                        } else if (as == 1) {
28942                                if (it.isOutputDouble()) {
28943                                        while (it.hasNext()) {
28944                                                final double ix = it.aDouble;
28945                                                long ox;
28946                                                ox = toLong(Math.cbrt(ix));
28947                                                for (int j = 0; j < is; j++) {
28948                                                        oai64data[it.oIndex + j] = ox;
28949                                                }
28950                                        }
28951                                } else {
28952                                        while (it.hasNext()) {
28953                                                final long ix = it.aLong;
28954                                                long ox;
28955                                                ox = toLong(Math.cbrt(ix));
28956                                                for (int j = 0; j < is; j++) {
28957                                                        oai64data[it.oIndex + j] = ox;
28958                                                }
28959                                        }
28960                                }
28961                        } else {
28962                                if (it.isOutputDouble()) {
28963                                        while (it.hasNext()) {
28964                                                for (int j = 0; j < is; j++) {
28965                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
28966                                                        long ox;
28967                                                        ox = toLong(Math.cbrt(ix));
28968                                                        oai64data[it.oIndex + j] = ox;
28969                                                }
28970                                        }
28971                                } else {
28972                                        while (it.hasNext()) {
28973                                                for (int j = 0; j < is; j++) {
28974                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
28975                                                        long ox;
28976                                                        ox = toLong(Math.cbrt(ix));
28977                                                        oai64data[it.oIndex + j] = ox;
28978                                                }
28979                                        }
28980                                }
28981                        }
28982                        break;
28983                case Dataset.ARRAYINT32:
28984                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
28985                        if (is == 1) {
28986                                if (it.isOutputDouble()) {
28987                                        while (it.hasNext()) {
28988                                                final double ix = it.aDouble;
28989                                                int ox;
28990                                                ox = (int) toLong(Math.cbrt(ix));
28991                                                oai32data[it.oIndex] = ox;
28992                                        }
28993                                } else {
28994                                        while (it.hasNext()) {
28995                                                final long ix = it.aLong;
28996                                                int ox;
28997                                                ox = (int) toLong(Math.cbrt(ix));
28998                                                oai32data[it.oIndex] = ox;
28999                                        }
29000                                }
29001                        } else if (as == 1) {
29002                                if (it.isOutputDouble()) {
29003                                        while (it.hasNext()) {
29004                                                final double ix = it.aDouble;
29005                                                int ox;
29006                                                ox = (int) toLong(Math.cbrt(ix));
29007                                                for (int j = 0; j < is; j++) {
29008                                                        oai32data[it.oIndex + j] = ox;
29009                                                }
29010                                        }
29011                                } else {
29012                                        while (it.hasNext()) {
29013                                                final long ix = it.aLong;
29014                                                int ox;
29015                                                ox = (int) toLong(Math.cbrt(ix));
29016                                                for (int j = 0; j < is; j++) {
29017                                                        oai32data[it.oIndex + j] = ox;
29018                                                }
29019                                        }
29020                                }
29021                        } else {
29022                                if (it.isOutputDouble()) {
29023                                        while (it.hasNext()) {
29024                                                for (int j = 0; j < is; j++) {
29025                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29026                                                        int ox;
29027                                                        ox = (int) toLong(Math.cbrt(ix));
29028                                                        oai32data[it.oIndex + j] = ox;
29029                                                }
29030                                        }
29031                                } else {
29032                                        while (it.hasNext()) {
29033                                                for (int j = 0; j < is; j++) {
29034                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29035                                                        int ox;
29036                                                        ox = (int) toLong(Math.cbrt(ix));
29037                                                        oai32data[it.oIndex + j] = ox;
29038                                                }
29039                                        }
29040                                }
29041                        }
29042                        break;
29043                case Dataset.FLOAT32:
29044                        final float[] of32data = ((FloatDataset) result).getData();
29045                        if (it.isOutputDouble()) {
29046                                while (it.hasNext()) {
29047                                        final double ix = it.aDouble;
29048                                        float ox;
29049                                        ox = (float) (Math.cbrt(ix));
29050                                        of32data[it.oIndex] = ox;
29051                                }
29052                        } else {
29053                                while (it.hasNext()) {
29054                                        final long ix = it.aLong;
29055                                        float ox;
29056                                        ox = (float) (Math.cbrt(ix));
29057                                        of32data[it.oIndex] = ox;
29058                                }
29059                        }
29060                        break;
29061                case Dataset.FLOAT64:
29062                        final double[] of64data = ((DoubleDataset) result).getData();
29063                        if (it.isOutputDouble()) {
29064                                while (it.hasNext()) {
29065                                        final double ix = it.aDouble;
29066                                        double ox;
29067                                        ox = (Math.cbrt(ix));
29068                                        of64data[it.oIndex] = ox;
29069                                }
29070                        } else {
29071                                while (it.hasNext()) {
29072                                        final long ix = it.aLong;
29073                                        double ox;
29074                                        ox = (Math.cbrt(ix));
29075                                        of64data[it.oIndex] = ox;
29076                                }
29077                        }
29078                        break;
29079                case Dataset.ARRAYFLOAT32:
29080                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
29081                        if (is == 1) {
29082                                if (it.isOutputDouble()) {
29083                                        while (it.hasNext()) {
29084                                                final double ix = it.aDouble;
29085                                                float ox;
29086                                                ox = (float) (Math.cbrt(ix));
29087                                                oaf32data[it.oIndex] = ox;
29088                                        }
29089                                } else {
29090                                        while (it.hasNext()) {
29091                                                final long ix = it.aLong;
29092                                                float ox;
29093                                                ox = (float) (Math.cbrt(ix));
29094                                                oaf32data[it.oIndex] = ox;
29095                                        }
29096                                }
29097                        } else if (as == 1) {
29098                                if (it.isOutputDouble()) {
29099                                        while (it.hasNext()) {
29100                                                final double ix = it.aDouble;
29101                                                float ox;
29102                                                ox = (float) (Math.cbrt(ix));
29103                                                for (int j = 0; j < is; j++) {
29104                                                        oaf32data[it.oIndex + j] = ox;
29105                                                }
29106                                        }
29107                                } else {
29108                                        while (it.hasNext()) {
29109                                                final long ix = it.aLong;
29110                                                float ox;
29111                                                ox = (float) (Math.cbrt(ix));
29112                                                for (int j = 0; j < is; j++) {
29113                                                        oaf32data[it.oIndex + j] = ox;
29114                                                }
29115                                        }
29116                                }
29117                        } else {
29118                                if (it.isOutputDouble()) {
29119                                        while (it.hasNext()) {
29120                                                for (int j = 0; j < is; j++) {
29121                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29122                                                        float ox;
29123                                                        ox = (float) (Math.cbrt(ix));
29124                                                        oaf32data[it.oIndex + j] = ox;
29125                                                }
29126                                        }
29127                                } else {
29128                                        while (it.hasNext()) {
29129                                                for (int j = 0; j < is; j++) {
29130                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29131                                                        float ox;
29132                                                        ox = (float) (Math.cbrt(ix));
29133                                                        oaf32data[it.oIndex + j] = ox;
29134                                                }
29135                                        }
29136                                }
29137                        }
29138                        break;
29139                case Dataset.ARRAYFLOAT64:
29140                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
29141                        if (is == 1) {
29142                                if (it.isOutputDouble()) {
29143                                        while (it.hasNext()) {
29144                                                final double ix = it.aDouble;
29145                                                double ox;
29146                                                ox = (Math.cbrt(ix));
29147                                                oaf64data[it.oIndex] = ox;
29148                                        }
29149                                } else {
29150                                        while (it.hasNext()) {
29151                                                final long ix = it.aLong;
29152                                                double ox;
29153                                                ox = (Math.cbrt(ix));
29154                                                oaf64data[it.oIndex] = ox;
29155                                        }
29156                                }
29157                        } else if (as == 1) {
29158                                if (it.isOutputDouble()) {
29159                                        while (it.hasNext()) {
29160                                                final double ix = it.aDouble;
29161                                                double ox;
29162                                                ox = (Math.cbrt(ix));
29163                                                for (int j = 0; j < is; j++) {
29164                                                        oaf64data[it.oIndex + j] = ox;
29165                                                }
29166                                        }
29167                                } else {
29168                                        while (it.hasNext()) {
29169                                                final long ix = it.aLong;
29170                                                double ox;
29171                                                ox = (Math.cbrt(ix));
29172                                                for (int j = 0; j < is; j++) {
29173                                                        oaf64data[it.oIndex + j] = ox;
29174                                                }
29175                                        }
29176                                }
29177                        } else {
29178                                if (it.isOutputDouble()) {
29179                                        while (it.hasNext()) {
29180                                                for (int j = 0; j < is; j++) {
29181                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29182                                                        double ox;
29183                                                        ox = (Math.cbrt(ix));
29184                                                        oaf64data[it.oIndex + j] = ox;
29185                                                }
29186                                        }
29187                                } else {
29188                                        while (it.hasNext()) {
29189                                                for (int j = 0; j < is; j++) {
29190                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29191                                                        double ox;
29192                                                        ox = (Math.cbrt(ix));
29193                                                        oaf64data[it.oIndex + j] = ox;
29194                                                }
29195                                        }
29196                                }
29197                        }
29198                        break;
29199                case Dataset.COMPLEX64:
29200                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
29201                        if (!da.isComplex()) {
29202                                if (it.isOutputDouble()) {
29203                                        final double iy = 0;
29204                                        while (it.hasNext()) {
29205                                                final double ix = it.aDouble;
29206                                                Complex tz;
29207                                                float ox;
29208                                                float oy;
29209                                                tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
29210                                                ox = (float) (tz.getReal());
29211                                                oy = (float) (tz.getImaginary());
29212                                                oc64data[it.oIndex] = ox;
29213                                                oc64data[it.oIndex + 1] = oy;
29214                                        }
29215                                } else {
29216                                        final long iy = 0;
29217                                        while (it.hasNext()) {
29218                                                final long ix = it.aLong;
29219                                                Complex tz;
29220                                                float ox;
29221                                                float oy;
29222                                                tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
29223                                                ox = (float) toLong(tz.getReal());
29224                                                oy = (float) toLong(tz.getImaginary());
29225                                                oc64data[it.oIndex] = ox;
29226                                                oc64data[it.oIndex + 1] = oy;
29227                                        }
29228                                }
29229                        } else {
29230                                while (it.hasNext()) {
29231                                        final double ix = it.aDouble;
29232                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
29233                                        Complex tz;
29234                                        float ox;
29235                                        float oy;
29236                                        tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
29237                                        ox = (float) (tz.getReal());
29238                                        oy = (float) (tz.getImaginary());
29239                                        oc64data[it.oIndex] = ox;
29240                                        oc64data[it.oIndex + 1] = oy;
29241                                }
29242                        }
29243                        break;
29244                case Dataset.COMPLEX128:
29245                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
29246                        if (!da.isComplex()) {
29247                                if (it.isOutputDouble()) {
29248                                        final double iy = 0;
29249                                        while (it.hasNext()) {
29250                                                final double ix = it.aDouble;
29251                                                Complex tz;
29252                                                double ox;
29253                                                double oy;
29254                                                tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
29255                                                ox = (tz.getReal());
29256                                                oy = (tz.getImaginary());
29257                                                oc128data[it.oIndex] = ox;
29258                                                oc128data[it.oIndex + 1] = oy;
29259                                        }
29260                                } else {
29261                                        final long iy = 0;
29262                                        while (it.hasNext()) {
29263                                                final long ix = it.aLong;
29264                                                Complex tz;
29265                                                double ox;
29266                                                double oy;
29267                                                tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
29268                                                ox = (tz.getReal());
29269                                                oy = (tz.getImaginary());
29270                                                oc128data[it.oIndex] = ox;
29271                                                oc128data[it.oIndex + 1] = oy;
29272                                        }
29273                                }
29274                        } else {
29275                                while (it.hasNext()) {
29276                                        final double ix = it.aDouble;
29277                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
29278                                        Complex tz;
29279                                        double ox;
29280                                        double oy;
29281                                        tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
29282                                        ox = (tz.getReal());
29283                                        oy = (tz.getImaginary());
29284                                        oc128data[it.oIndex] = ox;
29285                                        oc128data[it.oIndex + 1] = oy;
29286                                }
29287                        }
29288                        break;
29289                default:
29290                        throw new IllegalArgumentException("cbrt supports integer, compound integer, real, compound real, complex datasets only");
29291                }
29292
29293                addFunctionName(result, "cbrt");
29294                return result;
29295        }
29296
29297        /**
29298         * square - square each element
29299         * @param a single operand
29300         * @return dataset
29301         */
29302        public static Dataset square(final Object a) {
29303                return square(a, null);
29304        }
29305
29306        /**
29307         * square - square each element
29308         * @param a single operand
29309         * @param o output can be null - in which case, a new dataset is created
29310         * @return dataset
29311         */
29312        public static Dataset square(final Object a, final Dataset o) {
29313                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
29314                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
29315                final Dataset result = it.getOutput();
29316                if (!result.isComplex()) {
29317                        if (da.isComplex()) {
29318                                da = da.getRealView();
29319                                it = new SingleInputBroadcastIterator(da, result, true);
29320                        }
29321                }
29322                final int is = result.getElementsPerItem();
29323                final int as = da.getElementsPerItem();
29324                final int dt = result.getDType();
29325
29326                switch(dt) {
29327                case Dataset.INT8:
29328                        final byte[] oi8data = ((ByteDataset) result).getData();
29329                        if (it.isOutputDouble()) {
29330                                while (it.hasNext()) {
29331                                        final double ix = it.aDouble;
29332                                        byte ox;
29333                                        ox = (byte) toLong(ix*ix);
29334                                        oi8data[it.oIndex] = ox;
29335                                }
29336                        } else {
29337                                while (it.hasNext()) {
29338                                        final long ix = it.aLong;
29339                                        byte ox;
29340                                        ox = (byte) toLong(ix*ix);
29341                                        oi8data[it.oIndex] = ox;
29342                                }
29343                        }
29344                        break;
29345                case Dataset.INT16:
29346                        final short[] oi16data = ((ShortDataset) result).getData();
29347                        if (it.isOutputDouble()) {
29348                                while (it.hasNext()) {
29349                                        final double ix = it.aDouble;
29350                                        short ox;
29351                                        ox = (short) toLong(ix*ix);
29352                                        oi16data[it.oIndex] = ox;
29353                                }
29354                        } else {
29355                                while (it.hasNext()) {
29356                                        final long ix = it.aLong;
29357                                        short ox;
29358                                        ox = (short) toLong(ix*ix);
29359                                        oi16data[it.oIndex] = ox;
29360                                }
29361                        }
29362                        break;
29363                case Dataset.INT64:
29364                        final long[] oi64data = ((LongDataset) result).getData();
29365                        if (it.isOutputDouble()) {
29366                                while (it.hasNext()) {
29367                                        final double ix = it.aDouble;
29368                                        long ox;
29369                                        ox = toLong(ix*ix);
29370                                        oi64data[it.oIndex] = ox;
29371                                }
29372                        } else {
29373                                while (it.hasNext()) {
29374                                        final long ix = it.aLong;
29375                                        long ox;
29376                                        ox = toLong(ix*ix);
29377                                        oi64data[it.oIndex] = ox;
29378                                }
29379                        }
29380                        break;
29381                case Dataset.INT32:
29382                        final int[] oi32data = ((IntegerDataset) result).getData();
29383                        if (it.isOutputDouble()) {
29384                                while (it.hasNext()) {
29385                                        final double ix = it.aDouble;
29386                                        int ox;
29387                                        ox = (int) toLong(ix*ix);
29388                                        oi32data[it.oIndex] = ox;
29389                                }
29390                        } else {
29391                                while (it.hasNext()) {
29392                                        final long ix = it.aLong;
29393                                        int ox;
29394                                        ox = (int) toLong(ix*ix);
29395                                        oi32data[it.oIndex] = ox;
29396                                }
29397                        }
29398                        break;
29399                case Dataset.ARRAYINT8:
29400                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
29401                        if (is == 1) {
29402                                if (it.isOutputDouble()) {
29403                                        while (it.hasNext()) {
29404                                                final double ix = it.aDouble;
29405                                                byte ox;
29406                                                ox = (byte) toLong(ix*ix);
29407                                                oai8data[it.oIndex] = ox;
29408                                        }
29409                                } else {
29410                                        while (it.hasNext()) {
29411                                                final long ix = it.aLong;
29412                                                byte ox;
29413                                                ox = (byte) toLong(ix*ix);
29414                                                oai8data[it.oIndex] = ox;
29415                                        }
29416                                }
29417                        } else if (as == 1) {
29418                                if (it.isOutputDouble()) {
29419                                        while (it.hasNext()) {
29420                                                final double ix = it.aDouble;
29421                                                byte ox;
29422                                                ox = (byte) toLong(ix*ix);
29423                                                for (int j = 0; j < is; j++) {
29424                                                        oai8data[it.oIndex + j] = ox;
29425                                                }
29426                                        }
29427                                } else {
29428                                        while (it.hasNext()) {
29429                                                final long ix = it.aLong;
29430                                                byte ox;
29431                                                ox = (byte) toLong(ix*ix);
29432                                                for (int j = 0; j < is; j++) {
29433                                                        oai8data[it.oIndex + j] = ox;
29434                                                }
29435                                        }
29436                                }
29437                        } else {
29438                                if (it.isOutputDouble()) {
29439                                        while (it.hasNext()) {
29440                                                for (int j = 0; j < is; j++) {
29441                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29442                                                        byte ox;
29443                                                        ox = (byte) toLong(ix*ix);
29444                                                        oai8data[it.oIndex + j] = ox;
29445                                                }
29446                                        }
29447                                } else {
29448                                        while (it.hasNext()) {
29449                                                for (int j = 0; j < is; j++) {
29450                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29451                                                        byte ox;
29452                                                        ox = (byte) toLong(ix*ix);
29453                                                        oai8data[it.oIndex + j] = ox;
29454                                                }
29455                                        }
29456                                }
29457                        }
29458                        break;
29459                case Dataset.ARRAYINT16:
29460                        final short[] oai16data = ((CompoundShortDataset) result).getData();
29461                        if (is == 1) {
29462                                if (it.isOutputDouble()) {
29463                                        while (it.hasNext()) {
29464                                                final double ix = it.aDouble;
29465                                                short ox;
29466                                                ox = (short) toLong(ix*ix);
29467                                                oai16data[it.oIndex] = ox;
29468                                        }
29469                                } else {
29470                                        while (it.hasNext()) {
29471                                                final long ix = it.aLong;
29472                                                short ox;
29473                                                ox = (short) toLong(ix*ix);
29474                                                oai16data[it.oIndex] = ox;
29475                                        }
29476                                }
29477                        } else if (as == 1) {
29478                                if (it.isOutputDouble()) {
29479                                        while (it.hasNext()) {
29480                                                final double ix = it.aDouble;
29481                                                short ox;
29482                                                ox = (short) toLong(ix*ix);
29483                                                for (int j = 0; j < is; j++) {
29484                                                        oai16data[it.oIndex + j] = ox;
29485                                                }
29486                                        }
29487                                } else {
29488                                        while (it.hasNext()) {
29489                                                final long ix = it.aLong;
29490                                                short ox;
29491                                                ox = (short) toLong(ix*ix);
29492                                                for (int j = 0; j < is; j++) {
29493                                                        oai16data[it.oIndex + j] = ox;
29494                                                }
29495                                        }
29496                                }
29497                        } else {
29498                                if (it.isOutputDouble()) {
29499                                        while (it.hasNext()) {
29500                                                for (int j = 0; j < is; j++) {
29501                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29502                                                        short ox;
29503                                                        ox = (short) toLong(ix*ix);
29504                                                        oai16data[it.oIndex + j] = ox;
29505                                                }
29506                                        }
29507                                } else {
29508                                        while (it.hasNext()) {
29509                                                for (int j = 0; j < is; j++) {
29510                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29511                                                        short ox;
29512                                                        ox = (short) toLong(ix*ix);
29513                                                        oai16data[it.oIndex + j] = ox;
29514                                                }
29515                                        }
29516                                }
29517                        }
29518                        break;
29519                case Dataset.ARRAYINT64:
29520                        final long[] oai64data = ((CompoundLongDataset) result).getData();
29521                        if (is == 1) {
29522                                if (it.isOutputDouble()) {
29523                                        while (it.hasNext()) {
29524                                                final double ix = it.aDouble;
29525                                                long ox;
29526                                                ox = toLong(ix*ix);
29527                                                oai64data[it.oIndex] = ox;
29528                                        }
29529                                } else {
29530                                        while (it.hasNext()) {
29531                                                final long ix = it.aLong;
29532                                                long ox;
29533                                                ox = toLong(ix*ix);
29534                                                oai64data[it.oIndex] = ox;
29535                                        }
29536                                }
29537                        } else if (as == 1) {
29538                                if (it.isOutputDouble()) {
29539                                        while (it.hasNext()) {
29540                                                final double ix = it.aDouble;
29541                                                long ox;
29542                                                ox = toLong(ix*ix);
29543                                                for (int j = 0; j < is; j++) {
29544                                                        oai64data[it.oIndex + j] = ox;
29545                                                }
29546                                        }
29547                                } else {
29548                                        while (it.hasNext()) {
29549                                                final long ix = it.aLong;
29550                                                long ox;
29551                                                ox = toLong(ix*ix);
29552                                                for (int j = 0; j < is; j++) {
29553                                                        oai64data[it.oIndex + j] = ox;
29554                                                }
29555                                        }
29556                                }
29557                        } else {
29558                                if (it.isOutputDouble()) {
29559                                        while (it.hasNext()) {
29560                                                for (int j = 0; j < is; j++) {
29561                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29562                                                        long ox;
29563                                                        ox = toLong(ix*ix);
29564                                                        oai64data[it.oIndex + j] = ox;
29565                                                }
29566                                        }
29567                                } else {
29568                                        while (it.hasNext()) {
29569                                                for (int j = 0; j < is; j++) {
29570                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29571                                                        long ox;
29572                                                        ox = toLong(ix*ix);
29573                                                        oai64data[it.oIndex + j] = ox;
29574                                                }
29575                                        }
29576                                }
29577                        }
29578                        break;
29579                case Dataset.ARRAYINT32:
29580                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
29581                        if (is == 1) {
29582                                if (it.isOutputDouble()) {
29583                                        while (it.hasNext()) {
29584                                                final double ix = it.aDouble;
29585                                                int ox;
29586                                                ox = (int) toLong(ix*ix);
29587                                                oai32data[it.oIndex] = ox;
29588                                        }
29589                                } else {
29590                                        while (it.hasNext()) {
29591                                                final long ix = it.aLong;
29592                                                int ox;
29593                                                ox = (int) toLong(ix*ix);
29594                                                oai32data[it.oIndex] = ox;
29595                                        }
29596                                }
29597                        } else if (as == 1) {
29598                                if (it.isOutputDouble()) {
29599                                        while (it.hasNext()) {
29600                                                final double ix = it.aDouble;
29601                                                int ox;
29602                                                ox = (int) toLong(ix*ix);
29603                                                for (int j = 0; j < is; j++) {
29604                                                        oai32data[it.oIndex + j] = ox;
29605                                                }
29606                                        }
29607                                } else {
29608                                        while (it.hasNext()) {
29609                                                final long ix = it.aLong;
29610                                                int ox;
29611                                                ox = (int) toLong(ix*ix);
29612                                                for (int j = 0; j < is; j++) {
29613                                                        oai32data[it.oIndex + j] = ox;
29614                                                }
29615                                        }
29616                                }
29617                        } else {
29618                                if (it.isOutputDouble()) {
29619                                        while (it.hasNext()) {
29620                                                for (int j = 0; j < is; j++) {
29621                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29622                                                        int ox;
29623                                                        ox = (int) toLong(ix*ix);
29624                                                        oai32data[it.oIndex + j] = ox;
29625                                                }
29626                                        }
29627                                } else {
29628                                        while (it.hasNext()) {
29629                                                for (int j = 0; j < is; j++) {
29630                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29631                                                        int ox;
29632                                                        ox = (int) toLong(ix*ix);
29633                                                        oai32data[it.oIndex + j] = ox;
29634                                                }
29635                                        }
29636                                }
29637                        }
29638                        break;
29639                case Dataset.FLOAT32:
29640                        final float[] of32data = ((FloatDataset) result).getData();
29641                        if (it.isOutputDouble()) {
29642                                while (it.hasNext()) {
29643                                        final double ix = it.aDouble;
29644                                        float ox;
29645                                        ox = (float) (ix*ix);
29646                                        of32data[it.oIndex] = ox;
29647                                }
29648                        } else {
29649                                while (it.hasNext()) {
29650                                        final long ix = it.aLong;
29651                                        float ox;
29652                                        ox = (ix*ix);
29653                                        of32data[it.oIndex] = ox;
29654                                }
29655                        }
29656                        break;
29657                case Dataset.FLOAT64:
29658                        final double[] of64data = ((DoubleDataset) result).getData();
29659                        if (it.isOutputDouble()) {
29660                                while (it.hasNext()) {
29661                                        final double ix = it.aDouble;
29662                                        double ox;
29663                                        ox = (ix*ix);
29664                                        of64data[it.oIndex] = ox;
29665                                }
29666                        } else {
29667                                while (it.hasNext()) {
29668                                        final long ix = it.aLong;
29669                                        double ox;
29670                                        ox = (ix*ix);
29671                                        of64data[it.oIndex] = ox;
29672                                }
29673                        }
29674                        break;
29675                case Dataset.ARRAYFLOAT32:
29676                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
29677                        if (is == 1) {
29678                                if (it.isOutputDouble()) {
29679                                        while (it.hasNext()) {
29680                                                final double ix = it.aDouble;
29681                                                float ox;
29682                                                ox = (float) (ix*ix);
29683                                                oaf32data[it.oIndex] = ox;
29684                                        }
29685                                } else {
29686                                        while (it.hasNext()) {
29687                                                final long ix = it.aLong;
29688                                                float ox;
29689                                                ox = (ix*ix);
29690                                                oaf32data[it.oIndex] = ox;
29691                                        }
29692                                }
29693                        } else if (as == 1) {
29694                                if (it.isOutputDouble()) {
29695                                        while (it.hasNext()) {
29696                                                final double ix = it.aDouble;
29697                                                float ox;
29698                                                ox = (float) (ix*ix);
29699                                                for (int j = 0; j < is; j++) {
29700                                                        oaf32data[it.oIndex + j] = ox;
29701                                                }
29702                                        }
29703                                } else {
29704                                        while (it.hasNext()) {
29705                                                final long ix = it.aLong;
29706                                                float ox;
29707                                                ox = (ix*ix);
29708                                                for (int j = 0; j < is; j++) {
29709                                                        oaf32data[it.oIndex + j] = ox;
29710                                                }
29711                                        }
29712                                }
29713                        } else {
29714                                if (it.isOutputDouble()) {
29715                                        while (it.hasNext()) {
29716                                                for (int j = 0; j < is; j++) {
29717                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29718                                                        float ox;
29719                                                        ox = (float) (ix*ix);
29720                                                        oaf32data[it.oIndex + j] = ox;
29721                                                }
29722                                        }
29723                                } else {
29724                                        while (it.hasNext()) {
29725                                                for (int j = 0; j < is; j++) {
29726                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29727                                                        float ox;
29728                                                        ox = (ix*ix);
29729                                                        oaf32data[it.oIndex + j] = ox;
29730                                                }
29731                                        }
29732                                }
29733                        }
29734                        break;
29735                case Dataset.ARRAYFLOAT64:
29736                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
29737                        if (is == 1) {
29738                                if (it.isOutputDouble()) {
29739                                        while (it.hasNext()) {
29740                                                final double ix = it.aDouble;
29741                                                double ox;
29742                                                ox = (ix*ix);
29743                                                oaf64data[it.oIndex] = ox;
29744                                        }
29745                                } else {
29746                                        while (it.hasNext()) {
29747                                                final long ix = it.aLong;
29748                                                double ox;
29749                                                ox = (ix*ix);
29750                                                oaf64data[it.oIndex] = ox;
29751                                        }
29752                                }
29753                        } else if (as == 1) {
29754                                if (it.isOutputDouble()) {
29755                                        while (it.hasNext()) {
29756                                                final double ix = it.aDouble;
29757                                                double ox;
29758                                                ox = (ix*ix);
29759                                                for (int j = 0; j < is; j++) {
29760                                                        oaf64data[it.oIndex + j] = ox;
29761                                                }
29762                                        }
29763                                } else {
29764                                        while (it.hasNext()) {
29765                                                final long ix = it.aLong;
29766                                                double ox;
29767                                                ox = (ix*ix);
29768                                                for (int j = 0; j < is; j++) {
29769                                                        oaf64data[it.oIndex + j] = ox;
29770                                                }
29771                                        }
29772                                }
29773                        } else {
29774                                if (it.isOutputDouble()) {
29775                                        while (it.hasNext()) {
29776                                                for (int j = 0; j < is; j++) {
29777                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
29778                                                        double ox;
29779                                                        ox = (ix*ix);
29780                                                        oaf64data[it.oIndex + j] = ox;
29781                                                }
29782                                        }
29783                                } else {
29784                                        while (it.hasNext()) {
29785                                                for (int j = 0; j < is; j++) {
29786                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
29787                                                        double ox;
29788                                                        ox = (ix*ix);
29789                                                        oaf64data[it.oIndex + j] = ox;
29790                                                }
29791                                        }
29792                                }
29793                        }
29794                        break;
29795                case Dataset.COMPLEX64:
29796                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
29797                        if (!da.isComplex()) {
29798                                if (it.isOutputDouble()) {
29799                                        final double iy = 0;
29800                                        while (it.hasNext()) {
29801                                                final double ix = it.aDouble;
29802                                                float ox;
29803                                                float oy;
29804                                                ox = (float) (ix*ix - iy*iy);
29805                                                oy = (float) (2.*ix*iy);
29806                                                oc64data[it.oIndex] = ox;
29807                                                oc64data[it.oIndex + 1] = oy;
29808                                        }
29809                                } else {
29810                                        final long iy = 0;
29811                                        while (it.hasNext()) {
29812                                                final long ix = it.aLong;
29813                                                float ox;
29814                                                float oy;
29815                                                ox = (float) toLong(ix*ix - iy*iy);
29816                                                oy = (float) toLong(2.*ix*iy);
29817                                                oc64data[it.oIndex] = ox;
29818                                                oc64data[it.oIndex + 1] = oy;
29819                                        }
29820                                }
29821                        } else {
29822                                while (it.hasNext()) {
29823                                        final double ix = it.aDouble;
29824                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
29825                                        float ox;
29826                                        float oy;
29827                                        ox = (float) (ix*ix - iy*iy);
29828                                        oy = (float) (2.*ix*iy);
29829                                        oc64data[it.oIndex] = ox;
29830                                        oc64data[it.oIndex + 1] = oy;
29831                                }
29832                        }
29833                        break;
29834                case Dataset.COMPLEX128:
29835                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
29836                        if (!da.isComplex()) {
29837                                if (it.isOutputDouble()) {
29838                                        final double iy = 0;
29839                                        while (it.hasNext()) {
29840                                                final double ix = it.aDouble;
29841                                                double ox;
29842                                                double oy;
29843                                                ox = (ix*ix - iy*iy);
29844                                                oy = (2.*ix*iy);
29845                                                oc128data[it.oIndex] = ox;
29846                                                oc128data[it.oIndex + 1] = oy;
29847                                        }
29848                                } else {
29849                                        final long iy = 0;
29850                                        while (it.hasNext()) {
29851                                                final long ix = it.aLong;
29852                                                double ox;
29853                                                double oy;
29854                                                ox = (ix*ix - iy*iy);
29855                                                oy = (2.*ix*iy);
29856                                                oc128data[it.oIndex] = ox;
29857                                                oc128data[it.oIndex + 1] = oy;
29858                                        }
29859                                }
29860                        } else {
29861                                while (it.hasNext()) {
29862                                        final double ix = it.aDouble;
29863                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
29864                                        double ox;
29865                                        double oy;
29866                                        ox = (ix*ix - iy*iy);
29867                                        oy = (2.*ix*iy);
29868                                        oc128data[it.oIndex] = ox;
29869                                        oc128data[it.oIndex + 1] = oy;
29870                                }
29871                        }
29872                        break;
29873                default:
29874                        throw new IllegalArgumentException("square supports integer, compound integer, real, compound real, complex datasets only");
29875                }
29876
29877                addFunctionName(result, "square");
29878                return result;
29879        }
29880
29881        /**
29882         * floor - evaluate the floor function on each element of the dataset
29883         * @param a single operand
29884         * @return dataset
29885         */
29886        public static Dataset floor(final Object a) {
29887                return floor(a, null);
29888        }
29889
29890        /**
29891         * floor - evaluate the floor function on each element of the dataset
29892         * @param a single operand
29893         * @param o output can be null - in which case, a new dataset is created
29894         * @return dataset
29895         */
29896        public static Dataset floor(final Object a, final Dataset o) {
29897                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
29898                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
29899                final Dataset result = it.getOutput();
29900                if (!result.isComplex()) {
29901                        if (da.isComplex()) {
29902                                da = da.getRealView();
29903                                it = new SingleInputBroadcastIterator(da, result, true);
29904                        }
29905                }
29906                final int is = result.getElementsPerItem();
29907                final int as = da.getElementsPerItem();
29908                final int dt = result.getDType();
29909
29910                switch(dt) {
29911                case Dataset.INT8:
29912                        final byte[] oi8data = ((ByteDataset) result).getData();
29913                        if (it.isOutputDouble()) {
29914                                while (it.hasNext()) {
29915                                        final double ix = it.aDouble;
29916                                        byte ox;
29917                                        ox = (byte) toLong(ix);
29918                                        oi8data[it.oIndex] = ox;
29919                                }
29920                        } else {
29921                                while (it.hasNext()) {
29922                                        final long ix = it.aLong;
29923                                        byte ox;
29924                                        ox = (byte) toLong(ix);
29925                                        oi8data[it.oIndex] = ox;
29926                                }
29927                        }
29928                        break;
29929                case Dataset.INT16:
29930                        final short[] oi16data = ((ShortDataset) result).getData();
29931                        if (it.isOutputDouble()) {
29932                                while (it.hasNext()) {
29933                                        final double ix = it.aDouble;
29934                                        short ox;
29935                                        ox = (short) toLong(ix);
29936                                        oi16data[it.oIndex] = ox;
29937                                }
29938                        } else {
29939                                while (it.hasNext()) {
29940                                        final long ix = it.aLong;
29941                                        short ox;
29942                                        ox = (short) toLong(ix);
29943                                        oi16data[it.oIndex] = ox;
29944                                }
29945                        }
29946                        break;
29947                case Dataset.INT64:
29948                        final long[] oi64data = ((LongDataset) result).getData();
29949                        if (it.isOutputDouble()) {
29950                                while (it.hasNext()) {
29951                                        final double ix = it.aDouble;
29952                                        long ox;
29953                                        ox = toLong(ix);
29954                                        oi64data[it.oIndex] = ox;
29955                                }
29956                        } else {
29957                                while (it.hasNext()) {
29958                                        final long ix = it.aLong;
29959                                        long ox;
29960                                        ox = toLong(ix);
29961                                        oi64data[it.oIndex] = ox;
29962                                }
29963                        }
29964                        break;
29965                case Dataset.INT32:
29966                        final int[] oi32data = ((IntegerDataset) result).getData();
29967                        if (it.isOutputDouble()) {
29968                                while (it.hasNext()) {
29969                                        final double ix = it.aDouble;
29970                                        int ox;
29971                                        ox = (int) toLong(ix);
29972                                        oi32data[it.oIndex] = ox;
29973                                }
29974                        } else {
29975                                while (it.hasNext()) {
29976                                        final long ix = it.aLong;
29977                                        int ox;
29978                                        ox = (int) toLong(ix);
29979                                        oi32data[it.oIndex] = ox;
29980                                }
29981                        }
29982                        break;
29983                case Dataset.ARRAYINT8:
29984                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
29985                        if (is == 1) {
29986                                if (it.isOutputDouble()) {
29987                                        while (it.hasNext()) {
29988                                                final double ix = it.aDouble;
29989                                                byte ox;
29990                                                ox = (byte) toLong(ix);
29991                                                oai8data[it.oIndex] = ox;
29992                                        }
29993                                } else {
29994                                        while (it.hasNext()) {
29995                                                final long ix = it.aLong;
29996                                                byte ox;
29997                                                ox = (byte) toLong(ix);
29998                                                oai8data[it.oIndex] = ox;
29999                                        }
30000                                }
30001                        } else if (as == 1) {
30002                                if (it.isOutputDouble()) {
30003                                        while (it.hasNext()) {
30004                                                final double ix = it.aDouble;
30005                                                byte ox;
30006                                                ox = (byte) toLong(ix);
30007                                                for (int j = 0; j < is; j++) {
30008                                                        oai8data[it.oIndex + j] = ox;
30009                                                }
30010                                        }
30011                                } else {
30012                                        while (it.hasNext()) {
30013                                                final long ix = it.aLong;
30014                                                byte ox;
30015                                                ox = (byte) toLong(ix);
30016                                                for (int j = 0; j < is; j++) {
30017                                                        oai8data[it.oIndex + j] = ox;
30018                                                }
30019                                        }
30020                                }
30021                        } else {
30022                                if (it.isOutputDouble()) {
30023                                        while (it.hasNext()) {
30024                                                for (int j = 0; j < is; j++) {
30025                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30026                                                        byte ox;
30027                                                        ox = (byte) toLong(ix);
30028                                                        oai8data[it.oIndex + j] = ox;
30029                                                }
30030                                        }
30031                                } else {
30032                                        while (it.hasNext()) {
30033                                                for (int j = 0; j < is; j++) {
30034                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30035                                                        byte ox;
30036                                                        ox = (byte) toLong(ix);
30037                                                        oai8data[it.oIndex + j] = ox;
30038                                                }
30039                                        }
30040                                }
30041                        }
30042                        break;
30043                case Dataset.ARRAYINT16:
30044                        final short[] oai16data = ((CompoundShortDataset) result).getData();
30045                        if (is == 1) {
30046                                if (it.isOutputDouble()) {
30047                                        while (it.hasNext()) {
30048                                                final double ix = it.aDouble;
30049                                                short ox;
30050                                                ox = (short) toLong(ix);
30051                                                oai16data[it.oIndex] = ox;
30052                                        }
30053                                } else {
30054                                        while (it.hasNext()) {
30055                                                final long ix = it.aLong;
30056                                                short ox;
30057                                                ox = (short) toLong(ix);
30058                                                oai16data[it.oIndex] = ox;
30059                                        }
30060                                }
30061                        } else if (as == 1) {
30062                                if (it.isOutputDouble()) {
30063                                        while (it.hasNext()) {
30064                                                final double ix = it.aDouble;
30065                                                short ox;
30066                                                ox = (short) toLong(ix);
30067                                                for (int j = 0; j < is; j++) {
30068                                                        oai16data[it.oIndex + j] = ox;
30069                                                }
30070                                        }
30071                                } else {
30072                                        while (it.hasNext()) {
30073                                                final long ix = it.aLong;
30074                                                short ox;
30075                                                ox = (short) toLong(ix);
30076                                                for (int j = 0; j < is; j++) {
30077                                                        oai16data[it.oIndex + j] = ox;
30078                                                }
30079                                        }
30080                                }
30081                        } else {
30082                                if (it.isOutputDouble()) {
30083                                        while (it.hasNext()) {
30084                                                for (int j = 0; j < is; j++) {
30085                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30086                                                        short ox;
30087                                                        ox = (short) toLong(ix);
30088                                                        oai16data[it.oIndex + j] = ox;
30089                                                }
30090                                        }
30091                                } else {
30092                                        while (it.hasNext()) {
30093                                                for (int j = 0; j < is; j++) {
30094                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30095                                                        short ox;
30096                                                        ox = (short) toLong(ix);
30097                                                        oai16data[it.oIndex + j] = ox;
30098                                                }
30099                                        }
30100                                }
30101                        }
30102                        break;
30103                case Dataset.ARRAYINT64:
30104                        final long[] oai64data = ((CompoundLongDataset) result).getData();
30105                        if (is == 1) {
30106                                if (it.isOutputDouble()) {
30107                                        while (it.hasNext()) {
30108                                                final double ix = it.aDouble;
30109                                                long ox;
30110                                                ox = toLong(ix);
30111                                                oai64data[it.oIndex] = ox;
30112                                        }
30113                                } else {
30114                                        while (it.hasNext()) {
30115                                                final long ix = it.aLong;
30116                                                long ox;
30117                                                ox = toLong(ix);
30118                                                oai64data[it.oIndex] = ox;
30119                                        }
30120                                }
30121                        } else if (as == 1) {
30122                                if (it.isOutputDouble()) {
30123                                        while (it.hasNext()) {
30124                                                final double ix = it.aDouble;
30125                                                long ox;
30126                                                ox = toLong(ix);
30127                                                for (int j = 0; j < is; j++) {
30128                                                        oai64data[it.oIndex + j] = ox;
30129                                                }
30130                                        }
30131                                } else {
30132                                        while (it.hasNext()) {
30133                                                final long ix = it.aLong;
30134                                                long ox;
30135                                                ox = toLong(ix);
30136                                                for (int j = 0; j < is; j++) {
30137                                                        oai64data[it.oIndex + j] = ox;
30138                                                }
30139                                        }
30140                                }
30141                        } else {
30142                                if (it.isOutputDouble()) {
30143                                        while (it.hasNext()) {
30144                                                for (int j = 0; j < is; j++) {
30145                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30146                                                        long ox;
30147                                                        ox = toLong(ix);
30148                                                        oai64data[it.oIndex + j] = ox;
30149                                                }
30150                                        }
30151                                } else {
30152                                        while (it.hasNext()) {
30153                                                for (int j = 0; j < is; j++) {
30154                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30155                                                        long ox;
30156                                                        ox = toLong(ix);
30157                                                        oai64data[it.oIndex + j] = ox;
30158                                                }
30159                                        }
30160                                }
30161                        }
30162                        break;
30163                case Dataset.ARRAYINT32:
30164                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
30165                        if (is == 1) {
30166                                if (it.isOutputDouble()) {
30167                                        while (it.hasNext()) {
30168                                                final double ix = it.aDouble;
30169                                                int ox;
30170                                                ox = (int) toLong(ix);
30171                                                oai32data[it.oIndex] = ox;
30172                                        }
30173                                } else {
30174                                        while (it.hasNext()) {
30175                                                final long ix = it.aLong;
30176                                                int ox;
30177                                                ox = (int) toLong(ix);
30178                                                oai32data[it.oIndex] = ox;
30179                                        }
30180                                }
30181                        } else if (as == 1) {
30182                                if (it.isOutputDouble()) {
30183                                        while (it.hasNext()) {
30184                                                final double ix = it.aDouble;
30185                                                int ox;
30186                                                ox = (int) toLong(ix);
30187                                                for (int j = 0; j < is; j++) {
30188                                                        oai32data[it.oIndex + j] = ox;
30189                                                }
30190                                        }
30191                                } else {
30192                                        while (it.hasNext()) {
30193                                                final long ix = it.aLong;
30194                                                int ox;
30195                                                ox = (int) toLong(ix);
30196                                                for (int j = 0; j < is; j++) {
30197                                                        oai32data[it.oIndex + j] = ox;
30198                                                }
30199                                        }
30200                                }
30201                        } else {
30202                                if (it.isOutputDouble()) {
30203                                        while (it.hasNext()) {
30204                                                for (int j = 0; j < is; j++) {
30205                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30206                                                        int ox;
30207                                                        ox = (int) toLong(ix);
30208                                                        oai32data[it.oIndex + j] = ox;
30209                                                }
30210                                        }
30211                                } else {
30212                                        while (it.hasNext()) {
30213                                                for (int j = 0; j < is; j++) {
30214                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30215                                                        int ox;
30216                                                        ox = (int) toLong(ix);
30217                                                        oai32data[it.oIndex + j] = ox;
30218                                                }
30219                                        }
30220                                }
30221                        }
30222                        break;
30223                case Dataset.FLOAT32:
30224                        final float[] of32data = ((FloatDataset) result).getData();
30225                        if (it.isOutputDouble()) {
30226                                while (it.hasNext()) {
30227                                        final double ix = it.aDouble;
30228                                        float ox;
30229                                        ox = (float) (Math.floor(ix));
30230                                        of32data[it.oIndex] = ox;
30231                                }
30232                        } else {
30233                                while (it.hasNext()) {
30234                                        final long ix = it.aLong;
30235                                        float ox;
30236                                        ox = (float) (Math.floor(ix));
30237                                        of32data[it.oIndex] = ox;
30238                                }
30239                        }
30240                        break;
30241                case Dataset.FLOAT64:
30242                        final double[] of64data = ((DoubleDataset) result).getData();
30243                        if (it.isOutputDouble()) {
30244                                while (it.hasNext()) {
30245                                        final double ix = it.aDouble;
30246                                        double ox;
30247                                        ox = (Math.floor(ix));
30248                                        of64data[it.oIndex] = ox;
30249                                }
30250                        } else {
30251                                while (it.hasNext()) {
30252                                        final long ix = it.aLong;
30253                                        double ox;
30254                                        ox = (Math.floor(ix));
30255                                        of64data[it.oIndex] = ox;
30256                                }
30257                        }
30258                        break;
30259                case Dataset.ARRAYFLOAT32:
30260                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
30261                        if (is == 1) {
30262                                if (it.isOutputDouble()) {
30263                                        while (it.hasNext()) {
30264                                                final double ix = it.aDouble;
30265                                                float ox;
30266                                                ox = (float) (Math.floor(ix));
30267                                                oaf32data[it.oIndex] = ox;
30268                                        }
30269                                } else {
30270                                        while (it.hasNext()) {
30271                                                final long ix = it.aLong;
30272                                                float ox;
30273                                                ox = (float) (Math.floor(ix));
30274                                                oaf32data[it.oIndex] = ox;
30275                                        }
30276                                }
30277                        } else if (as == 1) {
30278                                if (it.isOutputDouble()) {
30279                                        while (it.hasNext()) {
30280                                                final double ix = it.aDouble;
30281                                                float ox;
30282                                                ox = (float) (Math.floor(ix));
30283                                                for (int j = 0; j < is; j++) {
30284                                                        oaf32data[it.oIndex + j] = ox;
30285                                                }
30286                                        }
30287                                } else {
30288                                        while (it.hasNext()) {
30289                                                final long ix = it.aLong;
30290                                                float ox;
30291                                                ox = (float) (Math.floor(ix));
30292                                                for (int j = 0; j < is; j++) {
30293                                                        oaf32data[it.oIndex + j] = ox;
30294                                                }
30295                                        }
30296                                }
30297                        } else {
30298                                if (it.isOutputDouble()) {
30299                                        while (it.hasNext()) {
30300                                                for (int j = 0; j < is; j++) {
30301                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30302                                                        float ox;
30303                                                        ox = (float) (Math.floor(ix));
30304                                                        oaf32data[it.oIndex + j] = ox;
30305                                                }
30306                                        }
30307                                } else {
30308                                        while (it.hasNext()) {
30309                                                for (int j = 0; j < is; j++) {
30310                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30311                                                        float ox;
30312                                                        ox = (float) (Math.floor(ix));
30313                                                        oaf32data[it.oIndex + j] = ox;
30314                                                }
30315                                        }
30316                                }
30317                        }
30318                        break;
30319                case Dataset.ARRAYFLOAT64:
30320                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
30321                        if (is == 1) {
30322                                if (it.isOutputDouble()) {
30323                                        while (it.hasNext()) {
30324                                                final double ix = it.aDouble;
30325                                                double ox;
30326                                                ox = (Math.floor(ix));
30327                                                oaf64data[it.oIndex] = ox;
30328                                        }
30329                                } else {
30330                                        while (it.hasNext()) {
30331                                                final long ix = it.aLong;
30332                                                double ox;
30333                                                ox = (Math.floor(ix));
30334                                                oaf64data[it.oIndex] = ox;
30335                                        }
30336                                }
30337                        } else if (as == 1) {
30338                                if (it.isOutputDouble()) {
30339                                        while (it.hasNext()) {
30340                                                final double ix = it.aDouble;
30341                                                double ox;
30342                                                ox = (Math.floor(ix));
30343                                                for (int j = 0; j < is; j++) {
30344                                                        oaf64data[it.oIndex + j] = ox;
30345                                                }
30346                                        }
30347                                } else {
30348                                        while (it.hasNext()) {
30349                                                final long ix = it.aLong;
30350                                                double ox;
30351                                                ox = (Math.floor(ix));
30352                                                for (int j = 0; j < is; j++) {
30353                                                        oaf64data[it.oIndex + j] = ox;
30354                                                }
30355                                        }
30356                                }
30357                        } else {
30358                                if (it.isOutputDouble()) {
30359                                        while (it.hasNext()) {
30360                                                for (int j = 0; j < is; j++) {
30361                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30362                                                        double ox;
30363                                                        ox = (Math.floor(ix));
30364                                                        oaf64data[it.oIndex + j] = ox;
30365                                                }
30366                                        }
30367                                } else {
30368                                        while (it.hasNext()) {
30369                                                for (int j = 0; j < is; j++) {
30370                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30371                                                        double ox;
30372                                                        ox = (Math.floor(ix));
30373                                                        oaf64data[it.oIndex + j] = ox;
30374                                                }
30375                                        }
30376                                }
30377                        }
30378                        break;
30379                case Dataset.COMPLEX64:
30380                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
30381                        if (!da.isComplex()) {
30382                                if (it.isOutputDouble()) {
30383                                        final double iy = 0;
30384                                        while (it.hasNext()) {
30385                                                final double ix = it.aDouble;
30386                                                float ox;
30387                                                float oy;
30388                                                ox = (float) (Math.floor(ix));
30389                                                oy = (float) (Math.floor(iy));
30390                                                oc64data[it.oIndex] = ox;
30391                                                oc64data[it.oIndex + 1] = oy;
30392                                        }
30393                                } else {
30394                                        final long iy = 0;
30395                                        while (it.hasNext()) {
30396                                                final long ix = it.aLong;
30397                                                float ox;
30398                                                float oy;
30399                                                ox = (float) toLong(Math.floor(ix));
30400                                                oy = (float) toLong(Math.floor(iy));
30401                                                oc64data[it.oIndex] = ox;
30402                                                oc64data[it.oIndex + 1] = oy;
30403                                        }
30404                                }
30405                        } else {
30406                                while (it.hasNext()) {
30407                                        final double ix = it.aDouble;
30408                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
30409                                        float ox;
30410                                        float oy;
30411                                        ox = (float) (Math.floor(ix));
30412                                        oy = (float) (Math.floor(iy));
30413                                        oc64data[it.oIndex] = ox;
30414                                        oc64data[it.oIndex + 1] = oy;
30415                                }
30416                        }
30417                        break;
30418                case Dataset.COMPLEX128:
30419                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
30420                        if (!da.isComplex()) {
30421                                if (it.isOutputDouble()) {
30422                                        final double iy = 0;
30423                                        while (it.hasNext()) {
30424                                                final double ix = it.aDouble;
30425                                                double ox;
30426                                                double oy;
30427                                                ox = (Math.floor(ix));
30428                                                oy = (Math.floor(iy));
30429                                                oc128data[it.oIndex] = ox;
30430                                                oc128data[it.oIndex + 1] = oy;
30431                                        }
30432                                } else {
30433                                        final long iy = 0;
30434                                        while (it.hasNext()) {
30435                                                final long ix = it.aLong;
30436                                                double ox;
30437                                                double oy;
30438                                                ox = (double) (Math.floor(ix));
30439                                                oy = (double) (Math.floor(iy));
30440                                                oc128data[it.oIndex] = ox;
30441                                                oc128data[it.oIndex + 1] = oy;
30442                                        }
30443                                }
30444                        } else {
30445                                while (it.hasNext()) {
30446                                        final double ix = it.aDouble;
30447                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
30448                                        double ox;
30449                                        double oy;
30450                                        ox = (Math.floor(ix));
30451                                        oy = (Math.floor(iy));
30452                                        oc128data[it.oIndex] = ox;
30453                                        oc128data[it.oIndex + 1] = oy;
30454                                }
30455                        }
30456                        break;
30457                default:
30458                        throw new IllegalArgumentException("floor supports integer, compound integer, real, compound real, complex datasets only");
30459                }
30460
30461                addFunctionName(result, "floor");
30462                return result;
30463        }
30464
30465        /**
30466         * ceil - evaluate the ceiling function on each element of the dataset
30467         * @param a single operand
30468         * @return dataset
30469         */
30470        public static Dataset ceil(final Object a) {
30471                return ceil(a, null);
30472        }
30473
30474        /**
30475         * ceil - evaluate the ceiling function on each element of the dataset
30476         * @param a single operand
30477         * @param o output can be null - in which case, a new dataset is created
30478         * @return dataset
30479         */
30480        public static Dataset ceil(final Object a, final Dataset o) {
30481                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
30482                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
30483                final Dataset result = it.getOutput();
30484                if (!result.isComplex()) {
30485                        if (da.isComplex()) {
30486                                da = da.getRealView();
30487                                it = new SingleInputBroadcastIterator(da, result, true);
30488                        }
30489                }
30490                final int is = result.getElementsPerItem();
30491                final int as = da.getElementsPerItem();
30492                final int dt = result.getDType();
30493
30494                switch(dt) {
30495                case Dataset.INT8:
30496                        final byte[] oi8data = ((ByteDataset) result).getData();
30497                        if (it.isOutputDouble()) {
30498                                while (it.hasNext()) {
30499                                        final double ix = it.aDouble;
30500                                        byte ox;
30501                                        ox = (byte) toLong(ix);
30502                                        oi8data[it.oIndex] = ox;
30503                                }
30504                        } else {
30505                                while (it.hasNext()) {
30506                                        final long ix = it.aLong;
30507                                        byte ox;
30508                                        ox = (byte) toLong(ix);
30509                                        oi8data[it.oIndex] = ox;
30510                                }
30511                        }
30512                        break;
30513                case Dataset.INT16:
30514                        final short[] oi16data = ((ShortDataset) result).getData();
30515                        if (it.isOutputDouble()) {
30516                                while (it.hasNext()) {
30517                                        final double ix = it.aDouble;
30518                                        short ox;
30519                                        ox = (short) toLong(ix);
30520                                        oi16data[it.oIndex] = ox;
30521                                }
30522                        } else {
30523                                while (it.hasNext()) {
30524                                        final long ix = it.aLong;
30525                                        short ox;
30526                                        ox = (short) toLong(ix);
30527                                        oi16data[it.oIndex] = ox;
30528                                }
30529                        }
30530                        break;
30531                case Dataset.INT64:
30532                        final long[] oi64data = ((LongDataset) result).getData();
30533                        if (it.isOutputDouble()) {
30534                                while (it.hasNext()) {
30535                                        final double ix = it.aDouble;
30536                                        long ox;
30537                                        ox = toLong(ix);
30538                                        oi64data[it.oIndex] = ox;
30539                                }
30540                        } else {
30541                                while (it.hasNext()) {
30542                                        final long ix = it.aLong;
30543                                        long ox;
30544                                        ox = toLong(ix);
30545                                        oi64data[it.oIndex] = ox;
30546                                }
30547                        }
30548                        break;
30549                case Dataset.INT32:
30550                        final int[] oi32data = ((IntegerDataset) result).getData();
30551                        if (it.isOutputDouble()) {
30552                                while (it.hasNext()) {
30553                                        final double ix = it.aDouble;
30554                                        int ox;
30555                                        ox = (int) toLong(ix);
30556                                        oi32data[it.oIndex] = ox;
30557                                }
30558                        } else {
30559                                while (it.hasNext()) {
30560                                        final long ix = it.aLong;
30561                                        int ox;
30562                                        ox = (int) toLong(ix);
30563                                        oi32data[it.oIndex] = ox;
30564                                }
30565                        }
30566                        break;
30567                case Dataset.ARRAYINT8:
30568                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
30569                        if (is == 1) {
30570                                if (it.isOutputDouble()) {
30571                                        while (it.hasNext()) {
30572                                                final double ix = it.aDouble;
30573                                                byte ox;
30574                                                ox = (byte) toLong(ix);
30575                                                oai8data[it.oIndex] = ox;
30576                                        }
30577                                } else {
30578                                        while (it.hasNext()) {
30579                                                final long ix = it.aLong;
30580                                                byte ox;
30581                                                ox = (byte) toLong(ix);
30582                                                oai8data[it.oIndex] = ox;
30583                                        }
30584                                }
30585                        } else if (as == 1) {
30586                                if (it.isOutputDouble()) {
30587                                        while (it.hasNext()) {
30588                                                final double ix = it.aDouble;
30589                                                byte ox;
30590                                                ox = (byte) toLong(ix);
30591                                                for (int j = 0; j < is; j++) {
30592                                                        oai8data[it.oIndex + j] = ox;
30593                                                }
30594                                        }
30595                                } else {
30596                                        while (it.hasNext()) {
30597                                                final long ix = it.aLong;
30598                                                byte ox;
30599                                                ox = (byte) toLong(ix);
30600                                                for (int j = 0; j < is; j++) {
30601                                                        oai8data[it.oIndex + j] = ox;
30602                                                }
30603                                        }
30604                                }
30605                        } else {
30606                                if (it.isOutputDouble()) {
30607                                        while (it.hasNext()) {
30608                                                for (int j = 0; j < is; j++) {
30609                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30610                                                        byte ox;
30611                                                        ox = (byte) toLong(ix);
30612                                                        oai8data[it.oIndex + j] = ox;
30613                                                }
30614                                        }
30615                                } else {
30616                                        while (it.hasNext()) {
30617                                                for (int j = 0; j < is; j++) {
30618                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30619                                                        byte ox;
30620                                                        ox = (byte) toLong(ix);
30621                                                        oai8data[it.oIndex + j] = ox;
30622                                                }
30623                                        }
30624                                }
30625                        }
30626                        break;
30627                case Dataset.ARRAYINT16:
30628                        final short[] oai16data = ((CompoundShortDataset) result).getData();
30629                        if (is == 1) {
30630                                if (it.isOutputDouble()) {
30631                                        while (it.hasNext()) {
30632                                                final double ix = it.aDouble;
30633                                                short ox;
30634                                                ox = (short) toLong(ix);
30635                                                oai16data[it.oIndex] = ox;
30636                                        }
30637                                } else {
30638                                        while (it.hasNext()) {
30639                                                final long ix = it.aLong;
30640                                                short ox;
30641                                                ox = (short) toLong(ix);
30642                                                oai16data[it.oIndex] = ox;
30643                                        }
30644                                }
30645                        } else if (as == 1) {
30646                                if (it.isOutputDouble()) {
30647                                        while (it.hasNext()) {
30648                                                final double ix = it.aDouble;
30649                                                short ox;
30650                                                ox = (short) toLong(ix);
30651                                                for (int j = 0; j < is; j++) {
30652                                                        oai16data[it.oIndex + j] = ox;
30653                                                }
30654                                        }
30655                                } else {
30656                                        while (it.hasNext()) {
30657                                                final long ix = it.aLong;
30658                                                short ox;
30659                                                ox = (short) toLong(ix);
30660                                                for (int j = 0; j < is; j++) {
30661                                                        oai16data[it.oIndex + j] = ox;
30662                                                }
30663                                        }
30664                                }
30665                        } else {
30666                                if (it.isOutputDouble()) {
30667                                        while (it.hasNext()) {
30668                                                for (int j = 0; j < is; j++) {
30669                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30670                                                        short ox;
30671                                                        ox = (short) toLong(ix);
30672                                                        oai16data[it.oIndex + j] = ox;
30673                                                }
30674                                        }
30675                                } else {
30676                                        while (it.hasNext()) {
30677                                                for (int j = 0; j < is; j++) {
30678                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30679                                                        short ox;
30680                                                        ox = (short) toLong(ix);
30681                                                        oai16data[it.oIndex + j] = ox;
30682                                                }
30683                                        }
30684                                }
30685                        }
30686                        break;
30687                case Dataset.ARRAYINT64:
30688                        final long[] oai64data = ((CompoundLongDataset) result).getData();
30689                        if (is == 1) {
30690                                if (it.isOutputDouble()) {
30691                                        while (it.hasNext()) {
30692                                                final double ix = it.aDouble;
30693                                                long ox;
30694                                                ox = toLong(ix);
30695                                                oai64data[it.oIndex] = ox;
30696                                        }
30697                                } else {
30698                                        while (it.hasNext()) {
30699                                                final long ix = it.aLong;
30700                                                long ox;
30701                                                ox = toLong(ix);
30702                                                oai64data[it.oIndex] = ox;
30703                                        }
30704                                }
30705                        } else if (as == 1) {
30706                                if (it.isOutputDouble()) {
30707                                        while (it.hasNext()) {
30708                                                final double ix = it.aDouble;
30709                                                long ox;
30710                                                ox = toLong(ix);
30711                                                for (int j = 0; j < is; j++) {
30712                                                        oai64data[it.oIndex + j] = ox;
30713                                                }
30714                                        }
30715                                } else {
30716                                        while (it.hasNext()) {
30717                                                final long ix = it.aLong;
30718                                                long ox;
30719                                                ox = toLong(ix);
30720                                                for (int j = 0; j < is; j++) {
30721                                                        oai64data[it.oIndex + j] = ox;
30722                                                }
30723                                        }
30724                                }
30725                        } else {
30726                                if (it.isOutputDouble()) {
30727                                        while (it.hasNext()) {
30728                                                for (int j = 0; j < is; j++) {
30729                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30730                                                        long ox;
30731                                                        ox = toLong(ix);
30732                                                        oai64data[it.oIndex + j] = ox;
30733                                                }
30734                                        }
30735                                } else {
30736                                        while (it.hasNext()) {
30737                                                for (int j = 0; j < is; j++) {
30738                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30739                                                        long ox;
30740                                                        ox = toLong(ix);
30741                                                        oai64data[it.oIndex + j] = ox;
30742                                                }
30743                                        }
30744                                }
30745                        }
30746                        break;
30747                case Dataset.ARRAYINT32:
30748                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
30749                        if (is == 1) {
30750                                if (it.isOutputDouble()) {
30751                                        while (it.hasNext()) {
30752                                                final double ix = it.aDouble;
30753                                                int ox;
30754                                                ox = (int) toLong(ix);
30755                                                oai32data[it.oIndex] = ox;
30756                                        }
30757                                } else {
30758                                        while (it.hasNext()) {
30759                                                final long ix = it.aLong;
30760                                                int ox;
30761                                                ox = (int) toLong(ix);
30762                                                oai32data[it.oIndex] = ox;
30763                                        }
30764                                }
30765                        } else if (as == 1) {
30766                                if (it.isOutputDouble()) {
30767                                        while (it.hasNext()) {
30768                                                final double ix = it.aDouble;
30769                                                int ox;
30770                                                ox = (int) toLong(ix);
30771                                                for (int j = 0; j < is; j++) {
30772                                                        oai32data[it.oIndex + j] = ox;
30773                                                }
30774                                        }
30775                                } else {
30776                                        while (it.hasNext()) {
30777                                                final long ix = it.aLong;
30778                                                int ox;
30779                                                ox = (int) toLong(ix);
30780                                                for (int j = 0; j < is; j++) {
30781                                                        oai32data[it.oIndex + j] = ox;
30782                                                }
30783                                        }
30784                                }
30785                        } else {
30786                                if (it.isOutputDouble()) {
30787                                        while (it.hasNext()) {
30788                                                for (int j = 0; j < is; j++) {
30789                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30790                                                        int ox;
30791                                                        ox = (int) toLong(ix);
30792                                                        oai32data[it.oIndex + j] = ox;
30793                                                }
30794                                        }
30795                                } else {
30796                                        while (it.hasNext()) {
30797                                                for (int j = 0; j < is; j++) {
30798                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30799                                                        int ox;
30800                                                        ox = (int) toLong(ix);
30801                                                        oai32data[it.oIndex + j] = ox;
30802                                                }
30803                                        }
30804                                }
30805                        }
30806                        break;
30807                case Dataset.FLOAT32:
30808                        final float[] of32data = ((FloatDataset) result).getData();
30809                        if (it.isOutputDouble()) {
30810                                while (it.hasNext()) {
30811                                        final double ix = it.aDouble;
30812                                        float ox;
30813                                        ox = (float) (Math.ceil(ix));
30814                                        of32data[it.oIndex] = ox;
30815                                }
30816                        } else {
30817                                while (it.hasNext()) {
30818                                        final long ix = it.aLong;
30819                                        float ox;
30820                                        ox = (float) (Math.ceil(ix));
30821                                        of32data[it.oIndex] = ox;
30822                                }
30823                        }
30824                        break;
30825                case Dataset.FLOAT64:
30826                        final double[] of64data = ((DoubleDataset) result).getData();
30827                        if (it.isOutputDouble()) {
30828                                while (it.hasNext()) {
30829                                        final double ix = it.aDouble;
30830                                        double ox;
30831                                        ox = (Math.ceil(ix));
30832                                        of64data[it.oIndex] = ox;
30833                                }
30834                        } else {
30835                                while (it.hasNext()) {
30836                                        final long ix = it.aLong;
30837                                        double ox;
30838                                        ox = (Math.ceil(ix));
30839                                        of64data[it.oIndex] = ox;
30840                                }
30841                        }
30842                        break;
30843                case Dataset.ARRAYFLOAT32:
30844                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
30845                        if (is == 1) {
30846                                if (it.isOutputDouble()) {
30847                                        while (it.hasNext()) {
30848                                                final double ix = it.aDouble;
30849                                                float ox;
30850                                                ox = (float) (Math.ceil(ix));
30851                                                oaf32data[it.oIndex] = ox;
30852                                        }
30853                                } else {
30854                                        while (it.hasNext()) {
30855                                                final long ix = it.aLong;
30856                                                float ox;
30857                                                ox = (float) (Math.ceil(ix));
30858                                                oaf32data[it.oIndex] = ox;
30859                                        }
30860                                }
30861                        } else if (as == 1) {
30862                                if (it.isOutputDouble()) {
30863                                        while (it.hasNext()) {
30864                                                final double ix = it.aDouble;
30865                                                float ox;
30866                                                ox = (float) (Math.ceil(ix));
30867                                                for (int j = 0; j < is; j++) {
30868                                                        oaf32data[it.oIndex + j] = ox;
30869                                                }
30870                                        }
30871                                } else {
30872                                        while (it.hasNext()) {
30873                                                final long ix = it.aLong;
30874                                                float ox;
30875                                                ox = (float) (Math.ceil(ix));
30876                                                for (int j = 0; j < is; j++) {
30877                                                        oaf32data[it.oIndex + j] = ox;
30878                                                }
30879                                        }
30880                                }
30881                        } else {
30882                                if (it.isOutputDouble()) {
30883                                        while (it.hasNext()) {
30884                                                for (int j = 0; j < is; j++) {
30885                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30886                                                        float ox;
30887                                                        ox = (float) (Math.ceil(ix));
30888                                                        oaf32data[it.oIndex + j] = ox;
30889                                                }
30890                                        }
30891                                } else {
30892                                        while (it.hasNext()) {
30893                                                for (int j = 0; j < is; j++) {
30894                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30895                                                        float ox;
30896                                                        ox = (float) (Math.ceil(ix));
30897                                                        oaf32data[it.oIndex + j] = ox;
30898                                                }
30899                                        }
30900                                }
30901                        }
30902                        break;
30903                case Dataset.ARRAYFLOAT64:
30904                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
30905                        if (is == 1) {
30906                                if (it.isOutputDouble()) {
30907                                        while (it.hasNext()) {
30908                                                final double ix = it.aDouble;
30909                                                double ox;
30910                                                ox = (Math.ceil(ix));
30911                                                oaf64data[it.oIndex] = ox;
30912                                        }
30913                                } else {
30914                                        while (it.hasNext()) {
30915                                                final long ix = it.aLong;
30916                                                double ox;
30917                                                ox = (Math.ceil(ix));
30918                                                oaf64data[it.oIndex] = ox;
30919                                        }
30920                                }
30921                        } else if (as == 1) {
30922                                if (it.isOutputDouble()) {
30923                                        while (it.hasNext()) {
30924                                                final double ix = it.aDouble;
30925                                                double ox;
30926                                                ox = (Math.ceil(ix));
30927                                                for (int j = 0; j < is; j++) {
30928                                                        oaf64data[it.oIndex + j] = ox;
30929                                                }
30930                                        }
30931                                } else {
30932                                        while (it.hasNext()) {
30933                                                final long ix = it.aLong;
30934                                                double ox;
30935                                                ox = (Math.ceil(ix));
30936                                                for (int j = 0; j < is; j++) {
30937                                                        oaf64data[it.oIndex + j] = ox;
30938                                                }
30939                                        }
30940                                }
30941                        } else {
30942                                if (it.isOutputDouble()) {
30943                                        while (it.hasNext()) {
30944                                                for (int j = 0; j < is; j++) {
30945                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
30946                                                        double ox;
30947                                                        ox = (Math.ceil(ix));
30948                                                        oaf64data[it.oIndex + j] = ox;
30949                                                }
30950                                        }
30951                                } else {
30952                                        while (it.hasNext()) {
30953                                                for (int j = 0; j < is; j++) {
30954                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
30955                                                        double ox;
30956                                                        ox = (Math.ceil(ix));
30957                                                        oaf64data[it.oIndex + j] = ox;
30958                                                }
30959                                        }
30960                                }
30961                        }
30962                        break;
30963                case Dataset.COMPLEX64:
30964                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
30965                        if (!da.isComplex()) {
30966                                if (it.isOutputDouble()) {
30967                                        final double iy = 0;
30968                                        while (it.hasNext()) {
30969                                                final double ix = it.aDouble;
30970                                                float ox;
30971                                                float oy;
30972                                                ox = (float) (Math.ceil(ix));
30973                                                oy = (float) (Math.ceil(iy));
30974                                                oc64data[it.oIndex] = ox;
30975                                                oc64data[it.oIndex + 1] = oy;
30976                                        }
30977                                } else {
30978                                        final long iy = 0;
30979                                        while (it.hasNext()) {
30980                                                final long ix = it.aLong;
30981                                                float ox;
30982                                                float oy;
30983                                                ox = (float) toLong(Math.ceil(ix));
30984                                                oy = (float) toLong(Math.ceil(iy));
30985                                                oc64data[it.oIndex] = ox;
30986                                                oc64data[it.oIndex + 1] = oy;
30987                                        }
30988                                }
30989                        } else {
30990                                while (it.hasNext()) {
30991                                        final double ix = it.aDouble;
30992                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
30993                                        float ox;
30994                                        float oy;
30995                                        ox = (float) (Math.ceil(ix));
30996                                        oy = (float) (Math.ceil(iy));
30997                                        oc64data[it.oIndex] = ox;
30998                                        oc64data[it.oIndex + 1] = oy;
30999                                }
31000                        }
31001                        break;
31002                case Dataset.COMPLEX128:
31003                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
31004                        if (!da.isComplex()) {
31005                                if (it.isOutputDouble()) {
31006                                        final double iy = 0;
31007                                        while (it.hasNext()) {
31008                                                final double ix = it.aDouble;
31009                                                double ox;
31010                                                double oy;
31011                                                ox = (Math.ceil(ix));
31012                                                oy = (Math.ceil(iy));
31013                                                oc128data[it.oIndex] = ox;
31014                                                oc128data[it.oIndex + 1] = oy;
31015                                        }
31016                                } else {
31017                                        final long iy = 0;
31018                                        while (it.hasNext()) {
31019                                                final long ix = it.aLong;
31020                                                double ox;
31021                                                double oy;
31022                                                ox = (double) (Math.ceil(ix));
31023                                                oy = (double) (Math.ceil(iy));
31024                                                oc128data[it.oIndex] = ox;
31025                                                oc128data[it.oIndex + 1] = oy;
31026                                        }
31027                                }
31028                        } else {
31029                                while (it.hasNext()) {
31030                                        final double ix = it.aDouble;
31031                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
31032                                        double ox;
31033                                        double oy;
31034                                        ox = (Math.ceil(ix));
31035                                        oy = (Math.ceil(iy));
31036                                        oc128data[it.oIndex] = ox;
31037                                        oc128data[it.oIndex + 1] = oy;
31038                                }
31039                        }
31040                        break;
31041                default:
31042                        throw new IllegalArgumentException("ceil supports integer, compound integer, real, compound real, complex datasets only");
31043                }
31044
31045                addFunctionName(result, "ceil");
31046                return result;
31047        }
31048
31049        /**
31050         * rint - round each element of the dataset
31051         * @param a single operand
31052         * @return dataset
31053         */
31054        public static Dataset rint(final Object a) {
31055                return rint(a, null);
31056        }
31057
31058        /**
31059         * rint - round each element of the dataset
31060         * @param a single operand
31061         * @param o output can be null - in which case, a new dataset is created
31062         * @return dataset
31063         */
31064        public static Dataset rint(final Object a, final Dataset o) {
31065                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
31066                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
31067                final Dataset result = it.getOutput();
31068                if (!result.isComplex()) {
31069                        if (da.isComplex()) {
31070                                da = da.getRealView();
31071                                it = new SingleInputBroadcastIterator(da, result, true);
31072                        }
31073                }
31074                final int is = result.getElementsPerItem();
31075                final int as = da.getElementsPerItem();
31076                final int dt = result.getDType();
31077
31078                switch(dt) {
31079                case Dataset.INT8:
31080                        final byte[] oi8data = ((ByteDataset) result).getData();
31081                        if (it.isOutputDouble()) {
31082                                while (it.hasNext()) {
31083                                        final double ix = it.aDouble;
31084                                        byte ox;
31085                                        ox = (byte) toLong(ix);
31086                                        oi8data[it.oIndex] = ox;
31087                                }
31088                        } else {
31089                                while (it.hasNext()) {
31090                                        final long ix = it.aLong;
31091                                        byte ox;
31092                                        ox = (byte) toLong(ix);
31093                                        oi8data[it.oIndex] = ox;
31094                                }
31095                        }
31096                        break;
31097                case Dataset.INT16:
31098                        final short[] oi16data = ((ShortDataset) result).getData();
31099                        if (it.isOutputDouble()) {
31100                                while (it.hasNext()) {
31101                                        final double ix = it.aDouble;
31102                                        short ox;
31103                                        ox = (short) toLong(ix);
31104                                        oi16data[it.oIndex] = ox;
31105                                }
31106                        } else {
31107                                while (it.hasNext()) {
31108                                        final long ix = it.aLong;
31109                                        short ox;
31110                                        ox = (short) toLong(ix);
31111                                        oi16data[it.oIndex] = ox;
31112                                }
31113                        }
31114                        break;
31115                case Dataset.INT64:
31116                        final long[] oi64data = ((LongDataset) result).getData();
31117                        if (it.isOutputDouble()) {
31118                                while (it.hasNext()) {
31119                                        final double ix = it.aDouble;
31120                                        long ox;
31121                                        ox = toLong(ix);
31122                                        oi64data[it.oIndex] = ox;
31123                                }
31124                        } else {
31125                                while (it.hasNext()) {
31126                                        final long ix = it.aLong;
31127                                        long ox;
31128                                        ox = toLong(ix);
31129                                        oi64data[it.oIndex] = ox;
31130                                }
31131                        }
31132                        break;
31133                case Dataset.INT32:
31134                        final int[] oi32data = ((IntegerDataset) result).getData();
31135                        if (it.isOutputDouble()) {
31136                                while (it.hasNext()) {
31137                                        final double ix = it.aDouble;
31138                                        int ox;
31139                                        ox = (int) toLong(ix);
31140                                        oi32data[it.oIndex] = ox;
31141                                }
31142                        } else {
31143                                while (it.hasNext()) {
31144                                        final long ix = it.aLong;
31145                                        int ox;
31146                                        ox = (int) toLong(ix);
31147                                        oi32data[it.oIndex] = ox;
31148                                }
31149                        }
31150                        break;
31151                case Dataset.ARRAYINT8:
31152                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
31153                        if (is == 1) {
31154                                if (it.isOutputDouble()) {
31155                                        while (it.hasNext()) {
31156                                                final double ix = it.aDouble;
31157                                                byte ox;
31158                                                ox = (byte) toLong(ix);
31159                                                oai8data[it.oIndex] = ox;
31160                                        }
31161                                } else {
31162                                        while (it.hasNext()) {
31163                                                final long ix = it.aLong;
31164                                                byte ox;
31165                                                ox = (byte) toLong(ix);
31166                                                oai8data[it.oIndex] = ox;
31167                                        }
31168                                }
31169                        } else if (as == 1) {
31170                                if (it.isOutputDouble()) {
31171                                        while (it.hasNext()) {
31172                                                final double ix = it.aDouble;
31173                                                byte ox;
31174                                                ox = (byte) toLong(ix);
31175                                                for (int j = 0; j < is; j++) {
31176                                                        oai8data[it.oIndex + j] = ox;
31177                                                }
31178                                        }
31179                                } else {
31180                                        while (it.hasNext()) {
31181                                                final long ix = it.aLong;
31182                                                byte ox;
31183                                                ox = (byte) toLong(ix);
31184                                                for (int j = 0; j < is; j++) {
31185                                                        oai8data[it.oIndex + j] = ox;
31186                                                }
31187                                        }
31188                                }
31189                        } else {
31190                                if (it.isOutputDouble()) {
31191                                        while (it.hasNext()) {
31192                                                for (int j = 0; j < is; j++) {
31193                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31194                                                        byte ox;
31195                                                        ox = (byte) toLong(ix);
31196                                                        oai8data[it.oIndex + j] = ox;
31197                                                }
31198                                        }
31199                                } else {
31200                                        while (it.hasNext()) {
31201                                                for (int j = 0; j < is; j++) {
31202                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31203                                                        byte ox;
31204                                                        ox = (byte) toLong(ix);
31205                                                        oai8data[it.oIndex + j] = ox;
31206                                                }
31207                                        }
31208                                }
31209                        }
31210                        break;
31211                case Dataset.ARRAYINT16:
31212                        final short[] oai16data = ((CompoundShortDataset) result).getData();
31213                        if (is == 1) {
31214                                if (it.isOutputDouble()) {
31215                                        while (it.hasNext()) {
31216                                                final double ix = it.aDouble;
31217                                                short ox;
31218                                                ox = (short) toLong(ix);
31219                                                oai16data[it.oIndex] = ox;
31220                                        }
31221                                } else {
31222                                        while (it.hasNext()) {
31223                                                final long ix = it.aLong;
31224                                                short ox;
31225                                                ox = (short) toLong(ix);
31226                                                oai16data[it.oIndex] = ox;
31227                                        }
31228                                }
31229                        } else if (as == 1) {
31230                                if (it.isOutputDouble()) {
31231                                        while (it.hasNext()) {
31232                                                final double ix = it.aDouble;
31233                                                short ox;
31234                                                ox = (short) toLong(ix);
31235                                                for (int j = 0; j < is; j++) {
31236                                                        oai16data[it.oIndex + j] = ox;
31237                                                }
31238                                        }
31239                                } else {
31240                                        while (it.hasNext()) {
31241                                                final long ix = it.aLong;
31242                                                short ox;
31243                                                ox = (short) toLong(ix);
31244                                                for (int j = 0; j < is; j++) {
31245                                                        oai16data[it.oIndex + j] = ox;
31246                                                }
31247                                        }
31248                                }
31249                        } else {
31250                                if (it.isOutputDouble()) {
31251                                        while (it.hasNext()) {
31252                                                for (int j = 0; j < is; j++) {
31253                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31254                                                        short ox;
31255                                                        ox = (short) toLong(ix);
31256                                                        oai16data[it.oIndex + j] = ox;
31257                                                }
31258                                        }
31259                                } else {
31260                                        while (it.hasNext()) {
31261                                                for (int j = 0; j < is; j++) {
31262                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31263                                                        short ox;
31264                                                        ox = (short) toLong(ix);
31265                                                        oai16data[it.oIndex + j] = ox;
31266                                                }
31267                                        }
31268                                }
31269                        }
31270                        break;
31271                case Dataset.ARRAYINT64:
31272                        final long[] oai64data = ((CompoundLongDataset) result).getData();
31273                        if (is == 1) {
31274                                if (it.isOutputDouble()) {
31275                                        while (it.hasNext()) {
31276                                                final double ix = it.aDouble;
31277                                                long ox;
31278                                                ox = toLong(ix);
31279                                                oai64data[it.oIndex] = ox;
31280                                        }
31281                                } else {
31282                                        while (it.hasNext()) {
31283                                                final long ix = it.aLong;
31284                                                long ox;
31285                                                ox = toLong(ix);
31286                                                oai64data[it.oIndex] = ox;
31287                                        }
31288                                }
31289                        } else if (as == 1) {
31290                                if (it.isOutputDouble()) {
31291                                        while (it.hasNext()) {
31292                                                final double ix = it.aDouble;
31293                                                long ox;
31294                                                ox = toLong(ix);
31295                                                for (int j = 0; j < is; j++) {
31296                                                        oai64data[it.oIndex + j] = ox;
31297                                                }
31298                                        }
31299                                } else {
31300                                        while (it.hasNext()) {
31301                                                final long ix = it.aLong;
31302                                                long ox;
31303                                                ox = toLong(ix);
31304                                                for (int j = 0; j < is; j++) {
31305                                                        oai64data[it.oIndex + j] = ox;
31306                                                }
31307                                        }
31308                                }
31309                        } else {
31310                                if (it.isOutputDouble()) {
31311                                        while (it.hasNext()) {
31312                                                for (int j = 0; j < is; j++) {
31313                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31314                                                        long ox;
31315                                                        ox = toLong(ix);
31316                                                        oai64data[it.oIndex + j] = ox;
31317                                                }
31318                                        }
31319                                } else {
31320                                        while (it.hasNext()) {
31321                                                for (int j = 0; j < is; j++) {
31322                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31323                                                        long ox;
31324                                                        ox = toLong(ix);
31325                                                        oai64data[it.oIndex + j] = ox;
31326                                                }
31327                                        }
31328                                }
31329                        }
31330                        break;
31331                case Dataset.ARRAYINT32:
31332                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
31333                        if (is == 1) {
31334                                if (it.isOutputDouble()) {
31335                                        while (it.hasNext()) {
31336                                                final double ix = it.aDouble;
31337                                                int ox;
31338                                                ox = (int) toLong(ix);
31339                                                oai32data[it.oIndex] = ox;
31340                                        }
31341                                } else {
31342                                        while (it.hasNext()) {
31343                                                final long ix = it.aLong;
31344                                                int ox;
31345                                                ox = (int) toLong(ix);
31346                                                oai32data[it.oIndex] = ox;
31347                                        }
31348                                }
31349                        } else if (as == 1) {
31350                                if (it.isOutputDouble()) {
31351                                        while (it.hasNext()) {
31352                                                final double ix = it.aDouble;
31353                                                int ox;
31354                                                ox = (int) toLong(ix);
31355                                                for (int j = 0; j < is; j++) {
31356                                                        oai32data[it.oIndex + j] = ox;
31357                                                }
31358                                        }
31359                                } else {
31360                                        while (it.hasNext()) {
31361                                                final long ix = it.aLong;
31362                                                int ox;
31363                                                ox = (int) toLong(ix);
31364                                                for (int j = 0; j < is; j++) {
31365                                                        oai32data[it.oIndex + j] = ox;
31366                                                }
31367                                        }
31368                                }
31369                        } else {
31370                                if (it.isOutputDouble()) {
31371                                        while (it.hasNext()) {
31372                                                for (int j = 0; j < is; j++) {
31373                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31374                                                        int ox;
31375                                                        ox = (int) toLong(ix);
31376                                                        oai32data[it.oIndex + j] = ox;
31377                                                }
31378                                        }
31379                                } else {
31380                                        while (it.hasNext()) {
31381                                                for (int j = 0; j < is; j++) {
31382                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31383                                                        int ox;
31384                                                        ox = (int) toLong(ix);
31385                                                        oai32data[it.oIndex + j] = ox;
31386                                                }
31387                                        }
31388                                }
31389                        }
31390                        break;
31391                case Dataset.FLOAT32:
31392                        final float[] of32data = ((FloatDataset) result).getData();
31393                        if (it.isOutputDouble()) {
31394                                while (it.hasNext()) {
31395                                        final double ix = it.aDouble;
31396                                        float ox;
31397                                        ox = (float) (Math.rint(ix));
31398                                        of32data[it.oIndex] = ox;
31399                                }
31400                        } else {
31401                                while (it.hasNext()) {
31402                                        final long ix = it.aLong;
31403                                        float ox;
31404                                        ox = (float) (Math.rint(ix));
31405                                        of32data[it.oIndex] = ox;
31406                                }
31407                        }
31408                        break;
31409                case Dataset.FLOAT64:
31410                        final double[] of64data = ((DoubleDataset) result).getData();
31411                        if (it.isOutputDouble()) {
31412                                while (it.hasNext()) {
31413                                        final double ix = it.aDouble;
31414                                        double ox;
31415                                        ox = (Math.rint(ix));
31416                                        of64data[it.oIndex] = ox;
31417                                }
31418                        } else {
31419                                while (it.hasNext()) {
31420                                        final long ix = it.aLong;
31421                                        double ox;
31422                                        ox = (Math.rint(ix));
31423                                        of64data[it.oIndex] = ox;
31424                                }
31425                        }
31426                        break;
31427                case Dataset.ARRAYFLOAT32:
31428                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
31429                        if (is == 1) {
31430                                if (it.isOutputDouble()) {
31431                                        while (it.hasNext()) {
31432                                                final double ix = it.aDouble;
31433                                                float ox;
31434                                                ox = (float) (Math.rint(ix));
31435                                                oaf32data[it.oIndex] = ox;
31436                                        }
31437                                } else {
31438                                        while (it.hasNext()) {
31439                                                final long ix = it.aLong;
31440                                                float ox;
31441                                                ox = (float) (Math.rint(ix));
31442                                                oaf32data[it.oIndex] = ox;
31443                                        }
31444                                }
31445                        } else if (as == 1) {
31446                                if (it.isOutputDouble()) {
31447                                        while (it.hasNext()) {
31448                                                final double ix = it.aDouble;
31449                                                float ox;
31450                                                ox = (float) (Math.rint(ix));
31451                                                for (int j = 0; j < is; j++) {
31452                                                        oaf32data[it.oIndex + j] = ox;
31453                                                }
31454                                        }
31455                                } else {
31456                                        while (it.hasNext()) {
31457                                                final long ix = it.aLong;
31458                                                float ox;
31459                                                ox = (float) (Math.rint(ix));
31460                                                for (int j = 0; j < is; j++) {
31461                                                        oaf32data[it.oIndex + j] = ox;
31462                                                }
31463                                        }
31464                                }
31465                        } else {
31466                                if (it.isOutputDouble()) {
31467                                        while (it.hasNext()) {
31468                                                for (int j = 0; j < is; j++) {
31469                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31470                                                        float ox;
31471                                                        ox = (float) (Math.rint(ix));
31472                                                        oaf32data[it.oIndex + j] = ox;
31473                                                }
31474                                        }
31475                                } else {
31476                                        while (it.hasNext()) {
31477                                                for (int j = 0; j < is; j++) {
31478                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31479                                                        float ox;
31480                                                        ox = (float) (Math.rint(ix));
31481                                                        oaf32data[it.oIndex + j] = ox;
31482                                                }
31483                                        }
31484                                }
31485                        }
31486                        break;
31487                case Dataset.ARRAYFLOAT64:
31488                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
31489                        if (is == 1) {
31490                                if (it.isOutputDouble()) {
31491                                        while (it.hasNext()) {
31492                                                final double ix = it.aDouble;
31493                                                double ox;
31494                                                ox = (Math.rint(ix));
31495                                                oaf64data[it.oIndex] = ox;
31496                                        }
31497                                } else {
31498                                        while (it.hasNext()) {
31499                                                final long ix = it.aLong;
31500                                                double ox;
31501                                                ox = (Math.rint(ix));
31502                                                oaf64data[it.oIndex] = ox;
31503                                        }
31504                                }
31505                        } else if (as == 1) {
31506                                if (it.isOutputDouble()) {
31507                                        while (it.hasNext()) {
31508                                                final double ix = it.aDouble;
31509                                                double ox;
31510                                                ox = (Math.rint(ix));
31511                                                for (int j = 0; j < is; j++) {
31512                                                        oaf64data[it.oIndex + j] = ox;
31513                                                }
31514                                        }
31515                                } else {
31516                                        while (it.hasNext()) {
31517                                                final long ix = it.aLong;
31518                                                double ox;
31519                                                ox = (Math.rint(ix));
31520                                                for (int j = 0; j < is; j++) {
31521                                                        oaf64data[it.oIndex + j] = ox;
31522                                                }
31523                                        }
31524                                }
31525                        } else {
31526                                if (it.isOutputDouble()) {
31527                                        while (it.hasNext()) {
31528                                                for (int j = 0; j < is; j++) {
31529                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31530                                                        double ox;
31531                                                        ox = (Math.rint(ix));
31532                                                        oaf64data[it.oIndex + j] = ox;
31533                                                }
31534                                        }
31535                                } else {
31536                                        while (it.hasNext()) {
31537                                                for (int j = 0; j < is; j++) {
31538                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31539                                                        double ox;
31540                                                        ox = (Math.rint(ix));
31541                                                        oaf64data[it.oIndex + j] = ox;
31542                                                }
31543                                        }
31544                                }
31545                        }
31546                        break;
31547                case Dataset.COMPLEX64:
31548                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
31549                        if (!da.isComplex()) {
31550                                if (it.isOutputDouble()) {
31551                                        final double iy = 0;
31552                                        while (it.hasNext()) {
31553                                                final double ix = it.aDouble;
31554                                                float ox;
31555                                                float oy;
31556                                                ox = (float) (Math.rint(ix));
31557                                                oy = (float) (Math.rint(iy));
31558                                                oc64data[it.oIndex] = ox;
31559                                                oc64data[it.oIndex + 1] = oy;
31560                                        }
31561                                } else {
31562                                        final long iy = 0;
31563                                        while (it.hasNext()) {
31564                                                final long ix = it.aLong;
31565                                                float ox;
31566                                                float oy;
31567                                                ox = (float) toLong(Math.rint(ix));
31568                                                oy = (float) toLong(Math.rint(iy));
31569                                                oc64data[it.oIndex] = ox;
31570                                                oc64data[it.oIndex + 1] = oy;
31571                                        }
31572                                }
31573                        } else {
31574                                while (it.hasNext()) {
31575                                        final double ix = it.aDouble;
31576                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
31577                                        float ox;
31578                                        float oy;
31579                                        ox = (float) (Math.rint(ix));
31580                                        oy = (float) (Math.rint(iy));
31581                                        oc64data[it.oIndex] = ox;
31582                                        oc64data[it.oIndex + 1] = oy;
31583                                }
31584                        }
31585                        break;
31586                case Dataset.COMPLEX128:
31587                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
31588                        if (!da.isComplex()) {
31589                                if (it.isOutputDouble()) {
31590                                        final double iy = 0;
31591                                        while (it.hasNext()) {
31592                                                final double ix = it.aDouble;
31593                                                double ox;
31594                                                double oy;
31595                                                ox = (Math.rint(ix));
31596                                                oy = (Math.rint(iy));
31597                                                oc128data[it.oIndex] = ox;
31598                                                oc128data[it.oIndex + 1] = oy;
31599                                        }
31600                                } else {
31601                                        final long iy = 0;
31602                                        while (it.hasNext()) {
31603                                                final long ix = it.aLong;
31604                                                double ox;
31605                                                double oy;
31606                                                ox = (double) (Math.rint(ix));
31607                                                oy = (double) (Math.rint(iy));
31608                                                oc128data[it.oIndex] = ox;
31609                                                oc128data[it.oIndex + 1] = oy;
31610                                        }
31611                                }
31612                        } else {
31613                                while (it.hasNext()) {
31614                                        final double ix = it.aDouble;
31615                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
31616                                        double ox;
31617                                        double oy;
31618                                        ox = (Math.rint(ix));
31619                                        oy = (Math.rint(iy));
31620                                        oc128data[it.oIndex] = ox;
31621                                        oc128data[it.oIndex + 1] = oy;
31622                                }
31623                        }
31624                        break;
31625                default:
31626                        throw new IllegalArgumentException("rint supports integer, compound integer, real, compound real, complex datasets only");
31627                }
31628
31629                addFunctionName(result, "rint");
31630                return result;
31631        }
31632
31633        /**
31634         * truncate - truncate each element to integers of the dataset
31635         * @param a single operand
31636         * @return dataset
31637         */
31638        public static Dataset truncate(final Object a) {
31639                return truncate(a, null);
31640        }
31641
31642        /**
31643         * truncate - truncate each element to integers of the dataset
31644         * @param a single operand
31645         * @param o output can be null - in which case, a new dataset is created
31646         * @return dataset
31647         */
31648        public static Dataset truncate(final Object a, final Dataset o) {
31649                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
31650                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
31651                final Dataset result = it.getOutput();
31652                if (!result.isComplex()) {
31653                        if (da.isComplex()) {
31654                                da = da.getRealView();
31655                                it = new SingleInputBroadcastIterator(da, result, true);
31656                        }
31657                }
31658                final int is = result.getElementsPerItem();
31659                final int as = da.getElementsPerItem();
31660                final int dt = result.getDType();
31661
31662                switch(dt) {
31663                case Dataset.INT8:
31664                        final byte[] oi8data = ((ByteDataset) result).getData();
31665                        if (it.isOutputDouble()) {
31666                                while (it.hasNext()) {
31667                                        final double ix = it.aDouble;
31668                                        byte ox;
31669                                        ox = (byte) toLong(ix);
31670                                        oi8data[it.oIndex] = ox;
31671                                }
31672                        } else {
31673                                while (it.hasNext()) {
31674                                        final long ix = it.aLong;
31675                                        byte ox;
31676                                        ox = (byte) toLong(ix);
31677                                        oi8data[it.oIndex] = ox;
31678                                }
31679                        }
31680                        break;
31681                case Dataset.INT16:
31682                        final short[] oi16data = ((ShortDataset) result).getData();
31683                        if (it.isOutputDouble()) {
31684                                while (it.hasNext()) {
31685                                        final double ix = it.aDouble;
31686                                        short ox;
31687                                        ox = (short) toLong(ix);
31688                                        oi16data[it.oIndex] = ox;
31689                                }
31690                        } else {
31691                                while (it.hasNext()) {
31692                                        final long ix = it.aLong;
31693                                        short ox;
31694                                        ox = (short) toLong(ix);
31695                                        oi16data[it.oIndex] = ox;
31696                                }
31697                        }
31698                        break;
31699                case Dataset.INT64:
31700                        final long[] oi64data = ((LongDataset) result).getData();
31701                        if (it.isOutputDouble()) {
31702                                while (it.hasNext()) {
31703                                        final double ix = it.aDouble;
31704                                        long ox;
31705                                        ox = toLong(ix);
31706                                        oi64data[it.oIndex] = ox;
31707                                }
31708                        } else {
31709                                while (it.hasNext()) {
31710                                        final long ix = it.aLong;
31711                                        long ox;
31712                                        ox = toLong(ix);
31713                                        oi64data[it.oIndex] = ox;
31714                                }
31715                        }
31716                        break;
31717                case Dataset.INT32:
31718                        final int[] oi32data = ((IntegerDataset) result).getData();
31719                        if (it.isOutputDouble()) {
31720                                while (it.hasNext()) {
31721                                        final double ix = it.aDouble;
31722                                        int ox;
31723                                        ox = (int) toLong(ix);
31724                                        oi32data[it.oIndex] = ox;
31725                                }
31726                        } else {
31727                                while (it.hasNext()) {
31728                                        final long ix = it.aLong;
31729                                        int ox;
31730                                        ox = (int) toLong(ix);
31731                                        oi32data[it.oIndex] = ox;
31732                                }
31733                        }
31734                        break;
31735                case Dataset.ARRAYINT8:
31736                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
31737                        if (is == 1) {
31738                                if (it.isOutputDouble()) {
31739                                        while (it.hasNext()) {
31740                                                final double ix = it.aDouble;
31741                                                byte ox;
31742                                                ox = (byte) toLong(ix);
31743                                                oai8data[it.oIndex] = ox;
31744                                        }
31745                                } else {
31746                                        while (it.hasNext()) {
31747                                                final long ix = it.aLong;
31748                                                byte ox;
31749                                                ox = (byte) toLong(ix);
31750                                                oai8data[it.oIndex] = ox;
31751                                        }
31752                                }
31753                        } else if (as == 1) {
31754                                if (it.isOutputDouble()) {
31755                                        while (it.hasNext()) {
31756                                                final double ix = it.aDouble;
31757                                                byte ox;
31758                                                ox = (byte) toLong(ix);
31759                                                for (int j = 0; j < is; j++) {
31760                                                        oai8data[it.oIndex + j] = ox;
31761                                                }
31762                                        }
31763                                } else {
31764                                        while (it.hasNext()) {
31765                                                final long ix = it.aLong;
31766                                                byte ox;
31767                                                ox = (byte) toLong(ix);
31768                                                for (int j = 0; j < is; j++) {
31769                                                        oai8data[it.oIndex + j] = ox;
31770                                                }
31771                                        }
31772                                }
31773                        } else {
31774                                if (it.isOutputDouble()) {
31775                                        while (it.hasNext()) {
31776                                                for (int j = 0; j < is; j++) {
31777                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31778                                                        byte ox;
31779                                                        ox = (byte) toLong(ix);
31780                                                        oai8data[it.oIndex + j] = ox;
31781                                                }
31782                                        }
31783                                } else {
31784                                        while (it.hasNext()) {
31785                                                for (int j = 0; j < is; j++) {
31786                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31787                                                        byte ox;
31788                                                        ox = (byte) toLong(ix);
31789                                                        oai8data[it.oIndex + j] = ox;
31790                                                }
31791                                        }
31792                                }
31793                        }
31794                        break;
31795                case Dataset.ARRAYINT16:
31796                        final short[] oai16data = ((CompoundShortDataset) result).getData();
31797                        if (is == 1) {
31798                                if (it.isOutputDouble()) {
31799                                        while (it.hasNext()) {
31800                                                final double ix = it.aDouble;
31801                                                short ox;
31802                                                ox = (short) toLong(ix);
31803                                                oai16data[it.oIndex] = ox;
31804                                        }
31805                                } else {
31806                                        while (it.hasNext()) {
31807                                                final long ix = it.aLong;
31808                                                short ox;
31809                                                ox = (short) toLong(ix);
31810                                                oai16data[it.oIndex] = ox;
31811                                        }
31812                                }
31813                        } else if (as == 1) {
31814                                if (it.isOutputDouble()) {
31815                                        while (it.hasNext()) {
31816                                                final double ix = it.aDouble;
31817                                                short ox;
31818                                                ox = (short) toLong(ix);
31819                                                for (int j = 0; j < is; j++) {
31820                                                        oai16data[it.oIndex + j] = ox;
31821                                                }
31822                                        }
31823                                } else {
31824                                        while (it.hasNext()) {
31825                                                final long ix = it.aLong;
31826                                                short ox;
31827                                                ox = (short) toLong(ix);
31828                                                for (int j = 0; j < is; j++) {
31829                                                        oai16data[it.oIndex + j] = ox;
31830                                                }
31831                                        }
31832                                }
31833                        } else {
31834                                if (it.isOutputDouble()) {
31835                                        while (it.hasNext()) {
31836                                                for (int j = 0; j < is; j++) {
31837                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31838                                                        short ox;
31839                                                        ox = (short) toLong(ix);
31840                                                        oai16data[it.oIndex + j] = ox;
31841                                                }
31842                                        }
31843                                } else {
31844                                        while (it.hasNext()) {
31845                                                for (int j = 0; j < is; j++) {
31846                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31847                                                        short ox;
31848                                                        ox = (short) toLong(ix);
31849                                                        oai16data[it.oIndex + j] = ox;
31850                                                }
31851                                        }
31852                                }
31853                        }
31854                        break;
31855                case Dataset.ARRAYINT64:
31856                        final long[] oai64data = ((CompoundLongDataset) result).getData();
31857                        if (is == 1) {
31858                                if (it.isOutputDouble()) {
31859                                        while (it.hasNext()) {
31860                                                final double ix = it.aDouble;
31861                                                long ox;
31862                                                ox = toLong(ix);
31863                                                oai64data[it.oIndex] = ox;
31864                                        }
31865                                } else {
31866                                        while (it.hasNext()) {
31867                                                final long ix = it.aLong;
31868                                                long ox;
31869                                                ox = toLong(ix);
31870                                                oai64data[it.oIndex] = ox;
31871                                        }
31872                                }
31873                        } else if (as == 1) {
31874                                if (it.isOutputDouble()) {
31875                                        while (it.hasNext()) {
31876                                                final double ix = it.aDouble;
31877                                                long ox;
31878                                                ox = toLong(ix);
31879                                                for (int j = 0; j < is; j++) {
31880                                                        oai64data[it.oIndex + j] = ox;
31881                                                }
31882                                        }
31883                                } else {
31884                                        while (it.hasNext()) {
31885                                                final long ix = it.aLong;
31886                                                long ox;
31887                                                ox = toLong(ix);
31888                                                for (int j = 0; j < is; j++) {
31889                                                        oai64data[it.oIndex + j] = ox;
31890                                                }
31891                                        }
31892                                }
31893                        } else {
31894                                if (it.isOutputDouble()) {
31895                                        while (it.hasNext()) {
31896                                                for (int j = 0; j < is; j++) {
31897                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31898                                                        long ox;
31899                                                        ox = toLong(ix);
31900                                                        oai64data[it.oIndex + j] = ox;
31901                                                }
31902                                        }
31903                                } else {
31904                                        while (it.hasNext()) {
31905                                                for (int j = 0; j < is; j++) {
31906                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31907                                                        long ox;
31908                                                        ox = toLong(ix);
31909                                                        oai64data[it.oIndex + j] = ox;
31910                                                }
31911                                        }
31912                                }
31913                        }
31914                        break;
31915                case Dataset.ARRAYINT32:
31916                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
31917                        if (is == 1) {
31918                                if (it.isOutputDouble()) {
31919                                        while (it.hasNext()) {
31920                                                final double ix = it.aDouble;
31921                                                int ox;
31922                                                ox = (int) toLong(ix);
31923                                                oai32data[it.oIndex] = ox;
31924                                        }
31925                                } else {
31926                                        while (it.hasNext()) {
31927                                                final long ix = it.aLong;
31928                                                int ox;
31929                                                ox = (int) toLong(ix);
31930                                                oai32data[it.oIndex] = ox;
31931                                        }
31932                                }
31933                        } else if (as == 1) {
31934                                if (it.isOutputDouble()) {
31935                                        while (it.hasNext()) {
31936                                                final double ix = it.aDouble;
31937                                                int ox;
31938                                                ox = (int) toLong(ix);
31939                                                for (int j = 0; j < is; j++) {
31940                                                        oai32data[it.oIndex + j] = ox;
31941                                                }
31942                                        }
31943                                } else {
31944                                        while (it.hasNext()) {
31945                                                final long ix = it.aLong;
31946                                                int ox;
31947                                                ox = (int) toLong(ix);
31948                                                for (int j = 0; j < is; j++) {
31949                                                        oai32data[it.oIndex + j] = ox;
31950                                                }
31951                                        }
31952                                }
31953                        } else {
31954                                if (it.isOutputDouble()) {
31955                                        while (it.hasNext()) {
31956                                                for (int j = 0; j < is; j++) {
31957                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
31958                                                        int ox;
31959                                                        ox = (int) toLong(ix);
31960                                                        oai32data[it.oIndex + j] = ox;
31961                                                }
31962                                        }
31963                                } else {
31964                                        while (it.hasNext()) {
31965                                                for (int j = 0; j < is; j++) {
31966                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
31967                                                        int ox;
31968                                                        ox = (int) toLong(ix);
31969                                                        oai32data[it.oIndex + j] = ox;
31970                                                }
31971                                        }
31972                                }
31973                        }
31974                        break;
31975                case Dataset.FLOAT32:
31976                        final float[] of32data = ((FloatDataset) result).getData();
31977                        if (it.isOutputDouble()) {
31978                                while (it.hasNext()) {
31979                                        final double ix = it.aDouble;
31980                                        float ox;
31981                                        ox = (float) (toLong(ix));
31982                                        of32data[it.oIndex] = ox;
31983                                }
31984                        } else {
31985                                while (it.hasNext()) {
31986                                        final long ix = it.aLong;
31987                                        float ox;
31988                                        ox = (toLong(ix));
31989                                        of32data[it.oIndex] = ox;
31990                                }
31991                        }
31992                        break;
31993                case Dataset.FLOAT64:
31994                        final double[] of64data = ((DoubleDataset) result).getData();
31995                        if (it.isOutputDouble()) {
31996                                while (it.hasNext()) {
31997                                        final double ix = it.aDouble;
31998                                        double ox;
31999                                        ox = (toLong(ix));
32000                                        of64data[it.oIndex] = ox;
32001                                }
32002                        } else {
32003                                while (it.hasNext()) {
32004                                        final long ix = it.aLong;
32005                                        double ox;
32006                                        ox = (toLong(ix));
32007                                        of64data[it.oIndex] = ox;
32008                                }
32009                        }
32010                        break;
32011                case Dataset.ARRAYFLOAT32:
32012                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
32013                        if (is == 1) {
32014                                if (it.isOutputDouble()) {
32015                                        while (it.hasNext()) {
32016                                                final double ix = it.aDouble;
32017                                                float ox;
32018                                                ox = (float) (toLong(ix));
32019                                                oaf32data[it.oIndex] = ox;
32020                                        }
32021                                } else {
32022                                        while (it.hasNext()) {
32023                                                final long ix = it.aLong;
32024                                                float ox;
32025                                                ox = (toLong(ix));
32026                                                oaf32data[it.oIndex] = ox;
32027                                        }
32028                                }
32029                        } else if (as == 1) {
32030                                if (it.isOutputDouble()) {
32031                                        while (it.hasNext()) {
32032                                                final double ix = it.aDouble;
32033                                                float ox;
32034                                                ox = (float) (toLong(ix));
32035                                                for (int j = 0; j < is; j++) {
32036                                                        oaf32data[it.oIndex + j] = ox;
32037                                                }
32038                                        }
32039                                } else {
32040                                        while (it.hasNext()) {
32041                                                final long ix = it.aLong;
32042                                                float ox;
32043                                                ox = (toLong(ix));
32044                                                for (int j = 0; j < is; j++) {
32045                                                        oaf32data[it.oIndex + j] = ox;
32046                                                }
32047                                        }
32048                                }
32049                        } else {
32050                                if (it.isOutputDouble()) {
32051                                        while (it.hasNext()) {
32052                                                for (int j = 0; j < is; j++) {
32053                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32054                                                        float ox;
32055                                                        ox = (float) (toLong(ix));
32056                                                        oaf32data[it.oIndex + j] = ox;
32057                                                }
32058                                        }
32059                                } else {
32060                                        while (it.hasNext()) {
32061                                                for (int j = 0; j < is; j++) {
32062                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32063                                                        float ox;
32064                                                        ox = (toLong(ix));
32065                                                        oaf32data[it.oIndex + j] = ox;
32066                                                }
32067                                        }
32068                                }
32069                        }
32070                        break;
32071                case Dataset.ARRAYFLOAT64:
32072                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
32073                        if (is == 1) {
32074                                if (it.isOutputDouble()) {
32075                                        while (it.hasNext()) {
32076                                                final double ix = it.aDouble;
32077                                                double ox;
32078                                                ox = (toLong(ix));
32079                                                oaf64data[it.oIndex] = ox;
32080                                        }
32081                                } else {
32082                                        while (it.hasNext()) {
32083                                                final long ix = it.aLong;
32084                                                double ox;
32085                                                ox = (toLong(ix));
32086                                                oaf64data[it.oIndex] = ox;
32087                                        }
32088                                }
32089                        } else if (as == 1) {
32090                                if (it.isOutputDouble()) {
32091                                        while (it.hasNext()) {
32092                                                final double ix = it.aDouble;
32093                                                double ox;
32094                                                ox = (toLong(ix));
32095                                                for (int j = 0; j < is; j++) {
32096                                                        oaf64data[it.oIndex + j] = ox;
32097                                                }
32098                                        }
32099                                } else {
32100                                        while (it.hasNext()) {
32101                                                final long ix = it.aLong;
32102                                                double ox;
32103                                                ox = (toLong(ix));
32104                                                for (int j = 0; j < is; j++) {
32105                                                        oaf64data[it.oIndex + j] = ox;
32106                                                }
32107                                        }
32108                                }
32109                        } else {
32110                                if (it.isOutputDouble()) {
32111                                        while (it.hasNext()) {
32112                                                for (int j = 0; j < is; j++) {
32113                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32114                                                        double ox;
32115                                                        ox = (toLong(ix));
32116                                                        oaf64data[it.oIndex + j] = ox;
32117                                                }
32118                                        }
32119                                } else {
32120                                        while (it.hasNext()) {
32121                                                for (int j = 0; j < is; j++) {
32122                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32123                                                        double ox;
32124                                                        ox = (toLong(ix));
32125                                                        oaf64data[it.oIndex + j] = ox;
32126                                                }
32127                                        }
32128                                }
32129                        }
32130                        break;
32131                case Dataset.COMPLEX64:
32132                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
32133                        if (!da.isComplex()) {
32134                                if (it.isOutputDouble()) {
32135                                        final double iy = 0;
32136                                        while (it.hasNext()) {
32137                                                final double ix = it.aDouble;
32138                                                float ox;
32139                                                float oy;
32140                                                ox = (float) (toLong(ix));
32141                                                oy = (float) (toLong(iy));
32142                                                oc64data[it.oIndex] = ox;
32143                                                oc64data[it.oIndex + 1] = oy;
32144                                        }
32145                                } else {
32146                                        final long iy = 0;
32147                                        while (it.hasNext()) {
32148                                                final long ix = it.aLong;
32149                                                float ox;
32150                                                float oy;
32151                                                ox = (float) toLong(toLong(ix));
32152                                                oy = (float) toLong(toLong(iy));
32153                                                oc64data[it.oIndex] = ox;
32154                                                oc64data[it.oIndex + 1] = oy;
32155                                        }
32156                                }
32157                        } else {
32158                                while (it.hasNext()) {
32159                                        final double ix = it.aDouble;
32160                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
32161                                        float ox;
32162                                        float oy;
32163                                        ox = (float) (toLong(ix));
32164                                        oy = (float) (toLong(iy));
32165                                        oc64data[it.oIndex] = ox;
32166                                        oc64data[it.oIndex + 1] = oy;
32167                                }
32168                        }
32169                        break;
32170                case Dataset.COMPLEX128:
32171                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
32172                        if (!da.isComplex()) {
32173                                if (it.isOutputDouble()) {
32174                                        final double iy = 0;
32175                                        while (it.hasNext()) {
32176                                                final double ix = it.aDouble;
32177                                                double ox;
32178                                                double oy;
32179                                                ox = (toLong(ix));
32180                                                oy = (toLong(iy));
32181                                                oc128data[it.oIndex] = ox;
32182                                                oc128data[it.oIndex + 1] = oy;
32183                                        }
32184                                } else {
32185                                        final long iy = 0;
32186                                        while (it.hasNext()) {
32187                                                final long ix = it.aLong;
32188                                                double ox;
32189                                                double oy;
32190                                                ox = (toLong(ix));
32191                                                oy = (toLong(iy));
32192                                                oc128data[it.oIndex] = ox;
32193                                                oc128data[it.oIndex + 1] = oy;
32194                                        }
32195                                }
32196                        } else {
32197                                while (it.hasNext()) {
32198                                        final double ix = it.aDouble;
32199                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
32200                                        double ox;
32201                                        double oy;
32202                                        ox = (toLong(ix));
32203                                        oy = (toLong(iy));
32204                                        oc128data[it.oIndex] = ox;
32205                                        oc128data[it.oIndex + 1] = oy;
32206                                }
32207                        }
32208                        break;
32209                default:
32210                        throw new IllegalArgumentException("truncate supports integer, compound integer, real, compound real, complex datasets only");
32211                }
32212
32213                addFunctionName(result, "truncate");
32214                return result;
32215        }
32216
32217        /**
32218         * toDegrees - convert to degrees
32219         * @param a single operand
32220         * @return dataset
32221         */
32222        public static Dataset toDegrees(final Object a) {
32223                return toDegrees(a, null);
32224        }
32225
32226        /**
32227         * toDegrees - convert to degrees
32228         * @param a single operand
32229         * @param o output can be null - in which case, a new dataset is created
32230         * @return dataset
32231         */
32232        public static Dataset toDegrees(final Object a, final Dataset o) {
32233                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
32234                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
32235                final Dataset result = it.getOutput();
32236                if (!result.isComplex()) {
32237                        if (da.isComplex()) {
32238                                da = da.getRealView();
32239                                it = new SingleInputBroadcastIterator(da, result, true);
32240                        }
32241                }
32242                final int is = result.getElementsPerItem();
32243                final int as = da.getElementsPerItem();
32244                final int dt = result.getDType();
32245
32246                switch(dt) {
32247                case Dataset.INT8:
32248                        final byte[] oi8data = ((ByteDataset) result).getData();
32249                        if (it.isOutputDouble()) {
32250                                while (it.hasNext()) {
32251                                        final double ix = it.aDouble;
32252                                        byte ox;
32253                                        ox = (byte) toLong(Math.toDegrees(ix));
32254                                        oi8data[it.oIndex] = ox;
32255                                }
32256                        } else {
32257                                while (it.hasNext()) {
32258                                        final long ix = it.aLong;
32259                                        byte ox;
32260                                        ox = (byte) toLong(Math.toDegrees(ix));
32261                                        oi8data[it.oIndex] = ox;
32262                                }
32263                        }
32264                        break;
32265                case Dataset.INT16:
32266                        final short[] oi16data = ((ShortDataset) result).getData();
32267                        if (it.isOutputDouble()) {
32268                                while (it.hasNext()) {
32269                                        final double ix = it.aDouble;
32270                                        short ox;
32271                                        ox = (short) toLong(Math.toDegrees(ix));
32272                                        oi16data[it.oIndex] = ox;
32273                                }
32274                        } else {
32275                                while (it.hasNext()) {
32276                                        final long ix = it.aLong;
32277                                        short ox;
32278                                        ox = (short) toLong(Math.toDegrees(ix));
32279                                        oi16data[it.oIndex] = ox;
32280                                }
32281                        }
32282                        break;
32283                case Dataset.INT64:
32284                        final long[] oi64data = ((LongDataset) result).getData();
32285                        if (it.isOutputDouble()) {
32286                                while (it.hasNext()) {
32287                                        final double ix = it.aDouble;
32288                                        long ox;
32289                                        ox = toLong(Math.toDegrees(ix));
32290                                        oi64data[it.oIndex] = ox;
32291                                }
32292                        } else {
32293                                while (it.hasNext()) {
32294                                        final long ix = it.aLong;
32295                                        long ox;
32296                                        ox = toLong(Math.toDegrees(ix));
32297                                        oi64data[it.oIndex] = ox;
32298                                }
32299                        }
32300                        break;
32301                case Dataset.INT32:
32302                        final int[] oi32data = ((IntegerDataset) result).getData();
32303                        if (it.isOutputDouble()) {
32304                                while (it.hasNext()) {
32305                                        final double ix = it.aDouble;
32306                                        int ox;
32307                                        ox = (int) toLong(Math.toDegrees(ix));
32308                                        oi32data[it.oIndex] = ox;
32309                                }
32310                        } else {
32311                                while (it.hasNext()) {
32312                                        final long ix = it.aLong;
32313                                        int ox;
32314                                        ox = (int) toLong(Math.toDegrees(ix));
32315                                        oi32data[it.oIndex] = ox;
32316                                }
32317                        }
32318                        break;
32319                case Dataset.ARRAYINT8:
32320                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
32321                        if (is == 1) {
32322                                if (it.isOutputDouble()) {
32323                                        while (it.hasNext()) {
32324                                                final double ix = it.aDouble;
32325                                                byte ox;
32326                                                ox = (byte) toLong(Math.toDegrees(ix));
32327                                                oai8data[it.oIndex] = ox;
32328                                        }
32329                                } else {
32330                                        while (it.hasNext()) {
32331                                                final long ix = it.aLong;
32332                                                byte ox;
32333                                                ox = (byte) toLong(Math.toDegrees(ix));
32334                                                oai8data[it.oIndex] = ox;
32335                                        }
32336                                }
32337                        } else if (as == 1) {
32338                                if (it.isOutputDouble()) {
32339                                        while (it.hasNext()) {
32340                                                final double ix = it.aDouble;
32341                                                byte ox;
32342                                                ox = (byte) toLong(Math.toDegrees(ix));
32343                                                for (int j = 0; j < is; j++) {
32344                                                        oai8data[it.oIndex + j] = ox;
32345                                                }
32346                                        }
32347                                } else {
32348                                        while (it.hasNext()) {
32349                                                final long ix = it.aLong;
32350                                                byte ox;
32351                                                ox = (byte) toLong(Math.toDegrees(ix));
32352                                                for (int j = 0; j < is; j++) {
32353                                                        oai8data[it.oIndex + j] = ox;
32354                                                }
32355                                        }
32356                                }
32357                        } else {
32358                                if (it.isOutputDouble()) {
32359                                        while (it.hasNext()) {
32360                                                for (int j = 0; j < is; j++) {
32361                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32362                                                        byte ox;
32363                                                        ox = (byte) toLong(Math.toDegrees(ix));
32364                                                        oai8data[it.oIndex + j] = ox;
32365                                                }
32366                                        }
32367                                } else {
32368                                        while (it.hasNext()) {
32369                                                for (int j = 0; j < is; j++) {
32370                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32371                                                        byte ox;
32372                                                        ox = (byte) toLong(Math.toDegrees(ix));
32373                                                        oai8data[it.oIndex + j] = ox;
32374                                                }
32375                                        }
32376                                }
32377                        }
32378                        break;
32379                case Dataset.ARRAYINT16:
32380                        final short[] oai16data = ((CompoundShortDataset) result).getData();
32381                        if (is == 1) {
32382                                if (it.isOutputDouble()) {
32383                                        while (it.hasNext()) {
32384                                                final double ix = it.aDouble;
32385                                                short ox;
32386                                                ox = (short) toLong(Math.toDegrees(ix));
32387                                                oai16data[it.oIndex] = ox;
32388                                        }
32389                                } else {
32390                                        while (it.hasNext()) {
32391                                                final long ix = it.aLong;
32392                                                short ox;
32393                                                ox = (short) toLong(Math.toDegrees(ix));
32394                                                oai16data[it.oIndex] = ox;
32395                                        }
32396                                }
32397                        } else if (as == 1) {
32398                                if (it.isOutputDouble()) {
32399                                        while (it.hasNext()) {
32400                                                final double ix = it.aDouble;
32401                                                short ox;
32402                                                ox = (short) toLong(Math.toDegrees(ix));
32403                                                for (int j = 0; j < is; j++) {
32404                                                        oai16data[it.oIndex + j] = ox;
32405                                                }
32406                                        }
32407                                } else {
32408                                        while (it.hasNext()) {
32409                                                final long ix = it.aLong;
32410                                                short ox;
32411                                                ox = (short) toLong(Math.toDegrees(ix));
32412                                                for (int j = 0; j < is; j++) {
32413                                                        oai16data[it.oIndex + j] = ox;
32414                                                }
32415                                        }
32416                                }
32417                        } else {
32418                                if (it.isOutputDouble()) {
32419                                        while (it.hasNext()) {
32420                                                for (int j = 0; j < is; j++) {
32421                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32422                                                        short ox;
32423                                                        ox = (short) toLong(Math.toDegrees(ix));
32424                                                        oai16data[it.oIndex + j] = ox;
32425                                                }
32426                                        }
32427                                } else {
32428                                        while (it.hasNext()) {
32429                                                for (int j = 0; j < is; j++) {
32430                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32431                                                        short ox;
32432                                                        ox = (short) toLong(Math.toDegrees(ix));
32433                                                        oai16data[it.oIndex + j] = ox;
32434                                                }
32435                                        }
32436                                }
32437                        }
32438                        break;
32439                case Dataset.ARRAYINT64:
32440                        final long[] oai64data = ((CompoundLongDataset) result).getData();
32441                        if (is == 1) {
32442                                if (it.isOutputDouble()) {
32443                                        while (it.hasNext()) {
32444                                                final double ix = it.aDouble;
32445                                                long ox;
32446                                                ox = toLong(Math.toDegrees(ix));
32447                                                oai64data[it.oIndex] = ox;
32448                                        }
32449                                } else {
32450                                        while (it.hasNext()) {
32451                                                final long ix = it.aLong;
32452                                                long ox;
32453                                                ox = toLong(Math.toDegrees(ix));
32454                                                oai64data[it.oIndex] = ox;
32455                                        }
32456                                }
32457                        } else if (as == 1) {
32458                                if (it.isOutputDouble()) {
32459                                        while (it.hasNext()) {
32460                                                final double ix = it.aDouble;
32461                                                long ox;
32462                                                ox = toLong(Math.toDegrees(ix));
32463                                                for (int j = 0; j < is; j++) {
32464                                                        oai64data[it.oIndex + j] = ox;
32465                                                }
32466                                        }
32467                                } else {
32468                                        while (it.hasNext()) {
32469                                                final long ix = it.aLong;
32470                                                long ox;
32471                                                ox = toLong(Math.toDegrees(ix));
32472                                                for (int j = 0; j < is; j++) {
32473                                                        oai64data[it.oIndex + j] = ox;
32474                                                }
32475                                        }
32476                                }
32477                        } else {
32478                                if (it.isOutputDouble()) {
32479                                        while (it.hasNext()) {
32480                                                for (int j = 0; j < is; j++) {
32481                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32482                                                        long ox;
32483                                                        ox = toLong(Math.toDegrees(ix));
32484                                                        oai64data[it.oIndex + j] = ox;
32485                                                }
32486                                        }
32487                                } else {
32488                                        while (it.hasNext()) {
32489                                                for (int j = 0; j < is; j++) {
32490                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32491                                                        long ox;
32492                                                        ox = toLong(Math.toDegrees(ix));
32493                                                        oai64data[it.oIndex + j] = ox;
32494                                                }
32495                                        }
32496                                }
32497                        }
32498                        break;
32499                case Dataset.ARRAYINT32:
32500                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
32501                        if (is == 1) {
32502                                if (it.isOutputDouble()) {
32503                                        while (it.hasNext()) {
32504                                                final double ix = it.aDouble;
32505                                                int ox;
32506                                                ox = (int) toLong(Math.toDegrees(ix));
32507                                                oai32data[it.oIndex] = ox;
32508                                        }
32509                                } else {
32510                                        while (it.hasNext()) {
32511                                                final long ix = it.aLong;
32512                                                int ox;
32513                                                ox = (int) toLong(Math.toDegrees(ix));
32514                                                oai32data[it.oIndex] = ox;
32515                                        }
32516                                }
32517                        } else if (as == 1) {
32518                                if (it.isOutputDouble()) {
32519                                        while (it.hasNext()) {
32520                                                final double ix = it.aDouble;
32521                                                int ox;
32522                                                ox = (int) toLong(Math.toDegrees(ix));
32523                                                for (int j = 0; j < is; j++) {
32524                                                        oai32data[it.oIndex + j] = ox;
32525                                                }
32526                                        }
32527                                } else {
32528                                        while (it.hasNext()) {
32529                                                final long ix = it.aLong;
32530                                                int ox;
32531                                                ox = (int) toLong(Math.toDegrees(ix));
32532                                                for (int j = 0; j < is; j++) {
32533                                                        oai32data[it.oIndex + j] = ox;
32534                                                }
32535                                        }
32536                                }
32537                        } else {
32538                                if (it.isOutputDouble()) {
32539                                        while (it.hasNext()) {
32540                                                for (int j = 0; j < is; j++) {
32541                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32542                                                        int ox;
32543                                                        ox = (int) toLong(Math.toDegrees(ix));
32544                                                        oai32data[it.oIndex + j] = ox;
32545                                                }
32546                                        }
32547                                } else {
32548                                        while (it.hasNext()) {
32549                                                for (int j = 0; j < is; j++) {
32550                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32551                                                        int ox;
32552                                                        ox = (int) toLong(Math.toDegrees(ix));
32553                                                        oai32data[it.oIndex + j] = ox;
32554                                                }
32555                                        }
32556                                }
32557                        }
32558                        break;
32559                case Dataset.FLOAT32:
32560                        final float[] of32data = ((FloatDataset) result).getData();
32561                        if (it.isOutputDouble()) {
32562                                while (it.hasNext()) {
32563                                        final double ix = it.aDouble;
32564                                        float ox;
32565                                        ox = (float) (Math.toDegrees(ix));
32566                                        of32data[it.oIndex] = ox;
32567                                }
32568                        } else {
32569                                while (it.hasNext()) {
32570                                        final long ix = it.aLong;
32571                                        float ox;
32572                                        ox = (float) (Math.toDegrees(ix));
32573                                        of32data[it.oIndex] = ox;
32574                                }
32575                        }
32576                        break;
32577                case Dataset.FLOAT64:
32578                        final double[] of64data = ((DoubleDataset) result).getData();
32579                        if (it.isOutputDouble()) {
32580                                while (it.hasNext()) {
32581                                        final double ix = it.aDouble;
32582                                        double ox;
32583                                        ox = (Math.toDegrees(ix));
32584                                        of64data[it.oIndex] = ox;
32585                                }
32586                        } else {
32587                                while (it.hasNext()) {
32588                                        final long ix = it.aLong;
32589                                        double ox;
32590                                        ox = (Math.toDegrees(ix));
32591                                        of64data[it.oIndex] = ox;
32592                                }
32593                        }
32594                        break;
32595                case Dataset.ARRAYFLOAT32:
32596                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
32597                        if (is == 1) {
32598                                if (it.isOutputDouble()) {
32599                                        while (it.hasNext()) {
32600                                                final double ix = it.aDouble;
32601                                                float ox;
32602                                                ox = (float) (Math.toDegrees(ix));
32603                                                oaf32data[it.oIndex] = ox;
32604                                        }
32605                                } else {
32606                                        while (it.hasNext()) {
32607                                                final long ix = it.aLong;
32608                                                float ox;
32609                                                ox = (float) (Math.toDegrees(ix));
32610                                                oaf32data[it.oIndex] = ox;
32611                                        }
32612                                }
32613                        } else if (as == 1) {
32614                                if (it.isOutputDouble()) {
32615                                        while (it.hasNext()) {
32616                                                final double ix = it.aDouble;
32617                                                float ox;
32618                                                ox = (float) (Math.toDegrees(ix));
32619                                                for (int j = 0; j < is; j++) {
32620                                                        oaf32data[it.oIndex + j] = ox;
32621                                                }
32622                                        }
32623                                } else {
32624                                        while (it.hasNext()) {
32625                                                final long ix = it.aLong;
32626                                                float ox;
32627                                                ox = (float) (Math.toDegrees(ix));
32628                                                for (int j = 0; j < is; j++) {
32629                                                        oaf32data[it.oIndex + j] = ox;
32630                                                }
32631                                        }
32632                                }
32633                        } else {
32634                                if (it.isOutputDouble()) {
32635                                        while (it.hasNext()) {
32636                                                for (int j = 0; j < is; j++) {
32637                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32638                                                        float ox;
32639                                                        ox = (float) (Math.toDegrees(ix));
32640                                                        oaf32data[it.oIndex + j] = ox;
32641                                                }
32642                                        }
32643                                } else {
32644                                        while (it.hasNext()) {
32645                                                for (int j = 0; j < is; j++) {
32646                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32647                                                        float ox;
32648                                                        ox = (float) (Math.toDegrees(ix));
32649                                                        oaf32data[it.oIndex + j] = ox;
32650                                                }
32651                                        }
32652                                }
32653                        }
32654                        break;
32655                case Dataset.ARRAYFLOAT64:
32656                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
32657                        if (is == 1) {
32658                                if (it.isOutputDouble()) {
32659                                        while (it.hasNext()) {
32660                                                final double ix = it.aDouble;
32661                                                double ox;
32662                                                ox = (Math.toDegrees(ix));
32663                                                oaf64data[it.oIndex] = ox;
32664                                        }
32665                                } else {
32666                                        while (it.hasNext()) {
32667                                                final long ix = it.aLong;
32668                                                double ox;
32669                                                ox = (Math.toDegrees(ix));
32670                                                oaf64data[it.oIndex] = ox;
32671                                        }
32672                                }
32673                        } else if (as == 1) {
32674                                if (it.isOutputDouble()) {
32675                                        while (it.hasNext()) {
32676                                                final double ix = it.aDouble;
32677                                                double ox;
32678                                                ox = (Math.toDegrees(ix));
32679                                                for (int j = 0; j < is; j++) {
32680                                                        oaf64data[it.oIndex + j] = ox;
32681                                                }
32682                                        }
32683                                } else {
32684                                        while (it.hasNext()) {
32685                                                final long ix = it.aLong;
32686                                                double ox;
32687                                                ox = (Math.toDegrees(ix));
32688                                                for (int j = 0; j < is; j++) {
32689                                                        oaf64data[it.oIndex + j] = ox;
32690                                                }
32691                                        }
32692                                }
32693                        } else {
32694                                if (it.isOutputDouble()) {
32695                                        while (it.hasNext()) {
32696                                                for (int j = 0; j < is; j++) {
32697                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32698                                                        double ox;
32699                                                        ox = (Math.toDegrees(ix));
32700                                                        oaf64data[it.oIndex + j] = ox;
32701                                                }
32702                                        }
32703                                } else {
32704                                        while (it.hasNext()) {
32705                                                for (int j = 0; j < is; j++) {
32706                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32707                                                        double ox;
32708                                                        ox = (Math.toDegrees(ix));
32709                                                        oaf64data[it.oIndex + j] = ox;
32710                                                }
32711                                        }
32712                                }
32713                        }
32714                        break;
32715                case Dataset.COMPLEX64:
32716                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
32717                        if (!da.isComplex()) {
32718                                if (it.isOutputDouble()) {
32719                                        final double iy = 0;
32720                                        while (it.hasNext()) {
32721                                                final double ix = it.aDouble;
32722                                                float ox;
32723                                                float oy;
32724                                                ox = (float) (Math.toDegrees(ix));
32725                                                oy = (float) (Math.toDegrees(iy));
32726                                                oc64data[it.oIndex] = ox;
32727                                                oc64data[it.oIndex + 1] = oy;
32728                                        }
32729                                } else {
32730                                        final long iy = 0;
32731                                        while (it.hasNext()) {
32732                                                final long ix = it.aLong;
32733                                                float ox;
32734                                                float oy;
32735                                                ox = (float) toLong(Math.toDegrees(ix));
32736                                                oy = (float) toLong(Math.toDegrees(iy));
32737                                                oc64data[it.oIndex] = ox;
32738                                                oc64data[it.oIndex + 1] = oy;
32739                                        }
32740                                }
32741                        } else {
32742                                while (it.hasNext()) {
32743                                        final double ix = it.aDouble;
32744                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
32745                                        float ox;
32746                                        float oy;
32747                                        ox = (float) (Math.toDegrees(ix));
32748                                        oy = (float) (Math.toDegrees(iy));
32749                                        oc64data[it.oIndex] = ox;
32750                                        oc64data[it.oIndex + 1] = oy;
32751                                }
32752                        }
32753                        break;
32754                case Dataset.COMPLEX128:
32755                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
32756                        if (!da.isComplex()) {
32757                                if (it.isOutputDouble()) {
32758                                        final double iy = 0;
32759                                        while (it.hasNext()) {
32760                                                final double ix = it.aDouble;
32761                                                double ox;
32762                                                double oy;
32763                                                ox = (Math.toDegrees(ix));
32764                                                oy = (Math.toDegrees(iy));
32765                                                oc128data[it.oIndex] = ox;
32766                                                oc128data[it.oIndex + 1] = oy;
32767                                        }
32768                                } else {
32769                                        final long iy = 0;
32770                                        while (it.hasNext()) {
32771                                                final long ix = it.aLong;
32772                                                double ox;
32773                                                double oy;
32774                                                ox = (double) (Math.toDegrees(ix));
32775                                                oy = (double) (Math.toDegrees(iy));
32776                                                oc128data[it.oIndex] = ox;
32777                                                oc128data[it.oIndex + 1] = oy;
32778                                        }
32779                                }
32780                        } else {
32781                                while (it.hasNext()) {
32782                                        final double ix = it.aDouble;
32783                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
32784                                        double ox;
32785                                        double oy;
32786                                        ox = (Math.toDegrees(ix));
32787                                        oy = (Math.toDegrees(iy));
32788                                        oc128data[it.oIndex] = ox;
32789                                        oc128data[it.oIndex + 1] = oy;
32790                                }
32791                        }
32792                        break;
32793                default:
32794                        throw new IllegalArgumentException("toDegrees supports integer, compound integer, real, compound real, complex datasets only");
32795                }
32796
32797                addFunctionName(result, "toDegrees");
32798                return result;
32799        }
32800
32801        /**
32802         * toRadians - convert to radians
32803         * @param a single operand
32804         * @return dataset
32805         */
32806        public static Dataset toRadians(final Object a) {
32807                return toRadians(a, null);
32808        }
32809
32810        /**
32811         * toRadians - convert to radians
32812         * @param a single operand
32813         * @param o output can be null - in which case, a new dataset is created
32814         * @return dataset
32815         */
32816        public static Dataset toRadians(final Object a, final Dataset o) {
32817                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
32818                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
32819                final Dataset result = it.getOutput();
32820                if (!result.isComplex()) {
32821                        if (da.isComplex()) {
32822                                da = da.getRealView();
32823                                it = new SingleInputBroadcastIterator(da, result, true);
32824                        }
32825                }
32826                final int is = result.getElementsPerItem();
32827                final int as = da.getElementsPerItem();
32828                final int dt = result.getDType();
32829
32830                switch(dt) {
32831                case Dataset.INT8:
32832                        final byte[] oi8data = ((ByteDataset) result).getData();
32833                        if (it.isOutputDouble()) {
32834                                while (it.hasNext()) {
32835                                        final double ix = it.aDouble;
32836                                        byte ox;
32837                                        ox = (byte) toLong(Math.toRadians(ix));
32838                                        oi8data[it.oIndex] = ox;
32839                                }
32840                        } else {
32841                                while (it.hasNext()) {
32842                                        final long ix = it.aLong;
32843                                        byte ox;
32844                                        ox = (byte) toLong(Math.toRadians(ix));
32845                                        oi8data[it.oIndex] = ox;
32846                                }
32847                        }
32848                        break;
32849                case Dataset.INT16:
32850                        final short[] oi16data = ((ShortDataset) result).getData();
32851                        if (it.isOutputDouble()) {
32852                                while (it.hasNext()) {
32853                                        final double ix = it.aDouble;
32854                                        short ox;
32855                                        ox = (short) toLong(Math.toRadians(ix));
32856                                        oi16data[it.oIndex] = ox;
32857                                }
32858                        } else {
32859                                while (it.hasNext()) {
32860                                        final long ix = it.aLong;
32861                                        short ox;
32862                                        ox = (short) toLong(Math.toRadians(ix));
32863                                        oi16data[it.oIndex] = ox;
32864                                }
32865                        }
32866                        break;
32867                case Dataset.INT64:
32868                        final long[] oi64data = ((LongDataset) result).getData();
32869                        if (it.isOutputDouble()) {
32870                                while (it.hasNext()) {
32871                                        final double ix = it.aDouble;
32872                                        long ox;
32873                                        ox = toLong(Math.toRadians(ix));
32874                                        oi64data[it.oIndex] = ox;
32875                                }
32876                        } else {
32877                                while (it.hasNext()) {
32878                                        final long ix = it.aLong;
32879                                        long ox;
32880                                        ox = toLong(Math.toRadians(ix));
32881                                        oi64data[it.oIndex] = ox;
32882                                }
32883                        }
32884                        break;
32885                case Dataset.INT32:
32886                        final int[] oi32data = ((IntegerDataset) result).getData();
32887                        if (it.isOutputDouble()) {
32888                                while (it.hasNext()) {
32889                                        final double ix = it.aDouble;
32890                                        int ox;
32891                                        ox = (int) toLong(Math.toRadians(ix));
32892                                        oi32data[it.oIndex] = ox;
32893                                }
32894                        } else {
32895                                while (it.hasNext()) {
32896                                        final long ix = it.aLong;
32897                                        int ox;
32898                                        ox = (int) toLong(Math.toRadians(ix));
32899                                        oi32data[it.oIndex] = ox;
32900                                }
32901                        }
32902                        break;
32903                case Dataset.ARRAYINT8:
32904                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
32905                        if (is == 1) {
32906                                if (it.isOutputDouble()) {
32907                                        while (it.hasNext()) {
32908                                                final double ix = it.aDouble;
32909                                                byte ox;
32910                                                ox = (byte) toLong(Math.toRadians(ix));
32911                                                oai8data[it.oIndex] = ox;
32912                                        }
32913                                } else {
32914                                        while (it.hasNext()) {
32915                                                final long ix = it.aLong;
32916                                                byte ox;
32917                                                ox = (byte) toLong(Math.toRadians(ix));
32918                                                oai8data[it.oIndex] = ox;
32919                                        }
32920                                }
32921                        } else if (as == 1) {
32922                                if (it.isOutputDouble()) {
32923                                        while (it.hasNext()) {
32924                                                final double ix = it.aDouble;
32925                                                byte ox;
32926                                                ox = (byte) toLong(Math.toRadians(ix));
32927                                                for (int j = 0; j < is; j++) {
32928                                                        oai8data[it.oIndex + j] = ox;
32929                                                }
32930                                        }
32931                                } else {
32932                                        while (it.hasNext()) {
32933                                                final long ix = it.aLong;
32934                                                byte ox;
32935                                                ox = (byte) toLong(Math.toRadians(ix));
32936                                                for (int j = 0; j < is; j++) {
32937                                                        oai8data[it.oIndex + j] = ox;
32938                                                }
32939                                        }
32940                                }
32941                        } else {
32942                                if (it.isOutputDouble()) {
32943                                        while (it.hasNext()) {
32944                                                for (int j = 0; j < is; j++) {
32945                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
32946                                                        byte ox;
32947                                                        ox = (byte) toLong(Math.toRadians(ix));
32948                                                        oai8data[it.oIndex + j] = ox;
32949                                                }
32950                                        }
32951                                } else {
32952                                        while (it.hasNext()) {
32953                                                for (int j = 0; j < is; j++) {
32954                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
32955                                                        byte ox;
32956                                                        ox = (byte) toLong(Math.toRadians(ix));
32957                                                        oai8data[it.oIndex + j] = ox;
32958                                                }
32959                                        }
32960                                }
32961                        }
32962                        break;
32963                case Dataset.ARRAYINT16:
32964                        final short[] oai16data = ((CompoundShortDataset) result).getData();
32965                        if (is == 1) {
32966                                if (it.isOutputDouble()) {
32967                                        while (it.hasNext()) {
32968                                                final double ix = it.aDouble;
32969                                                short ox;
32970                                                ox = (short) toLong(Math.toRadians(ix));
32971                                                oai16data[it.oIndex] = ox;
32972                                        }
32973                                } else {
32974                                        while (it.hasNext()) {
32975                                                final long ix = it.aLong;
32976                                                short ox;
32977                                                ox = (short) toLong(Math.toRadians(ix));
32978                                                oai16data[it.oIndex] = ox;
32979                                        }
32980                                }
32981                        } else if (as == 1) {
32982                                if (it.isOutputDouble()) {
32983                                        while (it.hasNext()) {
32984                                                final double ix = it.aDouble;
32985                                                short ox;
32986                                                ox = (short) toLong(Math.toRadians(ix));
32987                                                for (int j = 0; j < is; j++) {
32988                                                        oai16data[it.oIndex + j] = ox;
32989                                                }
32990                                        }
32991                                } else {
32992                                        while (it.hasNext()) {
32993                                                final long ix = it.aLong;
32994                                                short ox;
32995                                                ox = (short) toLong(Math.toRadians(ix));
32996                                                for (int j = 0; j < is; j++) {
32997                                                        oai16data[it.oIndex + j] = ox;
32998                                                }
32999                                        }
33000                                }
33001                        } else {
33002                                if (it.isOutputDouble()) {
33003                                        while (it.hasNext()) {
33004                                                for (int j = 0; j < is; j++) {
33005                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33006                                                        short ox;
33007                                                        ox = (short) toLong(Math.toRadians(ix));
33008                                                        oai16data[it.oIndex + j] = ox;
33009                                                }
33010                                        }
33011                                } else {
33012                                        while (it.hasNext()) {
33013                                                for (int j = 0; j < is; j++) {
33014                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33015                                                        short ox;
33016                                                        ox = (short) toLong(Math.toRadians(ix));
33017                                                        oai16data[it.oIndex + j] = ox;
33018                                                }
33019                                        }
33020                                }
33021                        }
33022                        break;
33023                case Dataset.ARRAYINT64:
33024                        final long[] oai64data = ((CompoundLongDataset) result).getData();
33025                        if (is == 1) {
33026                                if (it.isOutputDouble()) {
33027                                        while (it.hasNext()) {
33028                                                final double ix = it.aDouble;
33029                                                long ox;
33030                                                ox = toLong(Math.toRadians(ix));
33031                                                oai64data[it.oIndex] = ox;
33032                                        }
33033                                } else {
33034                                        while (it.hasNext()) {
33035                                                final long ix = it.aLong;
33036                                                long ox;
33037                                                ox = toLong(Math.toRadians(ix));
33038                                                oai64data[it.oIndex] = ox;
33039                                        }
33040                                }
33041                        } else if (as == 1) {
33042                                if (it.isOutputDouble()) {
33043                                        while (it.hasNext()) {
33044                                                final double ix = it.aDouble;
33045                                                long ox;
33046                                                ox = toLong(Math.toRadians(ix));
33047                                                for (int j = 0; j < is; j++) {
33048                                                        oai64data[it.oIndex + j] = ox;
33049                                                }
33050                                        }
33051                                } else {
33052                                        while (it.hasNext()) {
33053                                                final long ix = it.aLong;
33054                                                long ox;
33055                                                ox = toLong(Math.toRadians(ix));
33056                                                for (int j = 0; j < is; j++) {
33057                                                        oai64data[it.oIndex + j] = ox;
33058                                                }
33059                                        }
33060                                }
33061                        } else {
33062                                if (it.isOutputDouble()) {
33063                                        while (it.hasNext()) {
33064                                                for (int j = 0; j < is; j++) {
33065                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33066                                                        long ox;
33067                                                        ox = toLong(Math.toRadians(ix));
33068                                                        oai64data[it.oIndex + j] = ox;
33069                                                }
33070                                        }
33071                                } else {
33072                                        while (it.hasNext()) {
33073                                                for (int j = 0; j < is; j++) {
33074                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33075                                                        long ox;
33076                                                        ox = toLong(Math.toRadians(ix));
33077                                                        oai64data[it.oIndex + j] = ox;
33078                                                }
33079                                        }
33080                                }
33081                        }
33082                        break;
33083                case Dataset.ARRAYINT32:
33084                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
33085                        if (is == 1) {
33086                                if (it.isOutputDouble()) {
33087                                        while (it.hasNext()) {
33088                                                final double ix = it.aDouble;
33089                                                int ox;
33090                                                ox = (int) toLong(Math.toRadians(ix));
33091                                                oai32data[it.oIndex] = ox;
33092                                        }
33093                                } else {
33094                                        while (it.hasNext()) {
33095                                                final long ix = it.aLong;
33096                                                int ox;
33097                                                ox = (int) toLong(Math.toRadians(ix));
33098                                                oai32data[it.oIndex] = ox;
33099                                        }
33100                                }
33101                        } else if (as == 1) {
33102                                if (it.isOutputDouble()) {
33103                                        while (it.hasNext()) {
33104                                                final double ix = it.aDouble;
33105                                                int ox;
33106                                                ox = (int) toLong(Math.toRadians(ix));
33107                                                for (int j = 0; j < is; j++) {
33108                                                        oai32data[it.oIndex + j] = ox;
33109                                                }
33110                                        }
33111                                } else {
33112                                        while (it.hasNext()) {
33113                                                final long ix = it.aLong;
33114                                                int ox;
33115                                                ox = (int) toLong(Math.toRadians(ix));
33116                                                for (int j = 0; j < is; j++) {
33117                                                        oai32data[it.oIndex + j] = ox;
33118                                                }
33119                                        }
33120                                }
33121                        } else {
33122                                if (it.isOutputDouble()) {
33123                                        while (it.hasNext()) {
33124                                                for (int j = 0; j < is; j++) {
33125                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33126                                                        int ox;
33127                                                        ox = (int) toLong(Math.toRadians(ix));
33128                                                        oai32data[it.oIndex + j] = ox;
33129                                                }
33130                                        }
33131                                } else {
33132                                        while (it.hasNext()) {
33133                                                for (int j = 0; j < is; j++) {
33134                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33135                                                        int ox;
33136                                                        ox = (int) toLong(Math.toRadians(ix));
33137                                                        oai32data[it.oIndex + j] = ox;
33138                                                }
33139                                        }
33140                                }
33141                        }
33142                        break;
33143                case Dataset.FLOAT32:
33144                        final float[] of32data = ((FloatDataset) result).getData();
33145                        if (it.isOutputDouble()) {
33146                                while (it.hasNext()) {
33147                                        final double ix = it.aDouble;
33148                                        float ox;
33149                                        ox = (float) (Math.toRadians(ix));
33150                                        of32data[it.oIndex] = ox;
33151                                }
33152                        } else {
33153                                while (it.hasNext()) {
33154                                        final long ix = it.aLong;
33155                                        float ox;
33156                                        ox = (float) (Math.toRadians(ix));
33157                                        of32data[it.oIndex] = ox;
33158                                }
33159                        }
33160                        break;
33161                case Dataset.FLOAT64:
33162                        final double[] of64data = ((DoubleDataset) result).getData();
33163                        if (it.isOutputDouble()) {
33164                                while (it.hasNext()) {
33165                                        final double ix = it.aDouble;
33166                                        double ox;
33167                                        ox = (Math.toRadians(ix));
33168                                        of64data[it.oIndex] = ox;
33169                                }
33170                        } else {
33171                                while (it.hasNext()) {
33172                                        final long ix = it.aLong;
33173                                        double ox;
33174                                        ox = (Math.toRadians(ix));
33175                                        of64data[it.oIndex] = ox;
33176                                }
33177                        }
33178                        break;
33179                case Dataset.ARRAYFLOAT32:
33180                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
33181                        if (is == 1) {
33182                                if (it.isOutputDouble()) {
33183                                        while (it.hasNext()) {
33184                                                final double ix = it.aDouble;
33185                                                float ox;
33186                                                ox = (float) (Math.toRadians(ix));
33187                                                oaf32data[it.oIndex] = ox;
33188                                        }
33189                                } else {
33190                                        while (it.hasNext()) {
33191                                                final long ix = it.aLong;
33192                                                float ox;
33193                                                ox = (float) (Math.toRadians(ix));
33194                                                oaf32data[it.oIndex] = ox;
33195                                        }
33196                                }
33197                        } else if (as == 1) {
33198                                if (it.isOutputDouble()) {
33199                                        while (it.hasNext()) {
33200                                                final double ix = it.aDouble;
33201                                                float ox;
33202                                                ox = (float) (Math.toRadians(ix));
33203                                                for (int j = 0; j < is; j++) {
33204                                                        oaf32data[it.oIndex + j] = ox;
33205                                                }
33206                                        }
33207                                } else {
33208                                        while (it.hasNext()) {
33209                                                final long ix = it.aLong;
33210                                                float ox;
33211                                                ox = (float) (Math.toRadians(ix));
33212                                                for (int j = 0; j < is; j++) {
33213                                                        oaf32data[it.oIndex + j] = ox;
33214                                                }
33215                                        }
33216                                }
33217                        } else {
33218                                if (it.isOutputDouble()) {
33219                                        while (it.hasNext()) {
33220                                                for (int j = 0; j < is; j++) {
33221                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33222                                                        float ox;
33223                                                        ox = (float) (Math.toRadians(ix));
33224                                                        oaf32data[it.oIndex + j] = ox;
33225                                                }
33226                                        }
33227                                } else {
33228                                        while (it.hasNext()) {
33229                                                for (int j = 0; j < is; j++) {
33230                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33231                                                        float ox;
33232                                                        ox = (float) (Math.toRadians(ix));
33233                                                        oaf32data[it.oIndex + j] = ox;
33234                                                }
33235                                        }
33236                                }
33237                        }
33238                        break;
33239                case Dataset.ARRAYFLOAT64:
33240                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
33241                        if (is == 1) {
33242                                if (it.isOutputDouble()) {
33243                                        while (it.hasNext()) {
33244                                                final double ix = it.aDouble;
33245                                                double ox;
33246                                                ox = (Math.toRadians(ix));
33247                                                oaf64data[it.oIndex] = ox;
33248                                        }
33249                                } else {
33250                                        while (it.hasNext()) {
33251                                                final long ix = it.aLong;
33252                                                double ox;
33253                                                ox = (Math.toRadians(ix));
33254                                                oaf64data[it.oIndex] = ox;
33255                                        }
33256                                }
33257                        } else if (as == 1) {
33258                                if (it.isOutputDouble()) {
33259                                        while (it.hasNext()) {
33260                                                final double ix = it.aDouble;
33261                                                double ox;
33262                                                ox = (Math.toRadians(ix));
33263                                                for (int j = 0; j < is; j++) {
33264                                                        oaf64data[it.oIndex + j] = ox;
33265                                                }
33266                                        }
33267                                } else {
33268                                        while (it.hasNext()) {
33269                                                final long ix = it.aLong;
33270                                                double ox;
33271                                                ox = (Math.toRadians(ix));
33272                                                for (int j = 0; j < is; j++) {
33273                                                        oaf64data[it.oIndex + j] = ox;
33274                                                }
33275                                        }
33276                                }
33277                        } else {
33278                                if (it.isOutputDouble()) {
33279                                        while (it.hasNext()) {
33280                                                for (int j = 0; j < is; j++) {
33281                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33282                                                        double ox;
33283                                                        ox = (Math.toRadians(ix));
33284                                                        oaf64data[it.oIndex + j] = ox;
33285                                                }
33286                                        }
33287                                } else {
33288                                        while (it.hasNext()) {
33289                                                for (int j = 0; j < is; j++) {
33290                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33291                                                        double ox;
33292                                                        ox = (Math.toRadians(ix));
33293                                                        oaf64data[it.oIndex + j] = ox;
33294                                                }
33295                                        }
33296                                }
33297                        }
33298                        break;
33299                case Dataset.COMPLEX64:
33300                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
33301                        if (!da.isComplex()) {
33302                                if (it.isOutputDouble()) {
33303                                        final double iy = 0;
33304                                        while (it.hasNext()) {
33305                                                final double ix = it.aDouble;
33306                                                float ox;
33307                                                float oy;
33308                                                ox = (float) (Math.toRadians(ix));
33309                                                oy = (float) (Math.toRadians(iy));
33310                                                oc64data[it.oIndex] = ox;
33311                                                oc64data[it.oIndex + 1] = oy;
33312                                        }
33313                                } else {
33314                                        final long iy = 0;
33315                                        while (it.hasNext()) {
33316                                                final long ix = it.aLong;
33317                                                float ox;
33318                                                float oy;
33319                                                ox = (float) toLong(Math.toRadians(ix));
33320                                                oy = (float) toLong(Math.toRadians(iy));
33321                                                oc64data[it.oIndex] = ox;
33322                                                oc64data[it.oIndex + 1] = oy;
33323                                        }
33324                                }
33325                        } else {
33326                                while (it.hasNext()) {
33327                                        final double ix = it.aDouble;
33328                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
33329                                        float ox;
33330                                        float oy;
33331                                        ox = (float) (Math.toRadians(ix));
33332                                        oy = (float) (Math.toRadians(iy));
33333                                        oc64data[it.oIndex] = ox;
33334                                        oc64data[it.oIndex + 1] = oy;
33335                                }
33336                        }
33337                        break;
33338                case Dataset.COMPLEX128:
33339                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
33340                        if (!da.isComplex()) {
33341                                if (it.isOutputDouble()) {
33342                                        final double iy = 0;
33343                                        while (it.hasNext()) {
33344                                                final double ix = it.aDouble;
33345                                                double ox;
33346                                                double oy;
33347                                                ox = (Math.toRadians(ix));
33348                                                oy = (Math.toRadians(iy));
33349                                                oc128data[it.oIndex] = ox;
33350                                                oc128data[it.oIndex + 1] = oy;
33351                                        }
33352                                } else {
33353                                        final long iy = 0;
33354                                        while (it.hasNext()) {
33355                                                final long ix = it.aLong;
33356                                                double ox;
33357                                                double oy;
33358                                                ox = (double) (Math.toRadians(ix));
33359                                                oy = (double) (Math.toRadians(iy));
33360                                                oc128data[it.oIndex] = ox;
33361                                                oc128data[it.oIndex + 1] = oy;
33362                                        }
33363                                }
33364                        } else {
33365                                while (it.hasNext()) {
33366                                        final double ix = it.aDouble;
33367                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
33368                                        double ox;
33369                                        double oy;
33370                                        ox = (Math.toRadians(ix));
33371                                        oy = (Math.toRadians(iy));
33372                                        oc128data[it.oIndex] = ox;
33373                                        oc128data[it.oIndex + 1] = oy;
33374                                }
33375                        }
33376                        break;
33377                default:
33378                        throw new IllegalArgumentException("toRadians supports integer, compound integer, real, compound real, complex datasets only");
33379                }
33380
33381                addFunctionName(result, "toRadians");
33382                return result;
33383        }
33384
33385        /**
33386         * signum - sign of each element
33387         * @param a single operand
33388         * @return dataset
33389         */
33390        public static Dataset signum(final Object a) {
33391                return signum(a, null);
33392        }
33393
33394        /**
33395         * signum - sign of each element
33396         * @param a single operand
33397         * @param o output can be null - in which case, a new dataset is created
33398         * @return dataset
33399         */
33400        public static Dataset signum(final Object a, final Dataset o) {
33401                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
33402                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
33403                final Dataset result = it.getOutput();
33404                if (!result.isComplex()) {
33405                        if (da.isComplex()) {
33406                                da = da.getRealView();
33407                                it = new SingleInputBroadcastIterator(da, result, true);
33408                        }
33409                }
33410                final int is = result.getElementsPerItem();
33411                final int as = da.getElementsPerItem();
33412                final int dt = result.getDType();
33413
33414                switch(dt) {
33415                case Dataset.INT8:
33416                        final byte[] oi8data = ((ByteDataset) result).getData();
33417                        if (it.isOutputDouble()) {
33418                                while (it.hasNext()) {
33419                                        final double ix = it.aDouble;
33420                                        byte ox;
33421                                        ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33422                                        oi8data[it.oIndex] = ox;
33423                                }
33424                        } else {
33425                                while (it.hasNext()) {
33426                                        final long ix = it.aLong;
33427                                        byte ox;
33428                                        ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33429                                        oi8data[it.oIndex] = ox;
33430                                }
33431                        }
33432                        break;
33433                case Dataset.INT16:
33434                        final short[] oi16data = ((ShortDataset) result).getData();
33435                        if (it.isOutputDouble()) {
33436                                while (it.hasNext()) {
33437                                        final double ix = it.aDouble;
33438                                        short ox;
33439                                        ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33440                                        oi16data[it.oIndex] = ox;
33441                                }
33442                        } else {
33443                                while (it.hasNext()) {
33444                                        final long ix = it.aLong;
33445                                        short ox;
33446                                        ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33447                                        oi16data[it.oIndex] = ox;
33448                                }
33449                        }
33450                        break;
33451                case Dataset.INT64:
33452                        final long[] oi64data = ((LongDataset) result).getData();
33453                        if (it.isOutputDouble()) {
33454                                while (it.hasNext()) {
33455                                        final double ix = it.aDouble;
33456                                        long ox;
33457                                        ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33458                                        oi64data[it.oIndex] = ox;
33459                                }
33460                        } else {
33461                                while (it.hasNext()) {
33462                                        final long ix = it.aLong;
33463                                        long ox;
33464                                        ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33465                                        oi64data[it.oIndex] = ox;
33466                                }
33467                        }
33468                        break;
33469                case Dataset.INT32:
33470                        final int[] oi32data = ((IntegerDataset) result).getData();
33471                        if (it.isOutputDouble()) {
33472                                while (it.hasNext()) {
33473                                        final double ix = it.aDouble;
33474                                        int ox;
33475                                        ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33476                                        oi32data[it.oIndex] = ox;
33477                                }
33478                        } else {
33479                                while (it.hasNext()) {
33480                                        final long ix = it.aLong;
33481                                        int ox;
33482                                        ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33483                                        oi32data[it.oIndex] = ox;
33484                                }
33485                        }
33486                        break;
33487                case Dataset.ARRAYINT8:
33488                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
33489                        if (is == 1) {
33490                                if (it.isOutputDouble()) {
33491                                        while (it.hasNext()) {
33492                                                final double ix = it.aDouble;
33493                                                byte ox;
33494                                                ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33495                                                oai8data[it.oIndex] = ox;
33496                                        }
33497                                } else {
33498                                        while (it.hasNext()) {
33499                                                final long ix = it.aLong;
33500                                                byte ox;
33501                                                ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33502                                                oai8data[it.oIndex] = ox;
33503                                        }
33504                                }
33505                        } else if (as == 1) {
33506                                if (it.isOutputDouble()) {
33507                                        while (it.hasNext()) {
33508                                                final double ix = it.aDouble;
33509                                                byte ox;
33510                                                ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33511                                                for (int j = 0; j < is; j++) {
33512                                                        oai8data[it.oIndex + j] = ox;
33513                                                }
33514                                        }
33515                                } else {
33516                                        while (it.hasNext()) {
33517                                                final long ix = it.aLong;
33518                                                byte ox;
33519                                                ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33520                                                for (int j = 0; j < is; j++) {
33521                                                        oai8data[it.oIndex + j] = ox;
33522                                                }
33523                                        }
33524                                }
33525                        } else {
33526                                if (it.isOutputDouble()) {
33527                                        while (it.hasNext()) {
33528                                                for (int j = 0; j < is; j++) {
33529                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33530                                                        byte ox;
33531                                                        ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33532                                                        oai8data[it.oIndex + j] = ox;
33533                                                }
33534                                        }
33535                                } else {
33536                                        while (it.hasNext()) {
33537                                                for (int j = 0; j < is; j++) {
33538                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33539                                                        byte ox;
33540                                                        ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33541                                                        oai8data[it.oIndex + j] = ox;
33542                                                }
33543                                        }
33544                                }
33545                        }
33546                        break;
33547                case Dataset.ARRAYINT16:
33548                        final short[] oai16data = ((CompoundShortDataset) result).getData();
33549                        if (is == 1) {
33550                                if (it.isOutputDouble()) {
33551                                        while (it.hasNext()) {
33552                                                final double ix = it.aDouble;
33553                                                short ox;
33554                                                ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33555                                                oai16data[it.oIndex] = ox;
33556                                        }
33557                                } else {
33558                                        while (it.hasNext()) {
33559                                                final long ix = it.aLong;
33560                                                short ox;
33561                                                ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33562                                                oai16data[it.oIndex] = ox;
33563                                        }
33564                                }
33565                        } else if (as == 1) {
33566                                if (it.isOutputDouble()) {
33567                                        while (it.hasNext()) {
33568                                                final double ix = it.aDouble;
33569                                                short ox;
33570                                                ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33571                                                for (int j = 0; j < is; j++) {
33572                                                        oai16data[it.oIndex + j] = ox;
33573                                                }
33574                                        }
33575                                } else {
33576                                        while (it.hasNext()) {
33577                                                final long ix = it.aLong;
33578                                                short ox;
33579                                                ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33580                                                for (int j = 0; j < is; j++) {
33581                                                        oai16data[it.oIndex + j] = ox;
33582                                                }
33583                                        }
33584                                }
33585                        } else {
33586                                if (it.isOutputDouble()) {
33587                                        while (it.hasNext()) {
33588                                                for (int j = 0; j < is; j++) {
33589                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33590                                                        short ox;
33591                                                        ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33592                                                        oai16data[it.oIndex + j] = ox;
33593                                                }
33594                                        }
33595                                } else {
33596                                        while (it.hasNext()) {
33597                                                for (int j = 0; j < is; j++) {
33598                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33599                                                        short ox;
33600                                                        ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33601                                                        oai16data[it.oIndex + j] = ox;
33602                                                }
33603                                        }
33604                                }
33605                        }
33606                        break;
33607                case Dataset.ARRAYINT64:
33608                        final long[] oai64data = ((CompoundLongDataset) result).getData();
33609                        if (is == 1) {
33610                                if (it.isOutputDouble()) {
33611                                        while (it.hasNext()) {
33612                                                final double ix = it.aDouble;
33613                                                long ox;
33614                                                ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33615                                                oai64data[it.oIndex] = ox;
33616                                        }
33617                                } else {
33618                                        while (it.hasNext()) {
33619                                                final long ix = it.aLong;
33620                                                long ox;
33621                                                ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33622                                                oai64data[it.oIndex] = ox;
33623                                        }
33624                                }
33625                        } else if (as == 1) {
33626                                if (it.isOutputDouble()) {
33627                                        while (it.hasNext()) {
33628                                                final double ix = it.aDouble;
33629                                                long ox;
33630                                                ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33631                                                for (int j = 0; j < is; j++) {
33632                                                        oai64data[it.oIndex + j] = ox;
33633                                                }
33634                                        }
33635                                } else {
33636                                        while (it.hasNext()) {
33637                                                final long ix = it.aLong;
33638                                                long ox;
33639                                                ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33640                                                for (int j = 0; j < is; j++) {
33641                                                        oai64data[it.oIndex + j] = ox;
33642                                                }
33643                                        }
33644                                }
33645                        } else {
33646                                if (it.isOutputDouble()) {
33647                                        while (it.hasNext()) {
33648                                                for (int j = 0; j < is; j++) {
33649                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33650                                                        long ox;
33651                                                        ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33652                                                        oai64data[it.oIndex + j] = ox;
33653                                                }
33654                                        }
33655                                } else {
33656                                        while (it.hasNext()) {
33657                                                for (int j = 0; j < is; j++) {
33658                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33659                                                        long ox;
33660                                                        ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33661                                                        oai64data[it.oIndex + j] = ox;
33662                                                }
33663                                        }
33664                                }
33665                        }
33666                        break;
33667                case Dataset.ARRAYINT32:
33668                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
33669                        if (is == 1) {
33670                                if (it.isOutputDouble()) {
33671                                        while (it.hasNext()) {
33672                                                final double ix = it.aDouble;
33673                                                int ox;
33674                                                ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33675                                                oai32data[it.oIndex] = ox;
33676                                        }
33677                                } else {
33678                                        while (it.hasNext()) {
33679                                                final long ix = it.aLong;
33680                                                int ox;
33681                                                ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33682                                                oai32data[it.oIndex] = ox;
33683                                        }
33684                                }
33685                        } else if (as == 1) {
33686                                if (it.isOutputDouble()) {
33687                                        while (it.hasNext()) {
33688                                                final double ix = it.aDouble;
33689                                                int ox;
33690                                                ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33691                                                for (int j = 0; j < is; j++) {
33692                                                        oai32data[it.oIndex + j] = ox;
33693                                                }
33694                                        }
33695                                } else {
33696                                        while (it.hasNext()) {
33697                                                final long ix = it.aLong;
33698                                                int ox;
33699                                                ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33700                                                for (int j = 0; j < is; j++) {
33701                                                        oai32data[it.oIndex + j] = ox;
33702                                                }
33703                                        }
33704                                }
33705                        } else {
33706                                if (it.isOutputDouble()) {
33707                                        while (it.hasNext()) {
33708                                                for (int j = 0; j < is; j++) {
33709                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33710                                                        int ox;
33711                                                        ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33712                                                        oai32data[it.oIndex + j] = ox;
33713                                                }
33714                                        }
33715                                } else {
33716                                        while (it.hasNext()) {
33717                                                for (int j = 0; j < is; j++) {
33718                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33719                                                        int ox;
33720                                                        ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
33721                                                        oai32data[it.oIndex + j] = ox;
33722                                                }
33723                                        }
33724                                }
33725                        }
33726                        break;
33727                case Dataset.FLOAT32:
33728                        final float[] of32data = ((FloatDataset) result).getData();
33729                        if (it.isOutputDouble()) {
33730                                while (it.hasNext()) {
33731                                        final double ix = it.aDouble;
33732                                        float ox;
33733                                        ox = (float) (Math.signum(ix));
33734                                        of32data[it.oIndex] = ox;
33735                                }
33736                        } else {
33737                                while (it.hasNext()) {
33738                                        final long ix = it.aLong;
33739                                        float ox;
33740                                        ox = (float) (Math.signum(ix));
33741                                        of32data[it.oIndex] = ox;
33742                                }
33743                        }
33744                        break;
33745                case Dataset.FLOAT64:
33746                        final double[] of64data = ((DoubleDataset) result).getData();
33747                        if (it.isOutputDouble()) {
33748                                while (it.hasNext()) {
33749                                        final double ix = it.aDouble;
33750                                        double ox;
33751                                        ox = (Math.signum(ix));
33752                                        of64data[it.oIndex] = ox;
33753                                }
33754                        } else {
33755                                while (it.hasNext()) {
33756                                        final long ix = it.aLong;
33757                                        double ox;
33758                                        ox = (Math.signum(ix));
33759                                        of64data[it.oIndex] = ox;
33760                                }
33761                        }
33762                        break;
33763                case Dataset.ARRAYFLOAT32:
33764                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
33765                        if (is == 1) {
33766                                if (it.isOutputDouble()) {
33767                                        while (it.hasNext()) {
33768                                                final double ix = it.aDouble;
33769                                                float ox;
33770                                                ox = (float) (Math.signum(ix));
33771                                                oaf32data[it.oIndex] = ox;
33772                                        }
33773                                } else {
33774                                        while (it.hasNext()) {
33775                                                final long ix = it.aLong;
33776                                                float ox;
33777                                                ox = (float) (Math.signum(ix));
33778                                                oaf32data[it.oIndex] = ox;
33779                                        }
33780                                }
33781                        } else if (as == 1) {
33782                                if (it.isOutputDouble()) {
33783                                        while (it.hasNext()) {
33784                                                final double ix = it.aDouble;
33785                                                float ox;
33786                                                ox = (float) (Math.signum(ix));
33787                                                for (int j = 0; j < is; j++) {
33788                                                        oaf32data[it.oIndex + j] = ox;
33789                                                }
33790                                        }
33791                                } else {
33792                                        while (it.hasNext()) {
33793                                                final long ix = it.aLong;
33794                                                float ox;
33795                                                ox = (float) (Math.signum(ix));
33796                                                for (int j = 0; j < is; j++) {
33797                                                        oaf32data[it.oIndex + j] = ox;
33798                                                }
33799                                        }
33800                                }
33801                        } else {
33802                                if (it.isOutputDouble()) {
33803                                        while (it.hasNext()) {
33804                                                for (int j = 0; j < is; j++) {
33805                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33806                                                        float ox;
33807                                                        ox = (float) (Math.signum(ix));
33808                                                        oaf32data[it.oIndex + j] = ox;
33809                                                }
33810                                        }
33811                                } else {
33812                                        while (it.hasNext()) {
33813                                                for (int j = 0; j < is; j++) {
33814                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33815                                                        float ox;
33816                                                        ox = (float) (Math.signum(ix));
33817                                                        oaf32data[it.oIndex + j] = ox;
33818                                                }
33819                                        }
33820                                }
33821                        }
33822                        break;
33823                case Dataset.ARRAYFLOAT64:
33824                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
33825                        if (is == 1) {
33826                                if (it.isOutputDouble()) {
33827                                        while (it.hasNext()) {
33828                                                final double ix = it.aDouble;
33829                                                double ox;
33830                                                ox = (Math.signum(ix));
33831                                                oaf64data[it.oIndex] = ox;
33832                                        }
33833                                } else {
33834                                        while (it.hasNext()) {
33835                                                final long ix = it.aLong;
33836                                                double ox;
33837                                                ox = (Math.signum(ix));
33838                                                oaf64data[it.oIndex] = ox;
33839                                        }
33840                                }
33841                        } else if (as == 1) {
33842                                if (it.isOutputDouble()) {
33843                                        while (it.hasNext()) {
33844                                                final double ix = it.aDouble;
33845                                                double ox;
33846                                                ox = (Math.signum(ix));
33847                                                for (int j = 0; j < is; j++) {
33848                                                        oaf64data[it.oIndex + j] = ox;
33849                                                }
33850                                        }
33851                                } else {
33852                                        while (it.hasNext()) {
33853                                                final long ix = it.aLong;
33854                                                double ox;
33855                                                ox = (Math.signum(ix));
33856                                                for (int j = 0; j < is; j++) {
33857                                                        oaf64data[it.oIndex + j] = ox;
33858                                                }
33859                                        }
33860                                }
33861                        } else {
33862                                if (it.isOutputDouble()) {
33863                                        while (it.hasNext()) {
33864                                                for (int j = 0; j < is; j++) {
33865                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
33866                                                        double ox;
33867                                                        ox = (Math.signum(ix));
33868                                                        oaf64data[it.oIndex + j] = ox;
33869                                                }
33870                                        }
33871                                } else {
33872                                        while (it.hasNext()) {
33873                                                for (int j = 0; j < is; j++) {
33874                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
33875                                                        double ox;
33876                                                        ox = (Math.signum(ix));
33877                                                        oaf64data[it.oIndex + j] = ox;
33878                                                }
33879                                        }
33880                                }
33881                        }
33882                        break;
33883                case Dataset.COMPLEX64:
33884                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
33885                        if (!da.isComplex()) {
33886                                if (it.isOutputDouble()) {
33887                                        final double iy = 0;
33888                                        while (it.hasNext()) {
33889                                                final double ix = it.aDouble;
33890                                                float ox;
33891                                                float oy;
33892                                                ox = (float) (Math.signum(ix));
33893                                                oy = (float) (Math.signum(iy));
33894                                                oc64data[it.oIndex] = ox;
33895                                                oc64data[it.oIndex + 1] = oy;
33896                                        }
33897                                } else {
33898                                        final long iy = 0;
33899                                        while (it.hasNext()) {
33900                                                final long ix = it.aLong;
33901                                                float ox;
33902                                                float oy;
33903                                                ox = (float) toLong(Math.signum(ix));
33904                                                oy = (float) toLong(Math.signum(iy));
33905                                                oc64data[it.oIndex] = ox;
33906                                                oc64data[it.oIndex + 1] = oy;
33907                                        }
33908                                }
33909                        } else {
33910                                while (it.hasNext()) {
33911                                        final double ix = it.aDouble;
33912                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
33913                                        float ox;
33914                                        float oy;
33915                                        ox = (float) (Math.signum(ix));
33916                                        oy = (float) (Math.signum(iy));
33917                                        oc64data[it.oIndex] = ox;
33918                                        oc64data[it.oIndex + 1] = oy;
33919                                }
33920                        }
33921                        break;
33922                case Dataset.COMPLEX128:
33923                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
33924                        if (!da.isComplex()) {
33925                                if (it.isOutputDouble()) {
33926                                        final double iy = 0;
33927                                        while (it.hasNext()) {
33928                                                final double ix = it.aDouble;
33929                                                double ox;
33930                                                double oy;
33931                                                ox = (Math.signum(ix));
33932                                                oy = (Math.signum(iy));
33933                                                oc128data[it.oIndex] = ox;
33934                                                oc128data[it.oIndex + 1] = oy;
33935                                        }
33936                                } else {
33937                                        final long iy = 0;
33938                                        while (it.hasNext()) {
33939                                                final long ix = it.aLong;
33940                                                double ox;
33941                                                double oy;
33942                                                ox = (double) (Math.signum(ix));
33943                                                oy = (double) (Math.signum(iy));
33944                                                oc128data[it.oIndex] = ox;
33945                                                oc128data[it.oIndex + 1] = oy;
33946                                        }
33947                                }
33948                        } else {
33949                                while (it.hasNext()) {
33950                                        final double ix = it.aDouble;
33951                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
33952                                        double ox;
33953                                        double oy;
33954                                        ox = (Math.signum(ix));
33955                                        oy = (Math.signum(iy));
33956                                        oc128data[it.oIndex] = ox;
33957                                        oc128data[it.oIndex + 1] = oy;
33958                                }
33959                        }
33960                        break;
33961                default:
33962                        throw new IllegalArgumentException("signum supports integer, compound integer, real, compound real, complex datasets only");
33963                }
33964
33965                addFunctionName(result, "signum");
33966                return result;
33967        }
33968
33969        /**
33970         * negative - negative value of each element
33971         * @param a single operand
33972         * @return dataset
33973         */
33974        public static Dataset negative(final Object a) {
33975                return negative(a, null);
33976        }
33977
33978        /**
33979         * negative - negative value of each element
33980         * @param a single operand
33981         * @param o output can be null - in which case, a new dataset is created
33982         * @return dataset
33983         */
33984        public static Dataset negative(final Object a, final Dataset o) {
33985                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
33986                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
33987                final Dataset result = it.getOutput();
33988                if (!result.isComplex()) {
33989                        if (da.isComplex()) {
33990                                da = da.getRealView();
33991                                it = new SingleInputBroadcastIterator(da, result, true);
33992                        }
33993                }
33994                final int is = result.getElementsPerItem();
33995                final int as = da.getElementsPerItem();
33996                final int dt = result.getDType();
33997
33998                switch(dt) {
33999                case Dataset.INT8:
34000                        final byte[] oi8data = ((ByteDataset) result).getData();
34001                        if (it.isOutputDouble()) {
34002                                while (it.hasNext()) {
34003                                        final double ix = it.aDouble;
34004                                        byte ox;
34005                                        ox = (byte) toLong(-ix);
34006                                        oi8data[it.oIndex] = ox;
34007                                }
34008                        } else {
34009                                while (it.hasNext()) {
34010                                        final long ix = it.aLong;
34011                                        byte ox;
34012                                        ox = (byte) toLong(-ix);
34013                                        oi8data[it.oIndex] = ox;
34014                                }
34015                        }
34016                        break;
34017                case Dataset.INT16:
34018                        final short[] oi16data = ((ShortDataset) result).getData();
34019                        if (it.isOutputDouble()) {
34020                                while (it.hasNext()) {
34021                                        final double ix = it.aDouble;
34022                                        short ox;
34023                                        ox = (short) toLong(-ix);
34024                                        oi16data[it.oIndex] = ox;
34025                                }
34026                        } else {
34027                                while (it.hasNext()) {
34028                                        final long ix = it.aLong;
34029                                        short ox;
34030                                        ox = (short) toLong(-ix);
34031                                        oi16data[it.oIndex] = ox;
34032                                }
34033                        }
34034                        break;
34035                case Dataset.INT64:
34036                        final long[] oi64data = ((LongDataset) result).getData();
34037                        if (it.isOutputDouble()) {
34038                                while (it.hasNext()) {
34039                                        final double ix = it.aDouble;
34040                                        long ox;
34041                                        ox = toLong(-ix);
34042                                        oi64data[it.oIndex] = ox;
34043                                }
34044                        } else {
34045                                while (it.hasNext()) {
34046                                        final long ix = it.aLong;
34047                                        long ox;
34048                                        ox = toLong(-ix);
34049                                        oi64data[it.oIndex] = ox;
34050                                }
34051                        }
34052                        break;
34053                case Dataset.INT32:
34054                        final int[] oi32data = ((IntegerDataset) result).getData();
34055                        if (it.isOutputDouble()) {
34056                                while (it.hasNext()) {
34057                                        final double ix = it.aDouble;
34058                                        int ox;
34059                                        ox = (int) toLong(-ix);
34060                                        oi32data[it.oIndex] = ox;
34061                                }
34062                        } else {
34063                                while (it.hasNext()) {
34064                                        final long ix = it.aLong;
34065                                        int ox;
34066                                        ox = (int) toLong(-ix);
34067                                        oi32data[it.oIndex] = ox;
34068                                }
34069                        }
34070                        break;
34071                case Dataset.ARRAYINT8:
34072                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
34073                        if (is == 1) {
34074                                if (it.isOutputDouble()) {
34075                                        while (it.hasNext()) {
34076                                                final double ix = it.aDouble;
34077                                                byte ox;
34078                                                ox = (byte) toLong(-ix);
34079                                                oai8data[it.oIndex] = ox;
34080                                        }
34081                                } else {
34082                                        while (it.hasNext()) {
34083                                                final long ix = it.aLong;
34084                                                byte ox;
34085                                                ox = (byte) toLong(-ix);
34086                                                oai8data[it.oIndex] = ox;
34087                                        }
34088                                }
34089                        } else if (as == 1) {
34090                                if (it.isOutputDouble()) {
34091                                        while (it.hasNext()) {
34092                                                final double ix = it.aDouble;
34093                                                byte ox;
34094                                                ox = (byte) toLong(-ix);
34095                                                for (int j = 0; j < is; j++) {
34096                                                        oai8data[it.oIndex + j] = ox;
34097                                                }
34098                                        }
34099                                } else {
34100                                        while (it.hasNext()) {
34101                                                final long ix = it.aLong;
34102                                                byte ox;
34103                                                ox = (byte) toLong(-ix);
34104                                                for (int j = 0; j < is; j++) {
34105                                                        oai8data[it.oIndex + j] = ox;
34106                                                }
34107                                        }
34108                                }
34109                        } else {
34110                                if (it.isOutputDouble()) {
34111                                        while (it.hasNext()) {
34112                                                for (int j = 0; j < is; j++) {
34113                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34114                                                        byte ox;
34115                                                        ox = (byte) toLong(-ix);
34116                                                        oai8data[it.oIndex + j] = ox;
34117                                                }
34118                                        }
34119                                } else {
34120                                        while (it.hasNext()) {
34121                                                for (int j = 0; j < is; j++) {
34122                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34123                                                        byte ox;
34124                                                        ox = (byte) toLong(-ix);
34125                                                        oai8data[it.oIndex + j] = ox;
34126                                                }
34127                                        }
34128                                }
34129                        }
34130                        break;
34131                case Dataset.ARRAYINT16:
34132                        final short[] oai16data = ((CompoundShortDataset) result).getData();
34133                        if (is == 1) {
34134                                if (it.isOutputDouble()) {
34135                                        while (it.hasNext()) {
34136                                                final double ix = it.aDouble;
34137                                                short ox;
34138                                                ox = (short) toLong(-ix);
34139                                                oai16data[it.oIndex] = ox;
34140                                        }
34141                                } else {
34142                                        while (it.hasNext()) {
34143                                                final long ix = it.aLong;
34144                                                short ox;
34145                                                ox = (short) toLong(-ix);
34146                                                oai16data[it.oIndex] = ox;
34147                                        }
34148                                }
34149                        } else if (as == 1) {
34150                                if (it.isOutputDouble()) {
34151                                        while (it.hasNext()) {
34152                                                final double ix = it.aDouble;
34153                                                short ox;
34154                                                ox = (short) toLong(-ix);
34155                                                for (int j = 0; j < is; j++) {
34156                                                        oai16data[it.oIndex + j] = ox;
34157                                                }
34158                                        }
34159                                } else {
34160                                        while (it.hasNext()) {
34161                                                final long ix = it.aLong;
34162                                                short ox;
34163                                                ox = (short) toLong(-ix);
34164                                                for (int j = 0; j < is; j++) {
34165                                                        oai16data[it.oIndex + j] = ox;
34166                                                }
34167                                        }
34168                                }
34169                        } else {
34170                                if (it.isOutputDouble()) {
34171                                        while (it.hasNext()) {
34172                                                for (int j = 0; j < is; j++) {
34173                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34174                                                        short ox;
34175                                                        ox = (short) toLong(-ix);
34176                                                        oai16data[it.oIndex + j] = ox;
34177                                                }
34178                                        }
34179                                } else {
34180                                        while (it.hasNext()) {
34181                                                for (int j = 0; j < is; j++) {
34182                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34183                                                        short ox;
34184                                                        ox = (short) toLong(-ix);
34185                                                        oai16data[it.oIndex + j] = ox;
34186                                                }
34187                                        }
34188                                }
34189                        }
34190                        break;
34191                case Dataset.ARRAYINT64:
34192                        final long[] oai64data = ((CompoundLongDataset) result).getData();
34193                        if (is == 1) {
34194                                if (it.isOutputDouble()) {
34195                                        while (it.hasNext()) {
34196                                                final double ix = it.aDouble;
34197                                                long ox;
34198                                                ox = toLong(-ix);
34199                                                oai64data[it.oIndex] = ox;
34200                                        }
34201                                } else {
34202                                        while (it.hasNext()) {
34203                                                final long ix = it.aLong;
34204                                                long ox;
34205                                                ox = toLong(-ix);
34206                                                oai64data[it.oIndex] = ox;
34207                                        }
34208                                }
34209                        } else if (as == 1) {
34210                                if (it.isOutputDouble()) {
34211                                        while (it.hasNext()) {
34212                                                final double ix = it.aDouble;
34213                                                long ox;
34214                                                ox = toLong(-ix);
34215                                                for (int j = 0; j < is; j++) {
34216                                                        oai64data[it.oIndex + j] = ox;
34217                                                }
34218                                        }
34219                                } else {
34220                                        while (it.hasNext()) {
34221                                                final long ix = it.aLong;
34222                                                long ox;
34223                                                ox = toLong(-ix);
34224                                                for (int j = 0; j < is; j++) {
34225                                                        oai64data[it.oIndex + j] = ox;
34226                                                }
34227                                        }
34228                                }
34229                        } else {
34230                                if (it.isOutputDouble()) {
34231                                        while (it.hasNext()) {
34232                                                for (int j = 0; j < is; j++) {
34233                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34234                                                        long ox;
34235                                                        ox = toLong(-ix);
34236                                                        oai64data[it.oIndex + j] = ox;
34237                                                }
34238                                        }
34239                                } else {
34240                                        while (it.hasNext()) {
34241                                                for (int j = 0; j < is; j++) {
34242                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34243                                                        long ox;
34244                                                        ox = toLong(-ix);
34245                                                        oai64data[it.oIndex + j] = ox;
34246                                                }
34247                                        }
34248                                }
34249                        }
34250                        break;
34251                case Dataset.ARRAYINT32:
34252                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
34253                        if (is == 1) {
34254                                if (it.isOutputDouble()) {
34255                                        while (it.hasNext()) {
34256                                                final double ix = it.aDouble;
34257                                                int ox;
34258                                                ox = (int) toLong(-ix);
34259                                                oai32data[it.oIndex] = ox;
34260                                        }
34261                                } else {
34262                                        while (it.hasNext()) {
34263                                                final long ix = it.aLong;
34264                                                int ox;
34265                                                ox = (int) toLong(-ix);
34266                                                oai32data[it.oIndex] = ox;
34267                                        }
34268                                }
34269                        } else if (as == 1) {
34270                                if (it.isOutputDouble()) {
34271                                        while (it.hasNext()) {
34272                                                final double ix = it.aDouble;
34273                                                int ox;
34274                                                ox = (int) toLong(-ix);
34275                                                for (int j = 0; j < is; j++) {
34276                                                        oai32data[it.oIndex + j] = ox;
34277                                                }
34278                                        }
34279                                } else {
34280                                        while (it.hasNext()) {
34281                                                final long ix = it.aLong;
34282                                                int ox;
34283                                                ox = (int) toLong(-ix);
34284                                                for (int j = 0; j < is; j++) {
34285                                                        oai32data[it.oIndex + j] = ox;
34286                                                }
34287                                        }
34288                                }
34289                        } else {
34290                                if (it.isOutputDouble()) {
34291                                        while (it.hasNext()) {
34292                                                for (int j = 0; j < is; j++) {
34293                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34294                                                        int ox;
34295                                                        ox = (int) toLong(-ix);
34296                                                        oai32data[it.oIndex + j] = ox;
34297                                                }
34298                                        }
34299                                } else {
34300                                        while (it.hasNext()) {
34301                                                for (int j = 0; j < is; j++) {
34302                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34303                                                        int ox;
34304                                                        ox = (int) toLong(-ix);
34305                                                        oai32data[it.oIndex + j] = ox;
34306                                                }
34307                                        }
34308                                }
34309                        }
34310                        break;
34311                case Dataset.FLOAT32:
34312                        final float[] of32data = ((FloatDataset) result).getData();
34313                        if (it.isOutputDouble()) {
34314                                while (it.hasNext()) {
34315                                        final double ix = it.aDouble;
34316                                        float ox;
34317                                        ox = (float) (-ix);
34318                                        of32data[it.oIndex] = ox;
34319                                }
34320                        } else {
34321                                while (it.hasNext()) {
34322                                        final long ix = it.aLong;
34323                                        float ox;
34324                                        ox = (-ix);
34325                                        of32data[it.oIndex] = ox;
34326                                }
34327                        }
34328                        break;
34329                case Dataset.FLOAT64:
34330                        final double[] of64data = ((DoubleDataset) result).getData();
34331                        if (it.isOutputDouble()) {
34332                                while (it.hasNext()) {
34333                                        final double ix = it.aDouble;
34334                                        double ox;
34335                                        ox = (-ix);
34336                                        of64data[it.oIndex] = ox;
34337                                }
34338                        } else {
34339                                while (it.hasNext()) {
34340                                        final long ix = it.aLong;
34341                                        double ox;
34342                                        ox = (-ix);
34343                                        of64data[it.oIndex] = ox;
34344                                }
34345                        }
34346                        break;
34347                case Dataset.ARRAYFLOAT32:
34348                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
34349                        if (is == 1) {
34350                                if (it.isOutputDouble()) {
34351                                        while (it.hasNext()) {
34352                                                final double ix = it.aDouble;
34353                                                float ox;
34354                                                ox = (float) (-ix);
34355                                                oaf32data[it.oIndex] = ox;
34356                                        }
34357                                } else {
34358                                        while (it.hasNext()) {
34359                                                final long ix = it.aLong;
34360                                                float ox;
34361                                                ox = (-ix);
34362                                                oaf32data[it.oIndex] = ox;
34363                                        }
34364                                }
34365                        } else if (as == 1) {
34366                                if (it.isOutputDouble()) {
34367                                        while (it.hasNext()) {
34368                                                final double ix = it.aDouble;
34369                                                float ox;
34370                                                ox = (float) (-ix);
34371                                                for (int j = 0; j < is; j++) {
34372                                                        oaf32data[it.oIndex + j] = ox;
34373                                                }
34374                                        }
34375                                } else {
34376                                        while (it.hasNext()) {
34377                                                final long ix = it.aLong;
34378                                                float ox;
34379                                                ox = (-ix);
34380                                                for (int j = 0; j < is; j++) {
34381                                                        oaf32data[it.oIndex + j] = ox;
34382                                                }
34383                                        }
34384                                }
34385                        } else {
34386                                if (it.isOutputDouble()) {
34387                                        while (it.hasNext()) {
34388                                                for (int j = 0; j < is; j++) {
34389                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34390                                                        float ox;
34391                                                        ox = (float) (-ix);
34392                                                        oaf32data[it.oIndex + j] = ox;
34393                                                }
34394                                        }
34395                                } else {
34396                                        while (it.hasNext()) {
34397                                                for (int j = 0; j < is; j++) {
34398                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34399                                                        float ox;
34400                                                        ox = (-ix);
34401                                                        oaf32data[it.oIndex + j] = ox;
34402                                                }
34403                                        }
34404                                }
34405                        }
34406                        break;
34407                case Dataset.ARRAYFLOAT64:
34408                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
34409                        if (is == 1) {
34410                                if (it.isOutputDouble()) {
34411                                        while (it.hasNext()) {
34412                                                final double ix = it.aDouble;
34413                                                double ox;
34414                                                ox = (-ix);
34415                                                oaf64data[it.oIndex] = ox;
34416                                        }
34417                                } else {
34418                                        while (it.hasNext()) {
34419                                                final long ix = it.aLong;
34420                                                double ox;
34421                                                ox = (-ix);
34422                                                oaf64data[it.oIndex] = ox;
34423                                        }
34424                                }
34425                        } else if (as == 1) {
34426                                if (it.isOutputDouble()) {
34427                                        while (it.hasNext()) {
34428                                                final double ix = it.aDouble;
34429                                                double ox;
34430                                                ox = (-ix);
34431                                                for (int j = 0; j < is; j++) {
34432                                                        oaf64data[it.oIndex + j] = ox;
34433                                                }
34434                                        }
34435                                } else {
34436                                        while (it.hasNext()) {
34437                                                final long ix = it.aLong;
34438                                                double ox;
34439                                                ox = (-ix);
34440                                                for (int j = 0; j < is; j++) {
34441                                                        oaf64data[it.oIndex + j] = ox;
34442                                                }
34443                                        }
34444                                }
34445                        } else {
34446                                if (it.isOutputDouble()) {
34447                                        while (it.hasNext()) {
34448                                                for (int j = 0; j < is; j++) {
34449                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34450                                                        double ox;
34451                                                        ox = (-ix);
34452                                                        oaf64data[it.oIndex + j] = ox;
34453                                                }
34454                                        }
34455                                } else {
34456                                        while (it.hasNext()) {
34457                                                for (int j = 0; j < is; j++) {
34458                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34459                                                        double ox;
34460                                                        ox = (-ix);
34461                                                        oaf64data[it.oIndex + j] = ox;
34462                                                }
34463                                        }
34464                                }
34465                        }
34466                        break;
34467                case Dataset.COMPLEX64:
34468                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
34469                        if (!da.isComplex()) {
34470                                if (it.isOutputDouble()) {
34471                                        final double iy = 0;
34472                                        while (it.hasNext()) {
34473                                                final double ix = it.aDouble;
34474                                                float ox;
34475                                                float oy;
34476                                                ox = (float) (-ix);
34477                                                oy = (float) (-iy);
34478                                                oc64data[it.oIndex] = ox;
34479                                                oc64data[it.oIndex + 1] = oy;
34480                                        }
34481                                } else {
34482                                        final long iy = 0;
34483                                        while (it.hasNext()) {
34484                                                final long ix = it.aLong;
34485                                                float ox;
34486                                                float oy;
34487                                                ox = (float) toLong(-ix);
34488                                                oy = (float) toLong(-iy);
34489                                                oc64data[it.oIndex] = ox;
34490                                                oc64data[it.oIndex + 1] = oy;
34491                                        }
34492                                }
34493                        } else {
34494                                while (it.hasNext()) {
34495                                        final double ix = it.aDouble;
34496                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
34497                                        float ox;
34498                                        float oy;
34499                                        ox = (float) (-ix);
34500                                        oy = (float) (-iy);
34501                                        oc64data[it.oIndex] = ox;
34502                                        oc64data[it.oIndex + 1] = oy;
34503                                }
34504                        }
34505                        break;
34506                case Dataset.COMPLEX128:
34507                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
34508                        if (!da.isComplex()) {
34509                                if (it.isOutputDouble()) {
34510                                        final double iy = 0;
34511                                        while (it.hasNext()) {
34512                                                final double ix = it.aDouble;
34513                                                double ox;
34514                                                double oy;
34515                                                ox = (-ix);
34516                                                oy = (-iy);
34517                                                oc128data[it.oIndex] = ox;
34518                                                oc128data[it.oIndex + 1] = oy;
34519                                        }
34520                                } else {
34521                                        final long iy = 0;
34522                                        while (it.hasNext()) {
34523                                                final long ix = it.aLong;
34524                                                double ox;
34525                                                double oy;
34526                                                ox = (-ix);
34527                                                oy = (-iy);
34528                                                oc128data[it.oIndex] = ox;
34529                                                oc128data[it.oIndex + 1] = oy;
34530                                        }
34531                                }
34532                        } else {
34533                                while (it.hasNext()) {
34534                                        final double ix = it.aDouble;
34535                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
34536                                        double ox;
34537                                        double oy;
34538                                        ox = (-ix);
34539                                        oy = (-iy);
34540                                        oc128data[it.oIndex] = ox;
34541                                        oc128data[it.oIndex + 1] = oy;
34542                                }
34543                        }
34544                        break;
34545                default:
34546                        throw new IllegalArgumentException("negative supports integer, compound integer, real, compound real, complex datasets only");
34547                }
34548
34549                addFunctionName(result, "negative");
34550                return result;
34551        }
34552
34553        /**
34554         * lowerClip - clip elements to lower limit
34555         * @param a single operand
34556         * @param pa first parameter
34557         * @return dataset
34558         * @since 2.3
34559         */
34560        public static Dataset lowerClip(final Object a, final Object pa) {
34561                return lowerClip(a, null, pa);
34562        }
34563
34564        /**
34565         * lowerClip - clip elements to lower limit
34566         * @param a single operand
34567         * @param o output can be null - in which case, a new dataset is created
34568         * @param pa first parameter
34569         * @return dataset
34570         * @since 2.3
34571         */
34572        public static Dataset lowerClip(final Object a, final Dataset o, final Object pa) {
34573                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
34574                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
34575                final Dataset result = it.getOutput();
34576                if (!result.isComplex()) {
34577                        if (da.isComplex()) {
34578                                da = da.getRealView();
34579                                it = new SingleInputBroadcastIterator(da, result, true);
34580                        }
34581                }
34582                final int is = result.getElementsPerItem();
34583                final int as = da.getElementsPerItem();
34584                final int dt = result.getDType();
34585                final double pax = DTypeUtils.toReal(pa);
34586
34587                switch(dt) {
34588                case Dataset.INT8:
34589                        final byte[] oi8data = ((ByteDataset) result).getData();
34590                        if (it.isOutputDouble()) {
34591                                while (it.hasNext()) {
34592                                        final double ix = it.aDouble;
34593                                        byte ox;
34594                                        if (ix < pax)
34595                                        ox = (byte) toLong(pax);
34596                                        else
34597                                        ox = (byte) toLong(ix);
34598                                        oi8data[it.oIndex] = ox;
34599                                }
34600                        } else {
34601                                while (it.hasNext()) {
34602                                        final long ix = it.aLong;
34603                                        byte ox;
34604                                        if (ix < pax)
34605                                        ox = (byte) toLong(pax);
34606                                        else
34607                                        ox = (byte) toLong(ix);
34608                                        oi8data[it.oIndex] = ox;
34609                                }
34610                        }
34611                        break;
34612                case Dataset.INT16:
34613                        final short[] oi16data = ((ShortDataset) result).getData();
34614                        if (it.isOutputDouble()) {
34615                                while (it.hasNext()) {
34616                                        final double ix = it.aDouble;
34617                                        short ox;
34618                                        if (ix < pax)
34619                                        ox = (short) toLong(pax);
34620                                        else
34621                                        ox = (short) toLong(ix);
34622                                        oi16data[it.oIndex] = ox;
34623                                }
34624                        } else {
34625                                while (it.hasNext()) {
34626                                        final long ix = it.aLong;
34627                                        short ox;
34628                                        if (ix < pax)
34629                                        ox = (short) toLong(pax);
34630                                        else
34631                                        ox = (short) toLong(ix);
34632                                        oi16data[it.oIndex] = ox;
34633                                }
34634                        }
34635                        break;
34636                case Dataset.INT64:
34637                        final long[] oi64data = ((LongDataset) result).getData();
34638                        if (it.isOutputDouble()) {
34639                                while (it.hasNext()) {
34640                                        final double ix = it.aDouble;
34641                                        long ox;
34642                                        if (ix < pax)
34643                                        ox = toLong(pax);
34644                                        else
34645                                        ox = toLong(ix);
34646                                        oi64data[it.oIndex] = ox;
34647                                }
34648                        } else {
34649                                while (it.hasNext()) {
34650                                        final long ix = it.aLong;
34651                                        long ox;
34652                                        if (ix < pax)
34653                                        ox = toLong(pax);
34654                                        else
34655                                        ox = toLong(ix);
34656                                        oi64data[it.oIndex] = ox;
34657                                }
34658                        }
34659                        break;
34660                case Dataset.INT32:
34661                        final int[] oi32data = ((IntegerDataset) result).getData();
34662                        if (it.isOutputDouble()) {
34663                                while (it.hasNext()) {
34664                                        final double ix = it.aDouble;
34665                                        int ox;
34666                                        if (ix < pax)
34667                                        ox = (int) toLong(pax);
34668                                        else
34669                                        ox = (int) toLong(ix);
34670                                        oi32data[it.oIndex] = ox;
34671                                }
34672                        } else {
34673                                while (it.hasNext()) {
34674                                        final long ix = it.aLong;
34675                                        int ox;
34676                                        if (ix < pax)
34677                                        ox = (int) toLong(pax);
34678                                        else
34679                                        ox = (int) toLong(ix);
34680                                        oi32data[it.oIndex] = ox;
34681                                }
34682                        }
34683                        break;
34684                case Dataset.ARRAYINT8:
34685                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
34686                        if (is == 1) {
34687                                if (it.isOutputDouble()) {
34688                                        while (it.hasNext()) {
34689                                                final double ix = it.aDouble;
34690                                                byte ox;
34691                                                if (ix < pax)
34692                                                ox = (byte) toLong(pax);
34693                                                else
34694                                                ox = (byte) toLong(ix);
34695                                                oai8data[it.oIndex] = ox;
34696                                        }
34697                                } else {
34698                                        while (it.hasNext()) {
34699                                                final long ix = it.aLong;
34700                                                byte ox;
34701                                                if (ix < pax)
34702                                                ox = (byte) toLong(pax);
34703                                                else
34704                                                ox = (byte) toLong(ix);
34705                                                oai8data[it.oIndex] = ox;
34706                                        }
34707                                }
34708                        } else if (as == 1) {
34709                                if (it.isOutputDouble()) {
34710                                        while (it.hasNext()) {
34711                                                final double ix = it.aDouble;
34712                                                byte ox;
34713                                                if (ix < pax)
34714                                                ox = (byte) toLong(pax);
34715                                                else
34716                                                ox = (byte) toLong(ix);
34717                                                for (int j = 0; j < is; j++) {
34718                                                        oai8data[it.oIndex + j] = ox;
34719                                                }
34720                                        }
34721                                } else {
34722                                        while (it.hasNext()) {
34723                                                final long ix = it.aLong;
34724                                                byte ox;
34725                                                if (ix < pax)
34726                                                ox = (byte) toLong(pax);
34727                                                else
34728                                                ox = (byte) toLong(ix);
34729                                                for (int j = 0; j < is; j++) {
34730                                                        oai8data[it.oIndex + j] = ox;
34731                                                }
34732                                        }
34733                                }
34734                        } else {
34735                                if (it.isOutputDouble()) {
34736                                        while (it.hasNext()) {
34737                                                for (int j = 0; j < is; j++) {
34738                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34739                                                        byte ox;
34740                                                        if (ix < pax)
34741                                                        ox = (byte) toLong(pax);
34742                                                        else
34743                                                        ox = (byte) toLong(ix);
34744                                                        oai8data[it.oIndex + j] = ox;
34745                                                }
34746                                        }
34747                                } else {
34748                                        while (it.hasNext()) {
34749                                                for (int j = 0; j < is; j++) {
34750                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34751                                                        byte ox;
34752                                                        if (ix < pax)
34753                                                        ox = (byte) toLong(pax);
34754                                                        else
34755                                                        ox = (byte) toLong(ix);
34756                                                        oai8data[it.oIndex + j] = ox;
34757                                                }
34758                                        }
34759                                }
34760                        }
34761                        break;
34762                case Dataset.ARRAYINT16:
34763                        final short[] oai16data = ((CompoundShortDataset) result).getData();
34764                        if (is == 1) {
34765                                if (it.isOutputDouble()) {
34766                                        while (it.hasNext()) {
34767                                                final double ix = it.aDouble;
34768                                                short ox;
34769                                                if (ix < pax)
34770                                                ox = (short) toLong(pax);
34771                                                else
34772                                                ox = (short) toLong(ix);
34773                                                oai16data[it.oIndex] = ox;
34774                                        }
34775                                } else {
34776                                        while (it.hasNext()) {
34777                                                final long ix = it.aLong;
34778                                                short ox;
34779                                                if (ix < pax)
34780                                                ox = (short) toLong(pax);
34781                                                else
34782                                                ox = (short) toLong(ix);
34783                                                oai16data[it.oIndex] = ox;
34784                                        }
34785                                }
34786                        } else if (as == 1) {
34787                                if (it.isOutputDouble()) {
34788                                        while (it.hasNext()) {
34789                                                final double ix = it.aDouble;
34790                                                short ox;
34791                                                if (ix < pax)
34792                                                ox = (short) toLong(pax);
34793                                                else
34794                                                ox = (short) toLong(ix);
34795                                                for (int j = 0; j < is; j++) {
34796                                                        oai16data[it.oIndex + j] = ox;
34797                                                }
34798                                        }
34799                                } else {
34800                                        while (it.hasNext()) {
34801                                                final long ix = it.aLong;
34802                                                short ox;
34803                                                if (ix < pax)
34804                                                ox = (short) toLong(pax);
34805                                                else
34806                                                ox = (short) toLong(ix);
34807                                                for (int j = 0; j < is; j++) {
34808                                                        oai16data[it.oIndex + j] = ox;
34809                                                }
34810                                        }
34811                                }
34812                        } else {
34813                                if (it.isOutputDouble()) {
34814                                        while (it.hasNext()) {
34815                                                for (int j = 0; j < is; j++) {
34816                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34817                                                        short ox;
34818                                                        if (ix < pax)
34819                                                        ox = (short) toLong(pax);
34820                                                        else
34821                                                        ox = (short) toLong(ix);
34822                                                        oai16data[it.oIndex + j] = ox;
34823                                                }
34824                                        }
34825                                } else {
34826                                        while (it.hasNext()) {
34827                                                for (int j = 0; j < is; j++) {
34828                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34829                                                        short ox;
34830                                                        if (ix < pax)
34831                                                        ox = (short) toLong(pax);
34832                                                        else
34833                                                        ox = (short) toLong(ix);
34834                                                        oai16data[it.oIndex + j] = ox;
34835                                                }
34836                                        }
34837                                }
34838                        }
34839                        break;
34840                case Dataset.ARRAYINT64:
34841                        final long[] oai64data = ((CompoundLongDataset) result).getData();
34842                        if (is == 1) {
34843                                if (it.isOutputDouble()) {
34844                                        while (it.hasNext()) {
34845                                                final double ix = it.aDouble;
34846                                                long ox;
34847                                                if (ix < pax)
34848                                                ox = toLong(pax);
34849                                                else
34850                                                ox = toLong(ix);
34851                                                oai64data[it.oIndex] = ox;
34852                                        }
34853                                } else {
34854                                        while (it.hasNext()) {
34855                                                final long ix = it.aLong;
34856                                                long ox;
34857                                                if (ix < pax)
34858                                                ox = toLong(pax);
34859                                                else
34860                                                ox = toLong(ix);
34861                                                oai64data[it.oIndex] = ox;
34862                                        }
34863                                }
34864                        } else if (as == 1) {
34865                                if (it.isOutputDouble()) {
34866                                        while (it.hasNext()) {
34867                                                final double ix = it.aDouble;
34868                                                long ox;
34869                                                if (ix < pax)
34870                                                ox = toLong(pax);
34871                                                else
34872                                                ox = toLong(ix);
34873                                                for (int j = 0; j < is; j++) {
34874                                                        oai64data[it.oIndex + j] = ox;
34875                                                }
34876                                        }
34877                                } else {
34878                                        while (it.hasNext()) {
34879                                                final long ix = it.aLong;
34880                                                long ox;
34881                                                if (ix < pax)
34882                                                ox = toLong(pax);
34883                                                else
34884                                                ox = toLong(ix);
34885                                                for (int j = 0; j < is; j++) {
34886                                                        oai64data[it.oIndex + j] = ox;
34887                                                }
34888                                        }
34889                                }
34890                        } else {
34891                                if (it.isOutputDouble()) {
34892                                        while (it.hasNext()) {
34893                                                for (int j = 0; j < is; j++) {
34894                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34895                                                        long ox;
34896                                                        if (ix < pax)
34897                                                        ox = toLong(pax);
34898                                                        else
34899                                                        ox = toLong(ix);
34900                                                        oai64data[it.oIndex + j] = ox;
34901                                                }
34902                                        }
34903                                } else {
34904                                        while (it.hasNext()) {
34905                                                for (int j = 0; j < is; j++) {
34906                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34907                                                        long ox;
34908                                                        if (ix < pax)
34909                                                        ox = toLong(pax);
34910                                                        else
34911                                                        ox = toLong(ix);
34912                                                        oai64data[it.oIndex + j] = ox;
34913                                                }
34914                                        }
34915                                }
34916                        }
34917                        break;
34918                case Dataset.ARRAYINT32:
34919                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
34920                        if (is == 1) {
34921                                if (it.isOutputDouble()) {
34922                                        while (it.hasNext()) {
34923                                                final double ix = it.aDouble;
34924                                                int ox;
34925                                                if (ix < pax)
34926                                                ox = (int) toLong(pax);
34927                                                else
34928                                                ox = (int) toLong(ix);
34929                                                oai32data[it.oIndex] = ox;
34930                                        }
34931                                } else {
34932                                        while (it.hasNext()) {
34933                                                final long ix = it.aLong;
34934                                                int ox;
34935                                                if (ix < pax)
34936                                                ox = (int) toLong(pax);
34937                                                else
34938                                                ox = (int) toLong(ix);
34939                                                oai32data[it.oIndex] = ox;
34940                                        }
34941                                }
34942                        } else if (as == 1) {
34943                                if (it.isOutputDouble()) {
34944                                        while (it.hasNext()) {
34945                                                final double ix = it.aDouble;
34946                                                int ox;
34947                                                if (ix < pax)
34948                                                ox = (int) toLong(pax);
34949                                                else
34950                                                ox = (int) toLong(ix);
34951                                                for (int j = 0; j < is; j++) {
34952                                                        oai32data[it.oIndex + j] = ox;
34953                                                }
34954                                        }
34955                                } else {
34956                                        while (it.hasNext()) {
34957                                                final long ix = it.aLong;
34958                                                int ox;
34959                                                if (ix < pax)
34960                                                ox = (int) toLong(pax);
34961                                                else
34962                                                ox = (int) toLong(ix);
34963                                                for (int j = 0; j < is; j++) {
34964                                                        oai32data[it.oIndex + j] = ox;
34965                                                }
34966                                        }
34967                                }
34968                        } else {
34969                                if (it.isOutputDouble()) {
34970                                        while (it.hasNext()) {
34971                                                for (int j = 0; j < is; j++) {
34972                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
34973                                                        int ox;
34974                                                        if (ix < pax)
34975                                                        ox = (int) toLong(pax);
34976                                                        else
34977                                                        ox = (int) toLong(ix);
34978                                                        oai32data[it.oIndex + j] = ox;
34979                                                }
34980                                        }
34981                                } else {
34982                                        while (it.hasNext()) {
34983                                                for (int j = 0; j < is; j++) {
34984                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
34985                                                        int ox;
34986                                                        if (ix < pax)
34987                                                        ox = (int) toLong(pax);
34988                                                        else
34989                                                        ox = (int) toLong(ix);
34990                                                        oai32data[it.oIndex + j] = ox;
34991                                                }
34992                                        }
34993                                }
34994                        }
34995                        break;
34996                case Dataset.FLOAT32:
34997                        final float[] of32data = ((FloatDataset) result).getData();
34998                        if (it.isOutputDouble()) {
34999                                while (it.hasNext()) {
35000                                        final double ix = it.aDouble;
35001                                        float ox;
35002                                        if (ix < pax)
35003                                        ox = (float) (pax);
35004                                        else
35005                                        ox = (float) (ix);
35006                                        of32data[it.oIndex] = ox;
35007                                }
35008                        } else {
35009                                while (it.hasNext()) {
35010                                        final long ix = it.aLong;
35011                                        float ox;
35012                                        if (ix < pax)
35013                                        ox = (float) (pax);
35014                                        else
35015                                        ox = (ix);
35016                                        of32data[it.oIndex] = ox;
35017                                }
35018                        }
35019                        break;
35020                case Dataset.FLOAT64:
35021                        final double[] of64data = ((DoubleDataset) result).getData();
35022                        if (it.isOutputDouble()) {
35023                                while (it.hasNext()) {
35024                                        final double ix = it.aDouble;
35025                                        double ox;
35026                                        if (ix < pax)
35027                                        ox = (pax);
35028                                        else
35029                                        ox = (ix);
35030                                        of64data[it.oIndex] = ox;
35031                                }
35032                        } else {
35033                                while (it.hasNext()) {
35034                                        final long ix = it.aLong;
35035                                        double ox;
35036                                        if (ix < pax)
35037                                        ox = (pax);
35038                                        else
35039                                        ox = (ix);
35040                                        of64data[it.oIndex] = ox;
35041                                }
35042                        }
35043                        break;
35044                case Dataset.ARRAYFLOAT32:
35045                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
35046                        if (is == 1) {
35047                                if (it.isOutputDouble()) {
35048                                        while (it.hasNext()) {
35049                                                final double ix = it.aDouble;
35050                                                float ox;
35051                                                if (ix < pax)
35052                                                ox = (float) (pax);
35053                                                else
35054                                                ox = (float) (ix);
35055                                                oaf32data[it.oIndex] = ox;
35056                                        }
35057                                } else {
35058                                        while (it.hasNext()) {
35059                                                final long ix = it.aLong;
35060                                                float ox;
35061                                                if (ix < pax)
35062                                                ox = (float) (pax);
35063                                                else
35064                                                ox = (ix);
35065                                                oaf32data[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                                                float ox;
35073                                                if (ix < pax)
35074                                                ox = (float) (pax);
35075                                                else
35076                                                ox = (float) (ix);
35077                                                for (int j = 0; j < is; j++) {
35078                                                        oaf32data[it.oIndex + j] = ox;
35079                                                }
35080                                        }
35081                                } else {
35082                                        while (it.hasNext()) {
35083                                                final long ix = it.aLong;
35084                                                float ox;
35085                                                if (ix < pax)
35086                                                ox = (float) (pax);
35087                                                else
35088                                                ox = (ix);
35089                                                for (int j = 0; j < is; j++) {
35090                                                        oaf32data[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                                                        float ox;
35100                                                        if (ix < pax)
35101                                                        ox = (float) (pax);
35102                                                        else
35103                                                        ox = (float) (ix);
35104                                                        oaf32data[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                                                        float ox;
35112                                                        if (ix < pax)
35113                                                        ox = (float) (pax);
35114                                                        else
35115                                                        ox = (ix);
35116                                                        oaf32data[it.oIndex + j] = ox;
35117                                                }
35118                                        }
35119                                }
35120                        }
35121                        break;
35122                case Dataset.ARRAYFLOAT64:
35123                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
35124                        if (is == 1) {
35125                                if (it.isOutputDouble()) {
35126                                        while (it.hasNext()) {
35127                                                final double ix = it.aDouble;
35128                                                double ox;
35129                                                if (ix < pax)
35130                                                ox = (pax);
35131                                                else
35132                                                ox = (ix);
35133                                                oaf64data[it.oIndex] = ox;
35134                                        }
35135                                } else {
35136                                        while (it.hasNext()) {
35137                                                final long ix = it.aLong;
35138                                                double ox;
35139                                                if (ix < pax)
35140                                                ox = (pax);
35141                                                else
35142                                                ox = (ix);
35143                                                oaf64data[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                                                double ox;
35151                                                if (ix < pax)
35152                                                ox = (pax);
35153                                                else
35154                                                ox = (ix);
35155                                                for (int j = 0; j < is; j++) {
35156                                                        oaf64data[it.oIndex + j] = ox;
35157                                                }
35158                                        }
35159                                } else {
35160                                        while (it.hasNext()) {
35161                                                final long ix = it.aLong;
35162                                                double ox;
35163                                                if (ix < pax)
35164                                                ox = (pax);
35165                                                else
35166                                                ox = (ix);
35167                                                for (int j = 0; j < is; j++) {
35168                                                        oaf64data[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                                                        double ox;
35178                                                        if (ix < pax)
35179                                                        ox = (pax);
35180                                                        else
35181                                                        ox = (ix);
35182                                                        oaf64data[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                                                        double ox;
35190                                                        if (ix < pax)
35191                                                        ox = (pax);
35192                                                        else
35193                                                        ox = (ix);
35194                                                        oaf64data[it.oIndex + j] = ox;
35195                                                }
35196                                        }
35197                                }
35198                        }
35199                        break;
35200                default:
35201                        throw new IllegalArgumentException("lowerClip supports integer, compound integer, real, compound real datasets only");
35202                }
35203
35204                addFunctionName(result, "lowerClip");
35205                return result;
35206        }
35207
35208        /**
35209         * upperClip - clip elements to upper limit
35210         * @param a single operand
35211         * @param pa first parameter
35212         * @return dataset
35213         * @since 2.3
35214         */
35215        public static Dataset upperClip(final Object a, final Object pa) {
35216                return upperClip(a, null, pa);
35217        }
35218
35219        /**
35220         * upperClip - clip elements to upper limit
35221         * @param a single operand
35222         * @param o output can be null - in which case, a new dataset is created
35223         * @param pa first parameter
35224         * @return dataset
35225         * @since 2.3
35226         */
35227        public static Dataset upperClip(final Object a, final Dataset o, final Object pa) {
35228                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
35229                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
35230                final Dataset result = it.getOutput();
35231                if (!result.isComplex()) {
35232                        if (da.isComplex()) {
35233                                da = da.getRealView();
35234                                it = new SingleInputBroadcastIterator(da, result, true);
35235                        }
35236                }
35237                final int is = result.getElementsPerItem();
35238                final int as = da.getElementsPerItem();
35239                final int dt = result.getDType();
35240                final double pax = DTypeUtils.toReal(pa);
35241
35242                switch(dt) {
35243                case Dataset.INT8:
35244                        final byte[] oi8data = ((ByteDataset) result).getData();
35245                        if (it.isOutputDouble()) {
35246                                while (it.hasNext()) {
35247                                        final double ix = it.aDouble;
35248                                        byte ox;
35249                                        if (ix > pax)
35250                                        ox = (byte) toLong(pax);
35251                                        else
35252                                        ox = (byte) toLong(ix);
35253                                        oi8data[it.oIndex] = ox;
35254                                }
35255                        } else {
35256                                while (it.hasNext()) {
35257                                        final long ix = it.aLong;
35258                                        byte ox;
35259                                        if (ix > pax)
35260                                        ox = (byte) toLong(pax);
35261                                        else
35262                                        ox = (byte) toLong(ix);
35263                                        oi8data[it.oIndex] = ox;
35264                                }
35265                        }
35266                        break;
35267                case Dataset.INT16:
35268                        final short[] oi16data = ((ShortDataset) result).getData();
35269                        if (it.isOutputDouble()) {
35270                                while (it.hasNext()) {
35271                                        final double ix = it.aDouble;
35272                                        short ox;
35273                                        if (ix > pax)
35274                                        ox = (short) toLong(pax);
35275                                        else
35276                                        ox = (short) toLong(ix);
35277                                        oi16data[it.oIndex] = ox;
35278                                }
35279                        } else {
35280                                while (it.hasNext()) {
35281                                        final long ix = it.aLong;
35282                                        short ox;
35283                                        if (ix > pax)
35284                                        ox = (short) toLong(pax);
35285                                        else
35286                                        ox = (short) toLong(ix);
35287                                        oi16data[it.oIndex] = ox;
35288                                }
35289                        }
35290                        break;
35291                case Dataset.INT64:
35292                        final long[] oi64data = ((LongDataset) result).getData();
35293                        if (it.isOutputDouble()) {
35294                                while (it.hasNext()) {
35295                                        final double ix = it.aDouble;
35296                                        long ox;
35297                                        if (ix > pax)
35298                                        ox = toLong(pax);
35299                                        else
35300                                        ox = toLong(ix);
35301                                        oi64data[it.oIndex] = ox;
35302                                }
35303                        } else {
35304                                while (it.hasNext()) {
35305                                        final long ix = it.aLong;
35306                                        long ox;
35307                                        if (ix > pax)
35308                                        ox = toLong(pax);
35309                                        else
35310                                        ox = toLong(ix);
35311                                        oi64data[it.oIndex] = ox;
35312                                }
35313                        }
35314                        break;
35315                case Dataset.INT32:
35316                        final int[] oi32data = ((IntegerDataset) result).getData();
35317                        if (it.isOutputDouble()) {
35318                                while (it.hasNext()) {
35319                                        final double ix = it.aDouble;
35320                                        int ox;
35321                                        if (ix > pax)
35322                                        ox = (int) toLong(pax);
35323                                        else
35324                                        ox = (int) toLong(ix);
35325                                        oi32data[it.oIndex] = ox;
35326                                }
35327                        } else {
35328                                while (it.hasNext()) {
35329                                        final long ix = it.aLong;
35330                                        int ox;
35331                                        if (ix > pax)
35332                                        ox = (int) toLong(pax);
35333                                        else
35334                                        ox = (int) toLong(ix);
35335                                        oi32data[it.oIndex] = ox;
35336                                }
35337                        }
35338                        break;
35339                case Dataset.ARRAYINT8:
35340                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
35341                        if (is == 1) {
35342                                if (it.isOutputDouble()) {
35343                                        while (it.hasNext()) {
35344                                                final double ix = it.aDouble;
35345                                                byte ox;
35346                                                if (ix > pax)
35347                                                ox = (byte) toLong(pax);
35348                                                else
35349                                                ox = (byte) toLong(ix);
35350                                                oai8data[it.oIndex] = ox;
35351                                        }
35352                                } else {
35353                                        while (it.hasNext()) {
35354                                                final long ix = it.aLong;
35355                                                byte ox;
35356                                                if (ix > pax)
35357                                                ox = (byte) toLong(pax);
35358                                                else
35359                                                ox = (byte) toLong(ix);
35360                                                oai8data[it.oIndex] = ox;
35361                                        }
35362                                }
35363                        } else if (as == 1) {
35364                                if (it.isOutputDouble()) {
35365                                        while (it.hasNext()) {
35366                                                final double ix = it.aDouble;
35367                                                byte ox;
35368                                                if (ix > pax)
35369                                                ox = (byte) toLong(pax);
35370                                                else
35371                                                ox = (byte) toLong(ix);
35372                                                for (int j = 0; j < is; j++) {
35373                                                        oai8data[it.oIndex + j] = ox;
35374                                                }
35375                                        }
35376                                } else {
35377                                        while (it.hasNext()) {
35378                                                final long ix = it.aLong;
35379                                                byte ox;
35380                                                if (ix > pax)
35381                                                ox = (byte) toLong(pax);
35382                                                else
35383                                                ox = (byte) toLong(ix);
35384                                                for (int j = 0; j < is; j++) {
35385                                                        oai8data[it.oIndex + j] = ox;
35386                                                }
35387                                        }
35388                                }
35389                        } else {
35390                                if (it.isOutputDouble()) {
35391                                        while (it.hasNext()) {
35392                                                for (int j = 0; j < is; j++) {
35393                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
35394                                                        byte ox;
35395                                                        if (ix > pax)
35396                                                        ox = (byte) toLong(pax);
35397                                                        else
35398                                                        ox = (byte) toLong(ix);
35399                                                        oai8data[it.oIndex + j] = ox;
35400                                                }
35401                                        }
35402                                } else {
35403                                        while (it.hasNext()) {
35404                                                for (int j = 0; j < is; j++) {
35405                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
35406                                                        byte ox;
35407                                                        if (ix > pax)
35408                                                        ox = (byte) toLong(pax);
35409                                                        else
35410                                                        ox = (byte) toLong(ix);
35411                                                        oai8data[it.oIndex + j] = ox;
35412                                                }
35413                                        }
35414                                }
35415                        }
35416                        break;
35417                case Dataset.ARRAYINT16:
35418                        final short[] oai16data = ((CompoundShortDataset) result).getData();
35419                        if (is == 1) {
35420                                if (it.isOutputDouble()) {
35421                                        while (it.hasNext()) {
35422                                                final double ix = it.aDouble;
35423                                                short ox;
35424                                                if (ix > pax)
35425                                                ox = (short) toLong(pax);
35426                                                else
35427                                                ox = (short) toLong(ix);
35428                                                oai16data[it.oIndex] = ox;
35429                                        }
35430                                } else {
35431                                        while (it.hasNext()) {
35432                                                final long ix = it.aLong;
35433                                                short ox;
35434                                                if (ix > pax)
35435                                                ox = (short) toLong(pax);
35436                                                else
35437                                                ox = (short) toLong(ix);
35438                                                oai16data[it.oIndex] = ox;
35439                                        }
35440                                }
35441                        } else if (as == 1) {
35442                                if (it.isOutputDouble()) {
35443                                        while (it.hasNext()) {
35444                                                final double ix = it.aDouble;
35445                                                short ox;
35446                                                if (ix > pax)
35447                                                ox = (short) toLong(pax);
35448                                                else
35449                                                ox = (short) toLong(ix);
35450                                                for (int j = 0; j < is; j++) {
35451                                                        oai16data[it.oIndex + j] = ox;
35452                                                }
35453                                        }
35454                                } else {
35455                                        while (it.hasNext()) {
35456                                                final long ix = it.aLong;
35457                                                short ox;
35458                                                if (ix > pax)
35459                                                ox = (short) toLong(pax);
35460                                                else
35461                                                ox = (short) toLong(ix);
35462                                                for (int j = 0; j < is; j++) {
35463                                                        oai16data[it.oIndex + j] = ox;
35464                                                }
35465                                        }
35466                                }
35467                        } else {
35468                                if (it.isOutputDouble()) {
35469                                        while (it.hasNext()) {
35470                                                for (int j = 0; j < is; j++) {
35471                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
35472                                                        short ox;
35473                                                        if (ix > pax)
35474                                                        ox = (short) toLong(pax);
35475                                                        else
35476                                                        ox = (short) toLong(ix);
35477                                                        oai16data[it.oIndex + j] = ox;
35478                                                }
35479                                        }
35480                                } else {
35481                                        while (it.hasNext()) {
35482                                                for (int j = 0; j < is; j++) {
35483                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
35484                                                        short ox;
35485                                                        if (ix > pax)
35486                                                        ox = (short) toLong(pax);
35487                                                        else
35488                                                        ox = (short) toLong(ix);
35489                                                        oai16data[it.oIndex + j] = ox;
35490                                                }
35491                                        }
35492                                }
35493                        }
35494                        break;
35495                case Dataset.ARRAYINT64:
35496                        final long[] oai64data = ((CompoundLongDataset) result).getData();
35497                        if (is == 1) {
35498                                if (it.isOutputDouble()) {
35499                                        while (it.hasNext()) {
35500                                                final double ix = it.aDouble;
35501                                                long ox;
35502                                                if (ix > pax)
35503                                                ox = toLong(pax);
35504                                                else
35505                                                ox = toLong(ix);
35506                                                oai64data[it.oIndex] = ox;
35507                                        }
35508                                } else {
35509                                        while (it.hasNext()) {
35510                                                final long ix = it.aLong;
35511                                                long ox;
35512                                                if (ix > pax)
35513                                                ox = toLong(pax);
35514                                                else
35515                                                ox = toLong(ix);
35516                                                oai64data[it.oIndex] = ox;
35517                                        }
35518                                }
35519                        } else if (as == 1) {
35520                                if (it.isOutputDouble()) {
35521                                        while (it.hasNext()) {
35522                                                final double ix = it.aDouble;
35523                                                long ox;
35524                                                if (ix > pax)
35525                                                ox = toLong(pax);
35526                                                else
35527                                                ox = toLong(ix);
35528                                                for (int j = 0; j < is; j++) {
35529                                                        oai64data[it.oIndex + j] = ox;
35530                                                }
35531                                        }
35532                                } else {
35533                                        while (it.hasNext()) {
35534                                                final long ix = it.aLong;
35535                                                long ox;
35536                                                if (ix > pax)
35537                                                ox = toLong(pax);
35538                                                else
35539                                                ox = toLong(ix);
35540                                                for (int j = 0; j < is; j++) {
35541                                                        oai64data[it.oIndex + j] = ox;
35542                                                }
35543                                        }
35544                                }
35545                        } else {
35546                                if (it.isOutputDouble()) {
35547                                        while (it.hasNext()) {
35548                                                for (int j = 0; j < is; j++) {
35549                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
35550                                                        long ox;
35551                                                        if (ix > pax)
35552                                                        ox = toLong(pax);
35553                                                        else
35554                                                        ox = toLong(ix);
35555                                                        oai64data[it.oIndex + j] = ox;
35556                                                }
35557                                        }
35558                                } else {
35559                                        while (it.hasNext()) {
35560                                                for (int j = 0; j < is; j++) {
35561                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
35562                                                        long ox;
35563                                                        if (ix > pax)
35564                                                        ox = toLong(pax);
35565                                                        else
35566                                                        ox = toLong(ix);
35567                                                        oai64data[it.oIndex + j] = ox;
35568                                                }
35569                                        }
35570                                }
35571                        }
35572                        break;
35573                case Dataset.ARRAYINT32:
35574                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
35575                        if (is == 1) {
35576                                if (it.isOutputDouble()) {
35577                                        while (it.hasNext()) {
35578                                                final double ix = it.aDouble;
35579                                                int ox;
35580                                                if (ix > pax)
35581                                                ox = (int) toLong(pax);
35582                                                else
35583                                                ox = (int) toLong(ix);
35584                                                oai32data[it.oIndex] = ox;
35585                                        }
35586                                } else {
35587                                        while (it.hasNext()) {
35588                                                final long ix = it.aLong;
35589                                                int ox;
35590                                                if (ix > pax)
35591                                                ox = (int) toLong(pax);
35592                                                else
35593                                                ox = (int) toLong(ix);
35594                                                oai32data[it.oIndex] = ox;
35595                                        }
35596                                }
35597                        } else if (as == 1) {
35598                                if (it.isOutputDouble()) {
35599                                        while (it.hasNext()) {
35600                                                final double ix = it.aDouble;
35601                                                int ox;
35602                                                if (ix > pax)
35603                                                ox = (int) toLong(pax);
35604                                                else
35605                                                ox = (int) toLong(ix);
35606                                                for (int j = 0; j < is; j++) {
35607                                                        oai32data[it.oIndex + j] = ox;
35608                                                }
35609                                        }
35610                                } else {
35611                                        while (it.hasNext()) {
35612                                                final long ix = it.aLong;
35613                                                int ox;
35614                                                if (ix > pax)
35615                                                ox = (int) toLong(pax);
35616                                                else
35617                                                ox = (int) toLong(ix);
35618                                                for (int j = 0; j < is; j++) {
35619                                                        oai32data[it.oIndex + j] = ox;
35620                                                }
35621                                        }
35622                                }
35623                        } else {
35624                                if (it.isOutputDouble()) {
35625                                        while (it.hasNext()) {
35626                                                for (int j = 0; j < is; j++) {
35627                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
35628                                                        int ox;
35629                                                        if (ix > pax)
35630                                                        ox = (int) toLong(pax);
35631                                                        else
35632                                                        ox = (int) toLong(ix);
35633                                                        oai32data[it.oIndex + j] = ox;
35634                                                }
35635                                        }
35636                                } else {
35637                                        while (it.hasNext()) {
35638                                                for (int j = 0; j < is; j++) {
35639                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
35640                                                        int ox;
35641                                                        if (ix > pax)
35642                                                        ox = (int) toLong(pax);
35643                                                        else
35644                                                        ox = (int) toLong(ix);
35645                                                        oai32data[it.oIndex + j] = ox;
35646                                                }
35647                                        }
35648                                }
35649                        }
35650                        break;
35651                case Dataset.FLOAT32:
35652                        final float[] of32data = ((FloatDataset) result).getData();
35653                        if (it.isOutputDouble()) {
35654                                while (it.hasNext()) {
35655                                        final double ix = it.aDouble;
35656                                        float ox;
35657                                        if (ix > pax)
35658                                        ox = (float) (pax);
35659                                        else
35660                                        ox = (float) (ix);
35661                                        of32data[it.oIndex] = ox;
35662                                }
35663                        } else {
35664                                while (it.hasNext()) {
35665                                        final long ix = it.aLong;
35666                                        float ox;
35667                                        if (ix > pax)
35668                                        ox = (float) (pax);
35669                                        else
35670                                        ox = (ix);
35671                                        of32data[it.oIndex] = ox;
35672                                }
35673                        }
35674                        break;
35675                case Dataset.FLOAT64:
35676                        final double[] of64data = ((DoubleDataset) result).getData();
35677                        if (it.isOutputDouble()) {
35678                                while (it.hasNext()) {
35679                                        final double ix = it.aDouble;
35680                                        double ox;
35681                                        if (ix > pax)
35682                                        ox = (pax);
35683                                        else
35684                                        ox = (ix);
35685                                        of64data[it.oIndex] = ox;
35686                                }
35687                        } else {
35688                                while (it.hasNext()) {
35689                                        final long ix = it.aLong;
35690                                        double ox;
35691                                        if (ix > pax)
35692                                        ox = (pax);
35693                                        else
35694                                        ox = (ix);
35695                                        of64data[it.oIndex] = ox;
35696                                }
35697                        }
35698                        break;
35699                case Dataset.ARRAYFLOAT32:
35700                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
35701                        if (is == 1) {
35702                                if (it.isOutputDouble()) {
35703                                        while (it.hasNext()) {
35704                                                final double ix = it.aDouble;
35705                                                float ox;
35706                                                if (ix > pax)
35707                                                ox = (float) (pax);
35708                                                else
35709                                                ox = (float) (ix);
35710                                                oaf32data[it.oIndex] = ox;
35711                                        }
35712                                } else {
35713                                        while (it.hasNext()) {
35714                                                final long ix = it.aLong;
35715                                                float ox;
35716                                                if (ix > pax)
35717                                                ox = (float) (pax);
35718                                                else
35719                                                ox = (ix);
35720                                                oaf32data[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                                                float ox;
35728                                                if (ix > pax)
35729                                                ox = (float) (pax);
35730                                                else
35731                                                ox = (float) (ix);
35732                                                for (int j = 0; j < is; j++) {
35733                                                        oaf32data[it.oIndex + j] = ox;
35734                                                }
35735                                        }
35736                                } else {
35737                                        while (it.hasNext()) {
35738                                                final long ix = it.aLong;
35739                                                float ox;
35740                                                if (ix > pax)
35741                                                ox = (float) (pax);
35742                                                else
35743                                                ox = (ix);
35744                                                for (int j = 0; j < is; j++) {
35745                                                        oaf32data[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                                                        float ox;
35755                                                        if (ix > pax)
35756                                                        ox = (float) (pax);
35757                                                        else
35758                                                        ox = (float) (ix);
35759                                                        oaf32data[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                                                        float ox;
35767                                                        if (ix > pax)
35768                                                        ox = (float) (pax);
35769                                                        else
35770                                                        ox = (ix);
35771                                                        oaf32data[it.oIndex + j] = ox;
35772                                                }
35773                                        }
35774                                }
35775                        }
35776                        break;
35777                case Dataset.ARRAYFLOAT64:
35778                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
35779                        if (is == 1) {
35780                                if (it.isOutputDouble()) {
35781                                        while (it.hasNext()) {
35782                                                final double ix = it.aDouble;
35783                                                double ox;
35784                                                if (ix > pax)
35785                                                ox = (pax);
35786                                                else
35787                                                ox = (ix);
35788                                                oaf64data[it.oIndex] = ox;
35789                                        }
35790                                } else {
35791                                        while (it.hasNext()) {
35792                                                final long ix = it.aLong;
35793                                                double ox;
35794                                                if (ix > pax)
35795                                                ox = (pax);
35796                                                else
35797                                                ox = (ix);
35798                                                oaf64data[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                                                double ox;
35806                                                if (ix > pax)
35807                                                ox = (pax);
35808                                                else
35809                                                ox = (ix);
35810                                                for (int j = 0; j < is; j++) {
35811                                                        oaf64data[it.oIndex + j] = ox;
35812                                                }
35813                                        }
35814                                } else {
35815                                        while (it.hasNext()) {
35816                                                final long ix = it.aLong;
35817                                                double ox;
35818                                                if (ix > pax)
35819                                                ox = (pax);
35820                                                else
35821                                                ox = (ix);
35822                                                for (int j = 0; j < is; j++) {
35823                                                        oaf64data[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                                                        double ox;
35833                                                        if (ix > pax)
35834                                                        ox = (pax);
35835                                                        else
35836                                                        ox = (ix);
35837                                                        oaf64data[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                                                        double ox;
35845                                                        if (ix > pax)
35846                                                        ox = (pax);
35847                                                        else
35848                                                        ox = (ix);
35849                                                        oaf64data[it.oIndex + j] = ox;
35850                                                }
35851                                        }
35852                                }
35853                        }
35854                        break;
35855                default:
35856                        throw new IllegalArgumentException("upperClip supports integer, compound integer, real, compound real datasets only");
35857                }
35858
35859                addFunctionName(result, "upperClip");
35860                return result;
35861        }
35862
35863        /**
35864         * clip - clip elements to limits
35865         * @param a single operand
35866         * @param pa first parameter
35867         * @param pb second parameter
35868         * @return dataset
35869         */
35870        public static Dataset clip(final Object a, final Object pa, final Object pb) {
35871                return clip(a, null, pa, pb);
35872        }
35873
35874        /**
35875         * clip - clip elements to limits
35876         * @param a single operand
35877         * @param o output can be null - in which case, a new dataset is created
35878         * @param pa first parameter
35879         * @param pb second parameter
35880         * @return dataset
35881         */
35882        public static Dataset clip(final Object a, final Dataset o, final Object pa, final Object pb) {
35883                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
35884                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
35885                final Dataset result = it.getOutput();
35886                if (!result.isComplex()) {
35887                        if (da.isComplex()) {
35888                                da = da.getRealView();
35889                                it = new SingleInputBroadcastIterator(da, result, true);
35890                        }
35891                }
35892                final int is = result.getElementsPerItem();
35893                final int as = da.getElementsPerItem();
35894                final int dt = result.getDType();
35895                final double pax = DTypeUtils.toReal(pa);
35896                final double pbx = DTypeUtils.toReal(pb);
35897
35898                switch(dt) {
35899                case Dataset.INT8:
35900                        final byte[] oi8data = ((ByteDataset) result).getData();
35901                        if (it.isOutputDouble()) {
35902                                while (it.hasNext()) {
35903                                        final double ix = it.aDouble;
35904                                        byte ox;
35905                                        if (ix < pax)
35906                                                ox = (byte) toLong(pax);
35907                                        else if (ix > pbx)
35908                                                ox = (byte) toLong(pbx);
35909                                        else
35910                                                ox = (byte) toLong(ix);
35911                                        oi8data[it.oIndex] = ox;
35912                                }
35913                        } else {
35914                                while (it.hasNext()) {
35915                                        final long ix = it.aLong;
35916                                        byte ox;
35917                                        if (ix < pax)
35918                                                ox = (byte) toLong(pax);
35919                                        else if (ix > pbx)
35920                                                ox = (byte) toLong(pbx);
35921                                        else
35922                                                ox = (byte) toLong(ix);
35923                                        oi8data[it.oIndex] = ox;
35924                                }
35925                        }
35926                        break;
35927                case Dataset.INT16:
35928                        final short[] oi16data = ((ShortDataset) result).getData();
35929                        if (it.isOutputDouble()) {
35930                                while (it.hasNext()) {
35931                                        final double ix = it.aDouble;
35932                                        short ox;
35933                                        if (ix < pax)
35934                                                ox = (short) toLong(pax);
35935                                        else if (ix > pbx)
35936                                                ox = (short) toLong(pbx);
35937                                        else
35938                                                ox = (short) toLong(ix);
35939                                        oi16data[it.oIndex] = ox;
35940                                }
35941                        } else {
35942                                while (it.hasNext()) {
35943                                        final long ix = it.aLong;
35944                                        short ox;
35945                                        if (ix < pax)
35946                                                ox = (short) toLong(pax);
35947                                        else if (ix > pbx)
35948                                                ox = (short) toLong(pbx);
35949                                        else
35950                                                ox = (short) toLong(ix);
35951                                        oi16data[it.oIndex] = ox;
35952                                }
35953                        }
35954                        break;
35955                case Dataset.INT64:
35956                        final long[] oi64data = ((LongDataset) result).getData();
35957                        if (it.isOutputDouble()) {
35958                                while (it.hasNext()) {
35959                                        final double ix = it.aDouble;
35960                                        long ox;
35961                                        if (ix < pax)
35962                                                ox = toLong(pax);
35963                                        else if (ix > pbx)
35964                                                ox = toLong(pbx);
35965                                        else
35966                                                ox = toLong(ix);
35967                                        oi64data[it.oIndex] = ox;
35968                                }
35969                        } else {
35970                                while (it.hasNext()) {
35971                                        final long ix = it.aLong;
35972                                        long ox;
35973                                        if (ix < pax)
35974                                                ox = toLong(pax);
35975                                        else if (ix > pbx)
35976                                                ox = toLong(pbx);
35977                                        else
35978                                                ox = toLong(ix);
35979                                        oi64data[it.oIndex] = ox;
35980                                }
35981                        }
35982                        break;
35983                case Dataset.INT32:
35984                        final int[] oi32data = ((IntegerDataset) result).getData();
35985                        if (it.isOutputDouble()) {
35986                                while (it.hasNext()) {
35987                                        final double ix = it.aDouble;
35988                                        int ox;
35989                                        if (ix < pax)
35990                                                ox = (int) toLong(pax);
35991                                        else if (ix > pbx)
35992                                                ox = (int) toLong(pbx);
35993                                        else
35994                                                ox = (int) toLong(ix);
35995                                        oi32data[it.oIndex] = ox;
35996                                }
35997                        } else {
35998                                while (it.hasNext()) {
35999                                        final long ix = it.aLong;
36000                                        int ox;
36001                                        if (ix < pax)
36002                                                ox = (int) toLong(pax);
36003                                        else if (ix > pbx)
36004                                                ox = (int) toLong(pbx);
36005                                        else
36006                                                ox = (int) toLong(ix);
36007                                        oi32data[it.oIndex] = ox;
36008                                }
36009                        }
36010                        break;
36011                case Dataset.ARRAYINT8:
36012                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
36013                        if (is == 1) {
36014                                if (it.isOutputDouble()) {
36015                                        while (it.hasNext()) {
36016                                                final double ix = it.aDouble;
36017                                                byte ox;
36018                                                if (ix < pax)
36019                                                        ox = (byte) toLong(pax);
36020                                                else if (ix > pbx)
36021                                                        ox = (byte) toLong(pbx);
36022                                                else
36023                                                        ox = (byte) toLong(ix);
36024                                                oai8data[it.oIndex] = ox;
36025                                        }
36026                                } else {
36027                                        while (it.hasNext()) {
36028                                                final long ix = it.aLong;
36029                                                byte ox;
36030                                                if (ix < pax)
36031                                                        ox = (byte) toLong(pax);
36032                                                else if (ix > pbx)
36033                                                        ox = (byte) toLong(pbx);
36034                                                else
36035                                                        ox = (byte) toLong(ix);
36036                                                oai8data[it.oIndex] = ox;
36037                                        }
36038                                }
36039                        } else if (as == 1) {
36040                                if (it.isOutputDouble()) {
36041                                        while (it.hasNext()) {
36042                                                final double ix = it.aDouble;
36043                                                byte ox;
36044                                                if (ix < pax)
36045                                                        ox = (byte) toLong(pax);
36046                                                else if (ix > pbx)
36047                                                        ox = (byte) toLong(pbx);
36048                                                else
36049                                                        ox = (byte) toLong(ix);
36050                                                for (int j = 0; j < is; j++) {
36051                                                        oai8data[it.oIndex + j] = ox;
36052                                                }
36053                                        }
36054                                } else {
36055                                        while (it.hasNext()) {
36056                                                final long ix = it.aLong;
36057                                                byte ox;
36058                                                if (ix < pax)
36059                                                        ox = (byte) toLong(pax);
36060                                                else if (ix > pbx)
36061                                                        ox = (byte) toLong(pbx);
36062                                                else
36063                                                        ox = (byte) toLong(ix);
36064                                                for (int j = 0; j < is; j++) {
36065                                                        oai8data[it.oIndex + j] = ox;
36066                                                }
36067                                        }
36068                                }
36069                        } else {
36070                                if (it.isOutputDouble()) {
36071                                        while (it.hasNext()) {
36072                                                for (int j = 0; j < is; j++) {
36073                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
36074                                                        byte ox;
36075                                                        if (ix < pax)
36076                                                                ox = (byte) toLong(pax);
36077                                                        else if (ix > pbx)
36078                                                                ox = (byte) toLong(pbx);
36079                                                        else
36080                                                                ox = (byte) toLong(ix);
36081                                                        oai8data[it.oIndex + j] = ox;
36082                                                }
36083                                        }
36084                                } else {
36085                                        while (it.hasNext()) {
36086                                                for (int j = 0; j < is; j++) {
36087                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
36088                                                        byte ox;
36089                                                        if (ix < pax)
36090                                                                ox = (byte) toLong(pax);
36091                                                        else if (ix > pbx)
36092                                                                ox = (byte) toLong(pbx);
36093                                                        else
36094                                                                ox = (byte) toLong(ix);
36095                                                        oai8data[it.oIndex + j] = ox;
36096                                                }
36097                                        }
36098                                }
36099                        }
36100                        break;
36101                case Dataset.ARRAYINT16:
36102                        final short[] oai16data = ((CompoundShortDataset) result).getData();
36103                        if (is == 1) {
36104                                if (it.isOutputDouble()) {
36105                                        while (it.hasNext()) {
36106                                                final double ix = it.aDouble;
36107                                                short ox;
36108                                                if (ix < pax)
36109                                                        ox = (short) toLong(pax);
36110                                                else if (ix > pbx)
36111                                                        ox = (short) toLong(pbx);
36112                                                else
36113                                                        ox = (short) toLong(ix);
36114                                                oai16data[it.oIndex] = ox;
36115                                        }
36116                                } else {
36117                                        while (it.hasNext()) {
36118                                                final long ix = it.aLong;
36119                                                short ox;
36120                                                if (ix < pax)
36121                                                        ox = (short) toLong(pax);
36122                                                else if (ix > pbx)
36123                                                        ox = (short) toLong(pbx);
36124                                                else
36125                                                        ox = (short) toLong(ix);
36126                                                oai16data[it.oIndex] = ox;
36127                                        }
36128                                }
36129                        } else if (as == 1) {
36130                                if (it.isOutputDouble()) {
36131                                        while (it.hasNext()) {
36132                                                final double ix = it.aDouble;
36133                                                short ox;
36134                                                if (ix < pax)
36135                                                        ox = (short) toLong(pax);
36136                                                else if (ix > pbx)
36137                                                        ox = (short) toLong(pbx);
36138                                                else
36139                                                        ox = (short) toLong(ix);
36140                                                for (int j = 0; j < is; j++) {
36141                                                        oai16data[it.oIndex + j] = ox;
36142                                                }
36143                                        }
36144                                } else {
36145                                        while (it.hasNext()) {
36146                                                final long ix = it.aLong;
36147                                                short ox;
36148                                                if (ix < pax)
36149                                                        ox = (short) toLong(pax);
36150                                                else if (ix > pbx)
36151                                                        ox = (short) toLong(pbx);
36152                                                else
36153                                                        ox = (short) toLong(ix);
36154                                                for (int j = 0; j < is; j++) {
36155                                                        oai16data[it.oIndex + j] = ox;
36156                                                }
36157                                        }
36158                                }
36159                        } else {
36160                                if (it.isOutputDouble()) {
36161                                        while (it.hasNext()) {
36162                                                for (int j = 0; j < is; j++) {
36163                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
36164                                                        short ox;
36165                                                        if (ix < pax)
36166                                                                ox = (short) toLong(pax);
36167                                                        else if (ix > pbx)
36168                                                                ox = (short) toLong(pbx);
36169                                                        else
36170                                                                ox = (short) toLong(ix);
36171                                                        oai16data[it.oIndex + j] = ox;
36172                                                }
36173                                        }
36174                                } else {
36175                                        while (it.hasNext()) {
36176                                                for (int j = 0; j < is; j++) {
36177                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
36178                                                        short ox;
36179                                                        if (ix < pax)
36180                                                                ox = (short) toLong(pax);
36181                                                        else if (ix > pbx)
36182                                                                ox = (short) toLong(pbx);
36183                                                        else
36184                                                                ox = (short) toLong(ix);
36185                                                        oai16data[it.oIndex + j] = ox;
36186                                                }
36187                                        }
36188                                }
36189                        }
36190                        break;
36191                case Dataset.ARRAYINT64:
36192                        final long[] oai64data = ((CompoundLongDataset) result).getData();
36193                        if (is == 1) {
36194                                if (it.isOutputDouble()) {
36195                                        while (it.hasNext()) {
36196                                                final double ix = it.aDouble;
36197                                                long ox;
36198                                                if (ix < pax)
36199                                                        ox = toLong(pax);
36200                                                else if (ix > pbx)
36201                                                        ox = toLong(pbx);
36202                                                else
36203                                                        ox = toLong(ix);
36204                                                oai64data[it.oIndex] = ox;
36205                                        }
36206                                } else {
36207                                        while (it.hasNext()) {
36208                                                final long ix = it.aLong;
36209                                                long ox;
36210                                                if (ix < pax)
36211                                                        ox = toLong(pax);
36212                                                else if (ix > pbx)
36213                                                        ox = toLong(pbx);
36214                                                else
36215                                                        ox = toLong(ix);
36216                                                oai64data[it.oIndex] = ox;
36217                                        }
36218                                }
36219                        } else if (as == 1) {
36220                                if (it.isOutputDouble()) {
36221                                        while (it.hasNext()) {
36222                                                final double ix = it.aDouble;
36223                                                long ox;
36224                                                if (ix < pax)
36225                                                        ox = toLong(pax);
36226                                                else if (ix > pbx)
36227                                                        ox = toLong(pbx);
36228                                                else
36229                                                        ox = toLong(ix);
36230                                                for (int j = 0; j < is; j++) {
36231                                                        oai64data[it.oIndex + j] = ox;
36232                                                }
36233                                        }
36234                                } else {
36235                                        while (it.hasNext()) {
36236                                                final long ix = it.aLong;
36237                                                long ox;
36238                                                if (ix < pax)
36239                                                        ox = toLong(pax);
36240                                                else if (ix > pbx)
36241                                                        ox = toLong(pbx);
36242                                                else
36243                                                        ox = toLong(ix);
36244                                                for (int j = 0; j < is; j++) {
36245                                                        oai64data[it.oIndex + j] = ox;
36246                                                }
36247                                        }
36248                                }
36249                        } else {
36250                                if (it.isOutputDouble()) {
36251                                        while (it.hasNext()) {
36252                                                for (int j = 0; j < is; j++) {
36253                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
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                                                        oai64data[it.oIndex + j] = ox;
36262                                                }
36263                                        }
36264                                } else {
36265                                        while (it.hasNext()) {
36266                                                for (int j = 0; j < is; j++) {
36267                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
36268                                                        long ox;
36269                                                        if (ix < pax)
36270                                                                ox = toLong(pax);
36271                                                        else if (ix > pbx)
36272                                                                ox = toLong(pbx);
36273                                                        else
36274                                                                ox = toLong(ix);
36275                                                        oai64data[it.oIndex + j] = ox;
36276                                                }
36277                                        }
36278                                }
36279                        }
36280                        break;
36281                case Dataset.ARRAYINT32:
36282                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
36283                        if (is == 1) {
36284                                if (it.isOutputDouble()) {
36285                                        while (it.hasNext()) {
36286                                                final double ix = it.aDouble;
36287                                                int ox;
36288                                                if (ix < pax)
36289                                                        ox = (int) toLong(pax);
36290                                                else if (ix > pbx)
36291                                                        ox = (int) toLong(pbx);
36292                                                else
36293                                                        ox = (int) toLong(ix);
36294                                                oai32data[it.oIndex] = ox;
36295                                        }
36296                                } else {
36297                                        while (it.hasNext()) {
36298                                                final long ix = it.aLong;
36299                                                int ox;
36300                                                if (ix < pax)
36301                                                        ox = (int) toLong(pax);
36302                                                else if (ix > pbx)
36303                                                        ox = (int) toLong(pbx);
36304                                                else
36305                                                        ox = (int) toLong(ix);
36306                                                oai32data[it.oIndex] = ox;
36307                                        }
36308                                }
36309                        } else if (as == 1) {
36310                                if (it.isOutputDouble()) {
36311                                        while (it.hasNext()) {
36312                                                final double ix = it.aDouble;
36313                                                int ox;
36314                                                if (ix < pax)
36315                                                        ox = (int) toLong(pax);
36316                                                else if (ix > pbx)
36317                                                        ox = (int) toLong(pbx);
36318                                                else
36319                                                        ox = (int) toLong(ix);
36320                                                for (int j = 0; j < is; j++) {
36321                                                        oai32data[it.oIndex + j] = ox;
36322                                                }
36323                                        }
36324                                } else {
36325                                        while (it.hasNext()) {
36326                                                final long ix = it.aLong;
36327                                                int ox;
36328                                                if (ix < pax)
36329                                                        ox = (int) toLong(pax);
36330                                                else if (ix > pbx)
36331                                                        ox = (int) toLong(pbx);
36332                                                else
36333                                                        ox = (int) toLong(ix);
36334                                                for (int j = 0; j < is; j++) {
36335                                                        oai32data[it.oIndex + j] = ox;
36336                                                }
36337                                        }
36338                                }
36339                        } else {
36340                                if (it.isOutputDouble()) {
36341                                        while (it.hasNext()) {
36342                                                for (int j = 0; j < is; j++) {
36343                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
36344                                                        int ox;
36345                                                        if (ix < pax)
36346                                                                ox = (int) toLong(pax);
36347                                                        else if (ix > pbx)
36348                                                                ox = (int) toLong(pbx);
36349                                                        else
36350                                                                ox = (int) toLong(ix);
36351                                                        oai32data[it.oIndex + j] = ox;
36352                                                }
36353                                        }
36354                                } else {
36355                                        while (it.hasNext()) {
36356                                                for (int j = 0; j < is; j++) {
36357                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
36358                                                        int ox;
36359                                                        if (ix < pax)
36360                                                                ox = (int) toLong(pax);
36361                                                        else if (ix > pbx)
36362                                                                ox = (int) toLong(pbx);
36363                                                        else
36364                                                                ox = (int) toLong(ix);
36365                                                        oai32data[it.oIndex + j] = ox;
36366                                                }
36367                                        }
36368                                }
36369                        }
36370                        break;
36371                case Dataset.FLOAT32:
36372                        final float[] of32data = ((FloatDataset) result).getData();
36373                        if (it.isOutputDouble()) {
36374                                while (it.hasNext()) {
36375                                        final double ix = it.aDouble;
36376                                        float ox;
36377                                        if (Double.isNaN(ix))
36378                                                ox = (float) ((pax+pbx)/2.);
36379                                        else if (ix < pax)
36380                                                ox = (float) (pax);
36381                                        else if (ix > pbx)
36382                                                ox = (float) (pbx);
36383                                        else
36384                                                ox = (float) (ix);
36385                                        of32data[it.oIndex] = ox;
36386                                }
36387                        } else {
36388                                while (it.hasNext()) {
36389                                        final long ix = it.aLong;
36390                                        float ox;
36391                                        if (Double.isNaN(ix))
36392                                                ox = (float) ((pax+pbx)/2.);
36393                                        else if (ix < pax)
36394                                                ox = (float) (pax);
36395                                        else if (ix > pbx)
36396                                                ox = (float) (pbx);
36397                                        else
36398                                                ox = (ix);
36399                                        of32data[it.oIndex] = ox;
36400                                }
36401                        }
36402                        break;
36403                case Dataset.FLOAT64:
36404                        final double[] of64data = ((DoubleDataset) result).getData();
36405                        if (it.isOutputDouble()) {
36406                                while (it.hasNext()) {
36407                                        final double ix = it.aDouble;
36408                                        double ox;
36409                                        if (Double.isNaN(ix))
36410                                                ox = ((pax+pbx)/2.);
36411                                        else if (ix < pax)
36412                                                ox = (pax);
36413                                        else if (ix > pbx)
36414                                                ox = (pbx);
36415                                        else
36416                                                ox = (ix);
36417                                        of64data[it.oIndex] = ox;
36418                                }
36419                        } else {
36420                                while (it.hasNext()) {
36421                                        final long ix = it.aLong;
36422                                        double ox;
36423                                        if (Double.isNaN(ix))
36424                                                ox = ((pax+pbx)/2.);
36425                                        else if (ix < pax)
36426                                                ox = (pax);
36427                                        else if (ix > pbx)
36428                                                ox = (pbx);
36429                                        else
36430                                                ox = (ix);
36431                                        of64data[it.oIndex] = ox;
36432                                }
36433                        }
36434                        break;
36435                case Dataset.ARRAYFLOAT32:
36436                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
36437                        if (is == 1) {
36438                                if (it.isOutputDouble()) {
36439                                        while (it.hasNext()) {
36440                                                final double ix = it.aDouble;
36441                                                float ox;
36442                                                if (Double.isNaN(ix))
36443                                                        ox = (float) ((pax+pbx)/2.);
36444                                                else if (ix < pax)
36445                                                        ox = (float) (pax);
36446                                                else if (ix > pbx)
36447                                                        ox = (float) (pbx);
36448                                                else
36449                                                        ox = (float) (ix);
36450                                                oaf32data[it.oIndex] = ox;
36451                                        }
36452                                } else {
36453                                        while (it.hasNext()) {
36454                                                final long ix = it.aLong;
36455                                                float ox;
36456                                                if (Double.isNaN(ix))
36457                                                        ox = (float) ((pax+pbx)/2.);
36458                                                else if (ix < pax)
36459                                                        ox = (float) (pax);
36460                                                else if (ix > pbx)
36461                                                        ox = (float) (pbx);
36462                                                else
36463                                                        ox = (ix);
36464                                                oaf32data[it.oIndex] = ox;
36465                                        }
36466                                }
36467                        } else if (as == 1) {
36468                                if (it.isOutputDouble()) {
36469                                        while (it.hasNext()) {
36470                                                final double ix = it.aDouble;
36471                                                float ox;
36472                                                if (Double.isNaN(ix))
36473                                                        ox = (float) ((pax+pbx)/2.);
36474                                                else if (ix < pax)
36475                                                        ox = (float) (pax);
36476                                                else if (ix > pbx)
36477                                                        ox = (float) (pbx);
36478                                                else
36479                                                        ox = (float) (ix);
36480                                                for (int j = 0; j < is; j++) {
36481                                                        oaf32data[it.oIndex + j] = ox;
36482                                                }
36483                                        }
36484                                } else {
36485                                        while (it.hasNext()) {
36486                                                final long ix = it.aLong;
36487                                                float ox;
36488                                                if (Double.isNaN(ix))
36489                                                        ox = (float) ((pax+pbx)/2.);
36490                                                else if (ix < pax)
36491                                                        ox = (float) (pax);
36492                                                else if (ix > pbx)
36493                                                        ox = (float) (pbx);
36494                                                else
36495                                                        ox = (ix);
36496                                                for (int j = 0; j < is; j++) {
36497                                                        oaf32data[it.oIndex + j] = ox;
36498                                                }
36499                                        }
36500                                }
36501                        } else {
36502                                if (it.isOutputDouble()) {
36503                                        while (it.hasNext()) {
36504                                                for (int j = 0; j < is; j++) {
36505                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
36506                                                        float ox;
36507                                                        if (Double.isNaN(ix))
36508                                                                ox = (float) ((pax+pbx)/2.);
36509                                                        else if (ix < pax)
36510                                                                ox = (float) (pax);
36511                                                        else if (ix > pbx)
36512                                                                ox = (float) (pbx);
36513                                                        else
36514                                                                ox = (float) (ix);
36515                                                        oaf32data[it.oIndex + j] = ox;
36516                                                }
36517                                        }
36518                                } else {
36519                                        while (it.hasNext()) {
36520                                                for (int j = 0; j < is; j++) {
36521                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
36522                                                        float ox;
36523                                                        if (Double.isNaN(ix))
36524                                                                ox = (float) ((pax+pbx)/2.);
36525                                                        else if (ix < pax)
36526                                                                ox = (float) (pax);
36527                                                        else if (ix > pbx)
36528                                                                ox = (float) (pbx);
36529                                                        else
36530                                                                ox = (ix);
36531                                                        oaf32data[it.oIndex + j] = ox;
36532                                                }
36533                                        }
36534                                }
36535                        }
36536                        break;
36537                case Dataset.ARRAYFLOAT64:
36538                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
36539                        if (is == 1) {
36540                                if (it.isOutputDouble()) {
36541                                        while (it.hasNext()) {
36542                                                final double ix = it.aDouble;
36543                                                double ox;
36544                                                if (Double.isNaN(ix))
36545                                                        ox = ((pax+pbx)/2.);
36546                                                else if (ix < pax)
36547                                                        ox = (pax);
36548                                                else if (ix > pbx)
36549                                                        ox = (pbx);
36550                                                else
36551                                                        ox = (ix);
36552                                                oaf64data[it.oIndex] = ox;
36553                                        }
36554                                } else {
36555                                        while (it.hasNext()) {
36556                                                final long ix = it.aLong;
36557                                                double ox;
36558                                                if (Double.isNaN(ix))
36559                                                        ox = ((pax+pbx)/2.);
36560                                                else if (ix < pax)
36561                                                        ox = (pax);
36562                                                else if (ix > pbx)
36563                                                        ox = (pbx);
36564                                                else
36565                                                        ox = (ix);
36566                                                oaf64data[it.oIndex] = ox;
36567                                        }
36568                                }
36569                        } else if (as == 1) {
36570                                if (it.isOutputDouble()) {
36571                                        while (it.hasNext()) {
36572                                                final double ix = it.aDouble;
36573                                                double ox;
36574                                                if (Double.isNaN(ix))
36575                                                        ox = ((pax+pbx)/2.);
36576                                                else if (ix < pax)
36577                                                        ox = (pax);
36578                                                else if (ix > pbx)
36579                                                        ox = (pbx);
36580                                                else
36581                                                        ox = (ix);
36582                                                for (int j = 0; j < is; j++) {
36583                                                        oaf64data[it.oIndex + j] = ox;
36584                                                }
36585                                        }
36586                                } else {
36587                                        while (it.hasNext()) {
36588                                                final long ix = it.aLong;
36589                                                double ox;
36590                                                if (Double.isNaN(ix))
36591                                                        ox = ((pax+pbx)/2.);
36592                                                else if (ix < pax)
36593                                                        ox = (pax);
36594                                                else if (ix > pbx)
36595                                                        ox = (pbx);
36596                                                else
36597                                                        ox = (ix);
36598                                                for (int j = 0; j < is; j++) {
36599                                                        oaf64data[it.oIndex + j] = ox;
36600                                                }
36601                                        }
36602                                }
36603                        } else {
36604                                if (it.isOutputDouble()) {
36605                                        while (it.hasNext()) {
36606                                                for (int j = 0; j < is; j++) {
36607                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
36608                                                        double ox;
36609                                                        if (Double.isNaN(ix))
36610                                                                ox = ((pax+pbx)/2.);
36611                                                        else if (ix < pax)
36612                                                                ox = (pax);
36613                                                        else if (ix > pbx)
36614                                                                ox = (pbx);
36615                                                        else
36616                                                                ox = (ix);
36617                                                        oaf64data[it.oIndex + j] = ox;
36618                                                }
36619                                        }
36620                                } else {
36621                                        while (it.hasNext()) {
36622                                                for (int j = 0; j < is; j++) {
36623                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
36624                                                        double ox;
36625                                                        if (Double.isNaN(ix))
36626                                                                ox = ((pax+pbx)/2.);
36627                                                        else if (ix < pax)
36628                                                                ox = (pax);
36629                                                        else if (ix > pbx)
36630                                                                ox = (pbx);
36631                                                        else
36632                                                                ox = (ix);
36633                                                        oaf64data[it.oIndex + j] = ox;
36634                                                }
36635                                        }
36636                                }
36637                        }
36638                        break;
36639                default:
36640                        throw new IllegalArgumentException("clip supports integer, compound integer, real, compound real datasets only");
36641                }
36642
36643                addFunctionName(result, "clip");
36644                return result;
36645        }
36646
36647// End of generated code
36648
36649}