/* <sgml> Create a copy of BigDecimal object for local use.
<p>This does NOT make a copy of the mantissa array.
</sgml>
Arg1 is the BigDecimal to clone (non-null)
 --private static final com.ibm.icu.math.BigDecimal clone(com.ibm.icu.math.BigDecimal dec){
509017
function clone(dec) {
  //--com.ibm.icu.math.BigDecimal copy;
  var copy;
  copy=new BigDecimal();
  copy.ind=dec.ind;
  copy.exp=dec.exp;
  copy.form=dec.form;
  copy.mant=dec.mant;
  return copy;
  }
404415
public BigDecimal getBigDecimal(int index) throws JSONException {
		Object object = this.get(index);
		try {
			return new BigDecimal(object.toString());
		} catch (Exception e) {
			throw new JSONException("JSONArray[" + index +
					"] could not convert to BigDecimal.");
		}
	}
1065401
public BigDecimal getIdPartAsBigDecimal() {
    String val = getIdPart();
    if (isBlank(val)) {
      return null;
    }
    return new BigDecimal(val);
  }
83636
@SuppressWarnings("unchecked")
	public <T> T createInstance(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) 
			throws FMSException {
		Object obj = null;
		Class<?> type = arg1.getReturnType();
		if (String.class.equals(type)) {
			obj = null;
		} else if (Integer.class.equals(type) || int.class.equals(type)) {
			obj = Integer.valueOf(0);
		} else if (Byte.class.equals(type) || byte.class.equals(type)) {
			obj = Integer.valueOf(0);
		} else if (java.util.Date.class.equals(type)) {
			obj = new Date();
		} else if (java.sql.Timestamp.class.equals(type)) {
			obj = new Timestamp(System.currentTimeMillis());
		} else if (java.sql.Date.class.equals(type)) {
			obj = new java.sql.Date(System.currentTimeMillis());
		} else if (java.sql.Time.class.equals(type)) {
			obj = new java.sql.Time(System.currentTimeMillis());
		} else if (Long.class.equals(type) || long.class.equals(type)) {
			obj = Long.valueOf(0);
		} else if (Short.class.equals(type) || short.class.equals(type)) {
			obj = Short.valueOf("0");
		} else if (Double.class.equals(type) || double.class.equals(type)) {
			obj = Double.valueOf(0);
		} else if (Float.class.equals(type) || float.class.equals(type)) {
			obj = Float.valueOf(0);
		} else if (BigInteger.class.equals(type)) {
			obj = BigInteger.valueOf(0);
		} else if (BigDecimal.class.equals(type)) {
			obj = BigDecimal.valueOf(0);
		} else if (Boolean.class.equals(type) || boolean.class.equals(type)) {
			obj = Boolean.TRUE;
		} else if (List.class.isAssignableFrom(type)) {
			try {
				Type t = arg1.getGenericReturnType();
				Object value = getObject(t);
				Object queryValue = GenerateQuery.createQueryEntity(value);
				obj = arg3.invokeSuper(arg0, arg2);
				((List<Object>) obj).add(queryValue);
			} catch (Throwable t) {
				throw new FMSException(t);
			}
		} else if (Enum.class.isAssignableFrom(type)) {
			LOG.debug("Create instance for Enum");
			// Create EnumObject
		} else if (type.isArray()) {
			// Create ArrayObject
			LOG.debug("Create instance for Array Object");
		} else if (!Modifier.isFinal(type.getModifiers())) {
			obj = GenerateQuery.createQueryEntity(type);
		} else {
			obj = null;
		}
		return (T) obj;
	}
425868
public static BigDecimal deserializeBigDecimalFromString(String decimal) throws IOException
    {
        if (decimal == null) {
            return null;
        }
        BigDecimal bd = new BigDecimal(decimal);
        // if the scale is too large, check for trailing zeros
        if (bd.scale() > kDefaultScale) {
            bd = bd.stripTrailingZeros();
            if (bd.scale() > kDefaultScale) {
                bd = roundToScale(bd, kDefaultScale, getRoundingMode());
            }
        }
        // enforce scale 12 to make the precision check right
        if (bd.scale() < kDefaultScale) {
            bd = bd.setScale(kDefaultScale);
        }
        if (bd.precision() > 38) {
            throw new RuntimeException(
                    "Decimal " + bd + " has more than " + kDefaultPrecision + " digits of precision.");
        }
        return bd;
    }
1209894
final MetricDatum cloneMetricDatum(MetricDatum md) {
        return new MetricDatum()
            .withDimensions(md.getDimensions()) // a new collection is created
            .withMetricName(md.getMetricName())
            .withStatisticValues(md.getStatisticValues())
            .withTimestamp(md.getTimestamp())
            .withUnit(md.getUnit())
            .withValue(md.getValue());
    }
760454
public static Optional<BigDecimal> createBigDecimal(final String str) {
        if (N.isNullOrEmptyOrBlank(str) || str.trim().startsWith("--")) {
            return Optional.empty();
        }

        try {
            return Optional.of(new BigDecimal(str));
        } catch (NumberFormatException e) {
            return Optional.empty();
        }
    }
562440
public static boolean[] copyOf(final boolean[] original, final int newLength) {
        if (newLength == original.length) {
            return original.clone();
        }

        final boolean[] copy = new boolean[newLength];

        if (N.notNullOrEmpty(original)) {
            copy(original, 0, copy, 0, Math.min(original.length, newLength));
        }

        return copy;
    }
517898
public static byte[][] copyOf(final byte[][] a, final int s) {
        final byte[][] tmp = new byte[s][];
        System.arraycopy(a, 0, tmp, 0, Math.min(s, a.length));
        return tmp;
    }
825787
public double[] copyValues1D()
    {
        double v[] = new double[nCols];

        for (int c = 0; c < nCols; ++c) {
            v[c] = values[0][c];
        }

        return v;
    }
156344
public static BigDecimal bigDecimalValue(BigDecimal val)
    {
        if (val == null
            || val.getClass() == BigDecimal.class)
        {
            return val;
        }
        return new BigDecimal(val.unscaledValue(), val.scale());
    }
769974
public double[] copyValues1D()
    {
        double v[] = new double[nRows];

        for (int r = 0; r < nRows; ++r) {
            v[r] = values[r][0];
        }

        return v;
    }
536117
@Override
  public MeanVarianceMinMax put(double[] vals) {
    final int l = vals.length;
    if(l < 2) {
      if(l == 1) {
        put(vals[0]);
      }
      return this;
    }
    // First pass:
    double s1 = 0.;
    for(int i = 0; i < l; i++) {
      final double v = vals[i];
      s1 += v;
      min = v < min ? v : min;
      max = v > max ? v : max;
    }
    final double om1 = s1 / l;
    // Second pass:
    double om2 = 0., err = 0.;
    for(int i = 0; i < l; i++) {
      final double v = vals[i] - om1;
      om2 += v * v;
      err += v;
    }
    s1 += err;
    om2 += err / l;
    if(n <= 0) {
      n = l;
      sum = s1;
      m2 = om2;
      return this;
    }
    final double tmp = n * s1 - sum * l;
    final double oldn = n; // tmp copy
    n += l;
    sum += s1 + err;
    m2 += om2 + tmp * tmp / (l * n * oldn);
    return this;
  }
1320389
@Override
    public double[] transform(double[] x) {
        if (x.length != scale.length) {
            throw new IllegalArgumentException(String.format("Invalid vector size %d, expected %d", x.length, scale.length));
        }

        double[] y = copy ? new double[x.length] : x;
        for (int i = 0; i < x.length; i++) {
            y[i] = x[i] / scale[i];
        }

        return y;
    }
630089
public static final byte[] cloneSubArray(byte[] data, int offset, int size)
   {
      byte[] newData = new byte[size];
      System.arraycopy(data, offset, newData, 0, size);
      return (newData);
   }
1190901
@Override
    public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
        checkColumnBounds(columnIndex);
        try {
            final VoltType type = table.getColumnType(columnIndex - 1);
            BigDecimal decimalValue = null;
            switch(type) {
            case TINYINT:
                decimalValue = new BigDecimal(table.getLong(columnIndex - 1));
                break;
            case SMALLINT:
                decimalValue = new BigDecimal(table.getLong(columnIndex - 1));
                break;
            case INTEGER:
                decimalValue = new BigDecimal(table.getLong(columnIndex - 1));
                break;
            case BIGINT:
                decimalValue = new BigDecimal(table.getLong(columnIndex - 1));
                break;
            case FLOAT:
                decimalValue = new BigDecimal(table.getDouble(columnIndex - 1));
                break;
            case DECIMAL:
                decimalValue = table.getDecimalAsBigDecimal(columnIndex - 1);
                break;
            default:
                throw new IllegalArgumentException("Cannot get BigDecimal value for column type '" + type + "'");
            }

            return table.wasNull() ? null : decimalValue;
        } catch (Exception x) {
            throw SQLError.get(x);
        }
    }
821518
@Override
  public <NV extends NumberVector> NV projectRelativeScaledToDataSpace(double[] v, NumberVector.Factory<NV> prototype) {
    final int dim = v.length;
    double[] vec = new double[dim];
    for(int d = 0; d < dim; d++) {
      vec[d] = scales[d].getRelativeUnscaled(v[d]);
    }
    return prototype.newNumberVector(vec);
  }