var t;
(function(e) {
  e[e.ADD = 0] = "ADD", e[e.ATAN2 = 1] = "ATAN2", e[e.COMPLEX_MULTIPLY_IMAG = 2] = "COMPLEX_MULTIPLY_IMAG", e[e.COMPLEX_MULTIPLY_REAL = 3] = "COMPLEX_MULTIPLY_REAL", e[e.DIV = 4] = "DIV", e[e.ELU_DER = 5] = "ELU_DER", e[e.EQUAL = 6] = "EQUAL", e[e.FLOOR_DIV = 7] = "FLOOR_DIV", e[e.GREATER = 8] = "GREATER", e[e.GREATER_EQUAL = 9] = "GREATER_EQUAL", e[e.LESS = 10] = "LESS", e[e.LESS_EQUAL = 11] = "LESS_EQUAL", e[e.LOGICAL_AND = 12] = "LOGICAL_AND", e[e.LOGICAL_OR = 13] = "LOGICAL_OR", e[e.MAX = 14] = "MAX", e[e.MIN = 15] = "MIN", e[e.MOD = 16] = "MOD", e[e.MUL = 17] = "MUL", e[e.NOT_EQUAL = 18] = "NOT_EQUAL", e[e.POW = 19] = "POW", e[e.PRELU = 20] = "PRELU", e[e.SQUARED_DIFFERENCE = 21] = "SQUARED_DIFFERENCE", e[e.SUB = 22] = "SUB";
})(t || (t = {}));
const r = "let resultTemp = a + b;", L = "let resultTemp = atan2(a, b);", E = "let resultTemp = areal * breal - aimag * bimag;", c = "let resultTemp = areal * bimag + aimag * breal;", u = "let resultTemp = a / b;", n = "let resultTemp = select(a * (b + 1.0), a, b >= b - b);", A = `
  let zero = sign(a) * 0 + 0;
  let one = sign(b) * 0 + 1;
  let resultTemp = select(zero, one, a == b);
`, N = `
  let remainder =
      select(a % b, round(a % b), (round(a) == a) & (round(b) == b));
  let quotient = (a - remainder) / b;
  let resultTemp =
      round(select(quotient, quotient - 1, sign(remainder) == -sign(b)));
`, _ = `
  let zero = sign(a) * 0 + 0;
  let one = sign(b) * 0 + 1;
  let resultTemp = select(zero, one, a > b);
`, m = `
  let zero = sign(a) * 0 + 0;
  let one = sign(b) * 0 + 1;
  let resultTemp = select(zero, one, a >= b);
`, R = `
  let zero = sign(a) * 0 + 0;
  let one = sign(b) * 0 + 1;
  let resultTemp = select(zero, one, a < b);
`, U = `
  let zero = sign(a) * 0 + 0;
  let one = sign(b) * 0 + 1;
  let resultTemp = select(zero, one, a <= b);
`, I = "return f32(a >= 1.0 && b >= 1.0);", f = `return (vec4<f32>(a >= vec4<f32>(1.0)) *
  vec4<f32>(b >= vec4<f32>(1.0)));`, M = "return f32(a >= 1.0 || b >= 1.0);", i = `return min(vec4<f32>(a >= vec4<f32>(1.0)) +
  vec4<f32>(b >= vec4<f32>(1.0)), vec4<f32>(1.0));`, D = "let resultTemp = max(a, b);", v = "let resultTemp = min(a, b);", P = `
  let isNaN = b == 0.;
  var resultTemp = a % b;
  resultTemp = select((resultTemp + b) % b, resultTemp,
      (a < 0. && b < 0.) || (a >= 0. && b > 0.));
`, g = `
  let isNaN = !vec4<bool>(b);
  var resultTemp = vec4<f32>(a % b);
  if (!((a[0] < 0. && b[0] < 0.) || (a[0] >= 0. && b[0] > 0.))) {
    resultTemp[0] = (resultTemp[0] + b[0]) % b[0];
  }
  if (!((a[1] < 0. && b[1] < 0.) || (a[1] >= 0. && b[1] > 0.))) {
    resultTemp[1] = (resultTemp[1] + b[1]) % b[1];
  }
  if (!((a[2] < 0. && b[2] < 0.) || (a[2] >= 0. && b[2] > 0.))) {
    resultTemp[2] = (resultTemp[2] + b[2]) % b[2];
  }
  if (!((a[3] < 0. && b[3] < 0.) || (a[3] >= 0. && b[3] > 0.))) {
    resultTemp[3] = (resultTemp[3] + b[3]) % b[3];
  }
`, C = "let resultTemp = a * b;", S = `
  var resultTemp = f32(a != b);
  let valueForNaN = 1.0;
`, d = `
  var resultTemp = vec4<f32>(a != b);
  let valueForNaN = 1.0;
`, T = `
  let isNaN = a < 0.0 && floor(b) < b;
  if (b == 0.0) {
    return 1.0;
  }
  var resultTemp = select(sign(a) * pow(abs(a), b), pow(abs(a), b),
      round(abs(b) % 2.0) != 1.0);
`, G = `
  let isModRound1Bool = vec4<i32>(round(abs(b) % vec4<f32>(2.0))) == vec4<i32>(1);
  let isModRound1 = vec4<f32>(isModRound1Bool);
  let multiplier = sign(a) * isModRound1 + (vec4<f32>(1.0) - isModRound1);
  var resultTemp = multiplier * pow(abs(a), b);

  // Ensure that a^0 = 1, including 0^0 = 1 as this correspond to TF and JS
  let isExpZero = b == vec4<f32>(0.0);
  if (isExpZero.r) {
    resultTemp.r = 1.0;
  }
  if (isExpZero.g) {
    resultTemp.g = 1.0;
  }
  if (isExpZero.b) {
    resultTemp.b = 1.0;
  }
  if (isExpZero.a) {
    resultTemp.a = 1.0;
  }
  let isNaN = (a < vec4<f32>(0.0)) & (floor(b) < b);
`, Q = "if (a < 0.0) { return b * a; }  return a;", k = `
  let aLessThanZero = vec4<f32>(a < vec4<f32>(0.0));
  return (aLessThanZero * (b * a)) + ((vec4<f32>(1.0) - aLessThanZero) * a);
`, F = "let resultTemp = (a - b) * (a - b);", z = "let resultTemp = a - b;";
function X(e, a) {
  let s;
  do {
    switch (e) {
      case t.ATAN2:
        s = L;
        break;
      case t.MAX:
        s = D;
        break;
      case t.MIN:
        s = v;
        break;
      case t.MOD:
        s = a ? g : P;
        break;
      case t.NOT_EQUAL:
        s = a ? d : S;
        break;
      case t.POW:
        s = a ? G : T;
        break;
      default:
        continue;
    }
    let o, l, b;
    return a ? (o = "isnanVec4", l = "vec4<f32>", b = "vec4<bool>") : (o = "isnan", l = "f32", b = "bool"), `
      let aIsNaN = ${o}(a);
      let aPostLegalization = select(a, ${l}(42), aIsNaN);
      let bIsNaN = ${o}(b);
      let bPostLegalization = select(b, ${l}(42), bIsNaN);
      let isNaN = false;
      let valueForNaN = uniforms.NAN;
      {
        let a = aPostLegalization;
        let b = bPostLegalization;
        ${s}
        return select(
            resultTemp, ${l}(valueForNaN),
            ${b}(isNaN) | aIsNaN | bIsNaN);
      }
    `;
  } while (!1);
  switch (e) {
    case t.ADD:
      s = r;
      break;
    case t.COMPLEX_MULTIPLY_IMAG:
      s = c;
      break;
    case t.COMPLEX_MULTIPLY_REAL:
      s = E;
      break;
    case t.DIV:
      s = u;
      break;
    case t.ELU_DER:
      s = n;
      break;
    case t.EQUAL:
      s = A;
      break;
    case t.FLOOR_DIV:
      s = N;
      break;
    case t.GREATER:
      s = _;
      break;
    case t.GREATER_EQUAL:
      s = m;
      break;
    case t.LESS:
      s = R;
      break;
    case t.LESS_EQUAL:
      s = U;
      break;
    case t.LOGICAL_AND:
      return a ? f : I;
    case t.LOGICAL_OR:
      return a ? i : M;
    case t.MUL:
      s = C;
      break;
    case t.PRELU:
      return a ? k : Q;
    case t.SQUARED_DIFFERENCE:
      s = F;
      break;
    case t.SUB:
      s = z;
      break;
  }
  return `
    ${s}
    return resultTemp;
  `;
}
export {
  t as B,
  X as g
};
