1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have
  23  * questions.
  24  */
  25 package jdk.incubator.vector;
  26 
  27 /**
  28  * Operations on vectors that are not intrinsic candidates
  29  */
  30 @SuppressWarnings("cast")
  31 public final class DoubleVectorHelper {
  32 
  33     private DoubleVectorHelper() {}
  34 
  35     public interface BinaryOp {
  36         double apply(int i, double a, double b);
  37     }
  38 
  39     public interface UnaryOp {
  40         double apply(int i, double a);
  41     }
  42 
  43     public static 
  44     DoubleVector map(DoubleVector va, DoubleVector vb, BinaryOp op) {
  45         return va.bOp(vb, (i, a, b) -> op.apply(i, a, b));
  46     }
  47 
  48     public static 
  49     DoubleVector map(DoubleVector va, DoubleVector vb, Vector.Mask<Double> m, BinaryOp op) {
  50         return va.bOp(vb, m, (i, a, b) -> op.apply(i, a, b));
  51     }
  52 
  53     public static 
  54     DoubleVector map(DoubleVector va, UnaryOp op) {
  55         return va.uOp((i, a) -> op.apply(i, a));
  56     }
  57 
  58     public static 
  59     DoubleVector map(DoubleVector va, Vector.Mask<Double> m, UnaryOp op) {
  60         return va.uOp(m, (i, a) -> op.apply(i, a));
  61     }
  62 
  63 
  64 
  65     public static 
  66     DoubleVector ceil(DoubleVector va) {
  67         return va.uOp((i, a) -> (double) Math.ceil((double) a));
  68     }
  69 
  70     public static 
  71     DoubleVector ceil(DoubleVector va, Vector.Mask<Double> m) {
  72         return va.uOp(m, (i, a) -> (double) Math.ceil((double) a));
  73     }
  74 
  75     public static 
  76     DoubleVector copySign(DoubleVector va, DoubleVector vb) {
  77         return va.bOp(vb, (i, a, b) -> (double) Math.copySign((double) a, (double) b));
  78     }
  79 
  80     public static 
  81     DoubleVector copySign(DoubleVector va, DoubleVector vb, Vector.Mask<Double> m) {
  82         return va.bOp(vb, m, (i, a, b) -> (double) Math.copySign((double) a, (double) b));
  83     }
  84 
  85     public static 
  86     DoubleVector floor(DoubleVector va) {
  87         return va.uOp((i, a) -> (double) Math.floor((double) a));
  88     }
  89 
  90     public static 
  91     DoubleVector floor(DoubleVector va, Vector.Mask<Double> m) {
  92         return va.uOp(m, (i, a) -> (double) Math.floor((double) a));
  93     }
  94 
  95     public static 
  96     DoubleVector getExponent(DoubleVector va) {
  97         return va.uOp((i, a) -> (double) Math.getExponent((double) a));
  98     }
  99 
 100     public static 
 101     DoubleVector getExponent(DoubleVector va, Vector.Mask<Double> m) {
 102         return va.uOp(m, (i, a) -> (double) Math.getExponent((double) a));
 103     }
 104 
 105     public static 
 106     DoubleVector IEEEremainder(DoubleVector va, DoubleVector vb) {
 107         return va.bOp(vb, (i, a, b) -> (double) Math.IEEEremainder((double) a, (double) b));
 108     }
 109 
 110     public static 
 111     DoubleVector IEEEremainder(DoubleVector va, DoubleVector vb, Vector.Mask<Double> m) {
 112         return va.bOp(vb, m, (i, a, b) -> (double) Math.IEEEremainder((double) a, (double) b));
 113     }
 114 
 115     public static 
 116     DoubleVector nextAfter(DoubleVector va, DoubleVector vb) {
 117         return va.bOp(vb, (i, a, b) -> (double) Math.nextAfter((double) a, (double) b));
 118     }
 119 
 120     public static 
 121     DoubleVector nextAfter(DoubleVector va, DoubleVector vb, Vector.Mask<Double> m) {
 122         return va.bOp(vb, m, (i, a, b) -> (double) Math.nextAfter((double) a, (double) b));
 123     }
 124 
 125     public static 
 126     DoubleVector nextDown(DoubleVector va) {
 127         return va.uOp((i, a) -> (double) Math.nextDown((double) a));
 128     }
 129 
 130     public static 
 131     DoubleVector nextDown(DoubleVector va, Vector.Mask<Double> m) {
 132         return va.uOp(m, (i, a) -> (double) Math.nextDown((double) a));
 133     }
 134 
 135     public static 
 136     DoubleVector nextUp(DoubleVector va) {
 137         return va.uOp((i, a) -> (double) Math.nextUp((double) a));
 138     }
 139 
 140     public static 
 141     DoubleVector nextUp(DoubleVector va, Vector.Mask<Double> m) {
 142         return va.uOp(m, (i, a) -> (double) Math.nextUp((double) a));
 143     }
 144 
 145     public static 
 146     DoubleVector rint(DoubleVector va) {
 147         return va.uOp((i, a) -> (double) Math.rint((double) a));
 148     }
 149 
 150     public static 
 151     DoubleVector rint(DoubleVector va, Vector.Mask<Double> m) {
 152         return va.uOp(m, (i, a) -> (double) Math.rint((double) a));
 153     }
 154 
 155     public static 
 156     DoubleVector round(DoubleVector va) {
 157         return va.uOp((i, a) -> (double) Math.round((double) a));
 158     }
 159 
 160     public static 
 161     DoubleVector round(DoubleVector va, Vector.Mask<Double> m) {
 162         return va.uOp(m, (i, a) -> (double) Math.round((double) a));
 163     }
 164 
 165     public static 
 166     DoubleVector scalb(Vector<Integer> o) {
 167         throw  new UnsupportedOperationException("Scalb not implemented yet.");
 168     }
 169 
 170     public static 
 171     DoubleVector scalb(Vector<Integer> o, Vector.Mask<Double> m) {
 172         throw  new UnsupportedOperationException("Scalb not implemented yet.");
 173     }
 174 
 175     public static 
 176     DoubleVector signum(DoubleVector va) {
 177         return va.uOp((i, a) -> (double) Math.signum((double) a));
 178     }
 179 
 180     public static 
 181     DoubleVector signum(DoubleVector va, Vector.Mask<Double> m) {
 182         return va.uOp(m, (i, a) -> (double) Math.signum((double) a));
 183     }
 184 
 185     public static 
 186     DoubleVector toDegrees(DoubleVector va) {
 187         return va.uOp((i, a) -> (double) Math.toDegrees((double) a));
 188     }
 189 
 190     public static 
 191     DoubleVector toDegrees(DoubleVector va, Vector.Mask<Double> m) {
 192         return va.uOp(m, (i, a) -> (double) Math.toDegrees((double) a));
 193     }
 194 
 195     public static 
 196     DoubleVector toRadians(DoubleVector va) {
 197         return va.uOp((i, a) -> (double) Math.toRadians((double) a));
 198     }
 199 
 200     public static 
 201     DoubleVector toRadians(DoubleVector va, Vector.Mask<Double> m) {
 202         return va.uOp(m, (i, a) -> (double) Math.toRadians((double) a));
 203     }
 204 
 205     public static 
 206     DoubleVector ulp(DoubleVector va) {
 207         return va.uOp((i, a) -> (double) Math.ulp((double) a));
 208     }
 209 
 210     public static 
 211     DoubleVector ulp(DoubleVector va, Vector.Mask<Double> m) {
 212         return va.uOp(m, (i, a) -> (double) Math.ulp((double) a));
 213     }
 214 
 215 }